From 8b521b452e7c083097d39462ba6343727c9743c2 Mon Sep 17 00:00:00 2001 From: Jesus Federico Date: Mon, 22 Apr 2024 15:02:43 -0400 Subject: [PATCH] LTI-357: fix for making actioncable endpoint be dynamically configured (#305) --- app/controllers/rooms_controller.rb | 11 +++++++++++ config/application.rb | 4 +--- config/routes.rb | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 956d5e4b..e90021f7 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -39,6 +39,8 @@ class RoomsController < ApplicationController before_action :check_for_cancel, only: [:create, :update] before_action :allow_iframe_requests before_action :set_current_locale + before_action :set_action_cable, only: %i[launch] + after_action :broadcast_meeting, only: [:meeting_end] # GET /rooms/1 @@ -492,4 +494,13 @@ def room_handler(launch_params, tenant) Digest::SHA1.hexdigest(input) end + + def set_action_cable + relative_url_root = Rails.configuration.relative_url_root + relative_url_root = relative_url_root.chop if relative_url_root[-1] == '/' + config = ActionCable::Server::Configuration.new + config.cable = { url: "wss://#{request.host}#{relative_url_root}/rooms/cable" } + + ActionCable::Server::Base.new(config: config) + end end diff --git a/config/application.rb b/config/application.rb index 130a9df1..35f82bf7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -34,7 +34,6 @@ class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - config.url_host = ENV['URL_HOST'] config.build_number = ENV['BUILD_NUMBER'] || 'v1' @@ -56,8 +55,7 @@ class Application < Rails::Application # Mount Action Cable outside main process or domain relative_url_root = config.relative_url_root relative_url_root = relative_url_root.chop if relative_url_root[-1] == '/' - config.action_cable.url = "wss://#{ENV['URL_HOST']}#{relative_url_root}/rooms/cable" - config.action_cable.mount_path = '/rooms/cable' + config.action_cable.mount_path = "#{relative_url_root}/rooms/cable" # Settings for external services. config.cache_enabled = ENV.fetch('CACHE_ENABLED', 'false').casecmp?('true') diff --git a/config/routes.rb b/config/routes.rb index cce8a37c..4fc362b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,7 @@ # with BigBlueButton; if not, see . Rails.application.routes.draw do - mount ActionCable.server => Rails.configuration.action_cable.url + mount ActionCable.server => '/rooms/cable' scope 'rooms' do get '/health_check', to: 'health_check#show'