forked from External/greenlight
		
	Show a browser notification when a user is waiting to join a room
The owner of a room receives a browser notification if he has the page open and another person tries to join his room.
This commit is contained in:
		@@ -21,7 +21,7 @@
 | 
				
			|||||||
      $(".center-panel-wrapper").html(html);
 | 
					      $(".center-panel-wrapper").html(html);
 | 
				
			||||||
      displayRoomURL();
 | 
					      displayRoomURL();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var initRooms = function() {
 | 
					  var initRooms = function() {
 | 
				
			||||||
    App.messages = App.cable.subscriptions.create({
 | 
					    App.messages = App.cable.subscriptions.create({
 | 
				
			||||||
@@ -43,6 +43,13 @@
 | 
				
			|||||||
        } else if (data.action === 'meeting_ended') {
 | 
					        } else if (data.action === 'meeting_ended') {
 | 
				
			||||||
          sessionStatusRefresh($('.meeting-url').val());
 | 
					          sessionStatusRefresh($('.meeting-url').val());
 | 
				
			||||||
          showAlert(I18n.meeting_ended, 4000);
 | 
					          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)
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ var loopJoin = function() {
 | 
				
			|||||||
  jqxhr.fail(function(xhr, status, error) {
 | 
					  jqxhr.fail(function(xhr, status, error) {
 | 
				
			||||||
    console.info("meeting join failed");
 | 
					    console.info("meeting join failed");
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var alertTimeout = null;
 | 
					var alertTimeout = null;
 | 
				
			||||||
var showAlert = function(html, timeout_delay) {
 | 
					var showAlert = function(html, timeout_delay) {
 | 
				
			||||||
@@ -54,3 +54,19 @@ var showAlert = function(html, timeout_delay) {
 | 
				
			|||||||
var displayRoomURL = function() {
 | 
					var displayRoomURL = function() {
 | 
				
			||||||
  $('.meeting-url').val(Meeting.getInstance().getURL());
 | 
					  $('.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();
 | 
				
			||||||
@@ -52,8 +52,13 @@ class BbbController < ApplicationController
 | 
				
			|||||||
        options
 | 
					        options
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # the user can join the meeting
 | 
				
			||||||
      if bbb_res[:returncode] && current_user && current_user == user
 | 
					      if bbb_res[:returncode] && current_user && current_user == user
 | 
				
			||||||
        JoinMeetingJob.perform_later(user.encrypted_id)
 | 
					        JoinMeetingJob.perform_later(user.encrypted_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # user will be waiting for a moderator
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					        NotifyUserWaitingJob.perform_later(user.encrypted_id, params[:name])
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      render_bbb_response bbb_res, bbb_res[:response]
 | 
					      render_bbb_response bbb_res, bbb_res[:response]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,4 +15,8 @@
 | 
				
			|||||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
					# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module UsersHelper
 | 
					module UsersHelper
 | 
				
			||||||
 | 
					  def is_room_owner
 | 
				
			||||||
 | 
					    token = current_user ? current_user.encrypted_id : nil
 | 
				
			||||||
 | 
					    token.present? && params[:id].present? && token == params[:id]
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								app/jobs/notify_user_waiting_job.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								app/jobs/notify_user_waiting_job.rb
									
									
									
									
									
										Normal file
									
								
							@@ -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 <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NotifyUserWaitingJob < ApplicationJob
 | 
				
			||||||
 | 
					  queue_as :default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def perform(room, user)
 | 
				
			||||||
 | 
					    ActionCable.server.broadcast "#{room}_meeting_updates_channel",
 | 
				
			||||||
 | 
					                                 { action: 'user_waiting', user: user }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
@@ -77,10 +77,13 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
				
			|||||||
  </body>
 | 
					  </body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- Global javascript variables and helpers -->
 | 
				
			||||||
<script type="text/javascript">
 | 
					<script type="text/javascript">
 | 
				
			||||||
  window.I18n = <%= client_translations.to_json.html_safe %>
 | 
					  window.I18n = <%= client_translations.to_json.html_safe %>
 | 
				
			||||||
  window.GreenLight = {};
 | 
					  window.GreenLight = {};
 | 
				
			||||||
  window.GreenLight.META_LISTED = "<%= BbbApi::META_LISTED %>";
 | 
					  window.GreenLight.META_LISTED = "<%= BbbApi::META_LISTED %>";
 | 
				
			||||||
  window.GreenLight.META_TOKEN = "<%= BbbApi::META_TOKEN %>";
 | 
					  window.GreenLight.META_TOKEN = "<%= BbbApi::META_TOKEN %>";
 | 
				
			||||||
  window.GreenLight.META_HOOK_URL = "<%= BbbApi::META_HOOK_URL %>";
 | 
					  window.GreenLight.META_HOOK_URL = "<%= BbbApi::META_HOOK_URL %>";
 | 
				
			||||||
 | 
					  window.GreenLight.user = {};
 | 
				
			||||||
 | 
					  window.GreenLight.user.roomOwner = <%= is_room_owner %>;
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,6 +54,8 @@ en-US:
 | 
				
			|||||||
    recording_unlisted: Recording was unlisted
 | 
					    recording_unlisted: Recording was unlisted
 | 
				
			||||||
    recording_unpublished: Recording was unpublished
 | 
					    recording_unpublished: Recording was unpublished
 | 
				
			||||||
    unpublish_recording: Hide recording
 | 
					    unpublish_recording: Hide recording
 | 
				
			||||||
 | 
					    user_waiting_body: "%{user} is waiting to join your room!"
 | 
				
			||||||
 | 
					    user_waiting_title: A user is waiting
 | 
				
			||||||
  copied: Copied
 | 
					  copied: Copied
 | 
				
			||||||
  copy_error: Use Ctrl-c to copy
 | 
					  copy_error: Use Ctrl-c to copy
 | 
				
			||||||
  create_session: Create a Session
 | 
					  create_session: Create a Session
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user