diff --git a/app/assets/javascripts/channels/meeting_updates.js b/app/assets/javascripts/channels/meeting_updates.js index c0ec9c4e..87f6af15 100644 --- a/app/assets/javascripts/channels/meeting_updates.js +++ b/app/assets/javascripts/channels/meeting_updates.js @@ -21,7 +21,7 @@ $(".center-panel-wrapper").html(html); displayRoomURL(); }); - } + }; var initRooms = function() { App.messages = App.cable.subscriptions.create({ @@ -43,6 +43,13 @@ } else if (data.action === 'meeting_ended') { sessionStatusRefresh($('.meeting-url').val()); showAlert(I18n.meeting_ended, 4000); + } else if (data.action === 'user_waiting') { + // show a browser notification only to the owner + if (GreenLight.user.roomOwner) { + showNotification(I18n.user_waiting_title, { + body: I18n.user_waiting_body.replace(/%{user}/, data.user) + }); + } } } }); diff --git a/app/assets/javascripts/shared.js b/app/assets/javascripts/shared.js.erb similarity index 80% rename from app/assets/javascripts/shared.js rename to app/assets/javascripts/shared.js.erb index 166ef5ad..95f00343 100644 --- a/app/assets/javascripts/shared.js +++ b/app/assets/javascripts/shared.js.erb @@ -32,7 +32,7 @@ var loopJoin = function() { jqxhr.fail(function(xhr, status, error) { console.info("meeting join failed"); }); -} +}; var alertTimeout = null; var showAlert = function(html, timeout_delay) { @@ -54,3 +54,19 @@ var showAlert = function(html, timeout_delay) { var displayRoomURL = function() { $('.meeting-url').val(Meeting.getInstance().getURL()); }; + +var showNotification = function(title, options) { + if (Notification.permission === "granted") { + var icon = '<%= asset_path("bbb-logo.png") %>'; + options = $.extend(options, { + icon: icon + }); + var notification = new Notification(title, options); + notification.onclick = function() { + window.focus(); + }; + } +}; + +// TODO: only need permissions if the user is signed in +Notification.requestPermission(); diff --git a/app/controllers/bbb_controller.rb b/app/controllers/bbb_controller.rb index e3766468..485402fe 100644 --- a/app/controllers/bbb_controller.rb +++ b/app/controllers/bbb_controller.rb @@ -52,8 +52,13 @@ class BbbController < ApplicationController options ) + # the user can join the meeting if bbb_res[:returncode] && current_user && current_user == user JoinMeetingJob.perform_later(user.encrypted_id) + + # user will be waiting for a moderator + else + NotifyUserWaitingJob.perform_later(user.encrypted_id, params[:name]) end render_bbb_response bbb_res, bbb_res[:response] diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 2eba122d..19758ad6 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -15,4 +15,8 @@ # with BigBlueButton; if not, see . module UsersHelper + def is_room_owner + token = current_user ? current_user.encrypted_id : nil + token.present? && params[:id].present? && token == params[:id] + end end diff --git a/app/jobs/notify_user_waiting_job.rb b/app/jobs/notify_user_waiting_job.rb new file mode 100644 index 00000000..0211e42a --- /dev/null +++ b/app/jobs/notify_user_waiting_job.rb @@ -0,0 +1,24 @@ +# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. +# +# Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below). +# +# This program is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free Software +# Foundation; either version 3.0 of the License, or (at your option) any later +# version. +# +# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with BigBlueButton; if not, see . + +class NotifyUserWaitingJob < ApplicationJob + queue_as :default + + def perform(room, user) + ActionCable.server.broadcast "#{room}_meeting_updates_channel", + { action: 'user_waiting', user: user } + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e13b10ea..966aab86 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -77,10 +77,13 @@ with BigBlueButton; if not, see . + diff --git a/config/locales/en-us.yml b/config/locales/en-us.yml index aafa1769..95ae9cbf 100644 --- a/config/locales/en-us.yml +++ b/config/locales/en-us.yml @@ -54,6 +54,8 @@ en-US: recording_unlisted: Recording was unlisted recording_unpublished: Recording was unpublished unpublish_recording: Hide recording + user_waiting_body: "%{user} is waiting to join your room!" + user_waiting_title: A user is waiting copied: Copied copy_error: Use Ctrl-c to copy create_session: Create a Session