add support for BBB 2.0 webhooks

This commit is contained in:
Josh
2017-09-14 15:59:42 -04:00
parent 133dc664a4
commit fbc8a56fc0
4 changed files with 109 additions and 80 deletions

View File

@ -259,7 +259,12 @@ class BbbController < ApplicationController
end
def treat_callback_event(event)
eventName = (event.present? && event['header'].present?) ? event['header']['name'] : nil
# Check if the event is a BigBlueButton 2.0 event.
if event.has_key?('envelope')
eventName = (event.present? && event['envelope'].present?) ? event['envelope']['name'] : nil
else # The event came from BigBlueButton 1.1 (or earlier).
eventName = (event.present? && event['header'].present?) ? event['header']['name'] : nil
end
# a recording is ready
if eventName == "publish_ended"
@ -286,11 +291,11 @@ class BbbController < ApplicationController
else
logger.error "Bad format for event #{event}, won't process"
end
elsif eventName == "meeting_created_message"
elsif eventName == "meeting_created_message" || eventName == "MeetingCreatedEvtMsg"
# Fire an Actioncable event that updates _previously_joined for the client.
actioncable_event('create', params[:id], params[:room_id])
elsif eventName == "meeting_destroyed_event"
actioncable_event('destroy', params[:id], params[:room_id])
actioncable_event('create')
elsif eventName == "meeting_destroyed_event" || eventName == "MeetingEndedEvtMsg"
actioncable_event('destroy')
# Since the meeting is destroyed we have no way get the callback url to remove the meeting, so we must build it.
remove_url = build_callback_url(params[:id], params[:room_id])
@ -298,9 +303,13 @@ class BbbController < ApplicationController
# Remove webhook for the meeting.
webhook_remove(remove_url)
elsif eventName == "user_joined_message"
actioncable_event('join', params[:id], params[:room_id], event['payload']['user']['name'], event['payload']['user']['role'])
actioncable_event('join', {user_id: event['payload']['user']['extern_userid'], user: event['payload']['user']['name'], role: event['payload']['user']['role']})
elsif eventName == "UserJoinedMeetingEvtMsg"
actioncable_event('join', {user_id: event['core']['body']['intId'], user: event['core']['body']['name'], role: event['core']['body']['role']})
elsif eventName == "user_left_message"
actioncable_event('leave', params[:id], params[:room_id], event['payload']['user']['name'], event['payload']['user']['role'])
actioncable_event('leave', {user_id: event['payload']['user']['extern_userid']})
elsif eventName == "UserLeftMeetingEvtMsg"
actioncable_event('leave', {user_id: event['core']['body']['intId']})
else
logger.info "Callback event will not be treated. Event name: #{eventName}"
end
@ -312,13 +321,9 @@ class BbbController < ApplicationController
"#{request.base_url}#{relative_root}/rooms/#{room_id}/#{URI.encode(id)}/callback"
end
def actioncable_event(method, id, room_id, user = 'none', role = 'none')
ActionCable.server.broadcast 'refresh_meetings',
method: method,
meeting: id,
room: room_id,
user: user,
role: role
def actioncable_event(method, data = {})
data = {method: method, meeting: params[:id], room: params[:room_id]}.merge(data)
ActionCable.server.broadcast('refresh_meetings', data)
end
# Validates the checksum received in a callback call.

View File

@ -44,9 +44,38 @@ class LandingController < ApplicationController
# If someone tries to access the guest landing when guest access is enabled, just send them to root.
redirect_to root_url unless Rails.configuration.disable_guest_access
end
def send_meetings_data
render json: {active: bbb.get_meetings, waiting: WaitingList.waiting}
# Sends data on meetings that the current user has previously joined.
def get_previous_meeting_statuses
previously_joined = params[:previously_joined]
active_meetings = bbb.get_meetings[:meetings]
payload = {active: [], waiting: []}
# Find meetings that are owned by the current user and also active.
active_meetings.each do |m|
if m[:metadata].has_key?(:'room-id')
if previously_joined.include?(m[:meetingName])&& m[:metadata][:'room-id'] == current_user[:encrypted_id]
if m[:attendees] == {}
attendees = []
else
attendees = m[:attendees][:attendee]
attendees = [attendees] unless attendees.is_a?(Array)
end
participants = []
moderators = []
attendees.each do |a|
if a[:role] == 'MODERATOR'
moderators << {name: a[:fullName], user_id: a[:userID]}
else
participants << {name: a[:fullName], user_id: a[:userID]}
end
end
payload[:active] << {name: m[:meetingName], moderators: moderators, participants: participants}
end
end
end
# Add the waiting meetings.
payload[:waiting] = WaitingList.waiting[current_user[:encrypted_id]] || {}
render json: payload
end
def wait_for_moderator