diff --git a/app/controllers/concerns/bbb_helper.rb b/app/controllers/concerns/bbb_helper.rb index 263d61b9..c808e5ba 100644 --- a/app/controllers/concerns/bbb_helper.rb +++ b/app/controllers/concerns/bbb_helper.rb @@ -182,13 +182,13 @@ def wait_for_mod? # Return the number of participants in a meeting for the current room. def participant_count info = meeting_info - return info[:participantCount] if info[:returncode] == 'SUCCESS' + info[:participantCount] if info[:returncode] == 'SUCCESS' end # Return the meeting start time for the current room. def meeting_start_time info = meeting_info - return info[:startTime] if info[:returncode] == 'SUCCESS' + info[:startTime] if info[:returncode] == 'SUCCESS' end def bigbluebutton_moderator_roles diff --git a/app/controllers/concerns/broker_helper.rb b/app/controllers/concerns/broker_helper.rb new file mode 100644 index 00000000..6c6a4dd8 --- /dev/null +++ b/app/controllers/concerns/broker_helper.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. +# Copyright (c) 2018 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 . + +module BrokerHelper + extend ActiveSupport::Concern + + include OmniauthHelper + + # Fetch tenant settings from the broker + def tenant_settings(options = {}) + tenant = options[:tenant] || @room&.tenant || '' + Rails.cache.fetch("rooms/tenant_settings/#{tenant}", expires_in: 1.hour) do + bbbltibroker_url = omniauth_bbbltibroker_url("/api/v1/tenants/#{tenant}") + get_response = RestClient.get(bbbltibroker_url, 'Authorization' => "Bearer #{omniauth_client_token(omniauth_bbbltibroker_url)}") + + JSON.parse(get_response) + end + rescue StandardError => e + Rails.logger.error("Could not fetch tenant credentials from broker. Error message: #{e}") + nil + end + + # Fetch the params to use when creating the room handler + def handler_params(tenant) + tenant_settings(tenant: tenant)&.[]('settings')&.[]('handler_params')&.split(',') + end +end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index b201815c..82e69f2f 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -29,6 +29,7 @@ class RoomsController < ApplicationController # Include concerns. include BbbHelper include OmniauthHelper + include BrokerHelper before_action :print_parameters if Rails.configuration.developer_mode_enabled before_action :authenticate_user!, except: %i[meeting_close], raise: false @@ -296,7 +297,7 @@ def set_launch end def launch_room(launch_params, tenant) - handler = Digest::SHA1.hexdigest("rooms#{tenant}#{launch_params['resource_link_id']}") + handler = room_handler(launch_params, tenant) handler_legacy = launch_params['custom_params']['custom_handler_legacy'].presence ## Any launch. @@ -427,4 +428,19 @@ def set_current_locale response.set_header('Content-Language', I18n.locale) end + + # Generate room handler based on the settings pulled from the broker + def room_handler(launch_params, tenant) + input = "rooms#{tenant}" + + # use resource_link_id as the default param if nothing was specified in the broker settings + room_handler_params = handler_params(tenant).presence || ['resource_link_id'] + + room_handler_params.each do |param| + param_val = launch_params[param] + input += param_val.to_s if param_val + end + + Digest::SHA1.hexdigest(input) + end end