From ad7aaa1a11525fd2d06f9e4919e6939de4d7f057 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 21 Jun 2018 10:57:20 -0400 Subject: [PATCH] dynamically select websocket protocol --- app/assets/javascripts/cable.js | 6 +++++- app/controllers/application_controller.rb | 6 ++++++ app/views/layouts/application.html.erb | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index 2fb3e843..0edb4a6e 100644 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -6,7 +6,11 @@ //= require_tree ./channels (function() { + var protocol = (window.location.protocol === "https:" ? "wss://" : "ws://"); + var host = window.GreenLight.WEBSOCKET_HOST || window.location.host + window.GreenLight.RELATIVE_ROOT; + var url = protocol + host + '/cable'; + this.App || (this.App = {}); - App.cable = ActionCable.createConsumer(); + App.cable = ActionCable.createConsumer(url); }).call(this); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dc4ff6a3..a47ada99 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,6 +18,12 @@ class ApplicationController < ActionController::Base end helper_method :user_name_limit + # Relative root helper (when deploying to subdirectory). + def relative_root + Rails.configuration.relative_url_root || "" + end + helper_method :relative_root + # Determines if the BigBlueButton endpoint is configured (or set to default). def bigbluebutton_endpoint_default? return false if loadbalanced_configuration? diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 42fbcb9a..0883f47a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,13 @@ + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>