From f725b7f1bc42bdf1beeba144062d2dca0c958c58 Mon Sep 17 00:00:00 2001 From: jfederico Date: Mon, 17 Oct 2016 18:36:56 -0400 Subject: [PATCH] Implemented join to BBB first approach --- .gitignore | 1 + Gemfile | 3 ++ Gemfile.lock | 5 +++ app/assets/javascripts/bbb.coffee | 3 ++ app/assets/stylesheets/bbb.scss | 3 ++ app/controllers/application_controller.rb | 4 +++ app/controllers/bbb_controller.rb | 38 +++++++++++++++++++++++ app/controllers/landing_controller.rb | 4 ++- app/helpers/application_helper.rb | 22 +++++++++++++ app/helpers/bbb_helper.rb | 36 +++++++++++++++++++++ app/views/bbb/end.html.erb | 2 ++ app/views/bbb/join.html.erb | 2 ++ app/views/errors/error.html.erb | 2 ++ app/views/landing/index.html.erb | 38 +++++++++++++++++------ config/config.yml | 3 ++ config/initializers/load_config.rb | 1 + config/routes.rb | 3 ++ sample.env | 8 +++++ test/controllers/bbb_controller_test.rb | 14 +++++++++ 19 files changed, 182 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/bbb.coffee create mode 100644 app/assets/stylesheets/bbb.scss create mode 100644 app/controllers/bbb_controller.rb create mode 100644 app/helpers/bbb_helper.rb create mode 100644 app/views/bbb/end.html.erb create mode 100644 app/views/bbb/join.html.erb create mode 100644 app/views/errors/error.html.erb create mode 100644 config/config.yml create mode 100644 config/initializers/load_config.rb create mode 100644 sample.env create mode 100644 test/controllers/bbb_controller_test.rb diff --git a/.gitignore b/.gitignore index bab620de..7559b50b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ # Ignore Byebug command history file. .byebug_history +.env \ No newline at end of file diff --git a/Gemfile b/Gemfile index c1ee7d59..2c1ef168 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,9 @@ gem 'jbuilder', '~> 2.5' # gem 'capistrano-rails', group: :development group :development, :test do + # For environment configuration + gem 'dotenv-rails' + # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri end diff --git a/Gemfile.lock b/Gemfile.lock index 6e41f344..3a9be8f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,6 +63,10 @@ GEM railties (>= 4.1.0, < 5.1) responders warden (~> 1.2.3) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) erubis (2.7.0) execjs (2.7.0) faraday (0.9.2) @@ -217,6 +221,7 @@ DEPENDENCIES byebug coffee-rails (~> 4.2) devise (= 4.2.0) + dotenv-rails jbuilder (~> 2.5) jquery-datatables-rails (~> 3.4.0) jquery-rails diff --git a/app/assets/javascripts/bbb.coffee b/app/assets/javascripts/bbb.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/bbb.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/bbb.scss b/app/assets/stylesheets/bbb.scss new file mode 100644 index 00000000..687fe4e6 --- /dev/null +++ b/app/assets/stylesheets/bbb.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the bbb controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e..0a71c41d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,7 @@ +require 'bigbluebutton_api' +require 'digest/sha1' + class ApplicationController < ActionController::Base protect_from_forgery with: :exception + include ApplicationHelper end diff --git a/app/controllers/bbb_controller.rb b/app/controllers/bbb_controller.rb new file mode 100644 index 00000000..e51f7c36 --- /dev/null +++ b/app/controllers/bbb_controller.rb @@ -0,0 +1,38 @@ +class BbbController < ApplicationController + include BbbHelper + + # GET /join + # GET /join.json + def join + logger.info params.to_json + if ( !params.has_key?(:id) ) + render_response("missing_parameter", "meeting token was not included", :bad_request) + elsif ( !params.has_key?(:name) ) + render_response("missing_parameter", "user name was not included", :bad_request) + else + bbb_join_url = bbb_join_url(params[:id], false, params[:name], false) + if bbb_join_url[:returncode] + logger.info "#Execute the redirect" + render_response("ok", "execute the redirect", :ok, {:join_url => bbb_join_url[:join_url]}) + else + render_response("bigbluebutton_error", "join url could not be created", :internal_server_error) + end + end + end + + def close + end + + private + def render_response(messageKey, message, status, response={}) + respond_to do |format| + if (status == :ok) + format.html { render :template => "bbb/join" } + format.json { render :json => { :messageKey => messageKey, :message => message, :status => status, :response => response }, :status => status } + else + format.html { render :template => "errors/error" } + format.json { render :json => { :messageKey => messageKey, :message => message, :status => status, :response => response }, :status => status } + end + end + end +end diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index d33b4e2b..b02805b7 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -1,6 +1,8 @@ class LandingController < ApplicationController + include LandingHelper + def index @meeting_token = params[:id] || @meeting_token = rand.to_s[2..10] - @meeting_url = helpers.meeting_url(@meeting_token) + @meeting_url = meeting_url(@meeting_token) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be794..3b958476 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,24 @@ module ApplicationHelper + def bbb_endpoint + logger.info APP_CONFIG + #if ((defined? APP_CONFIG).to_s == 'constant') && (APP_CONFIG.has_key?('bbb_endpoint')) + # APP_CONFIG['bbb_endpoint'] + #else + 'http://test-install.blindsidenetworks.com/bigbluebutton/' + #end + end + + def bbb_secret + #if (defined? APP_CONFIG).to_s == 'constant' && (APP_CONFIG.has_key? 'bbb_secret') + # APP_CONFIG['bbb_secret'] + #else + '8cd8ef52e8e101574e400365b55e11a6' + #end + end + + def random_password(length) + o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten + password = (0...length).map { o[rand(o.length)] }.join + return password + end end diff --git a/app/helpers/bbb_helper.rb b/app/helpers/bbb_helper.rb new file mode 100644 index 00000000..d99712bf --- /dev/null +++ b/app/helpers/bbb_helper.rb @@ -0,0 +1,36 @@ +module BbbHelper + def bbb_join_url(meeting_token, meeting_recorded=false, user_fullname='User', user_is_moderator=false) + bbb ||= BigBlueButton::BigBlueButtonApi.new(helpers.bbb_endpoint + "api", bbb_secret, "0.8", true) + if !bbb + return { :returncode => false, :messageKey => "BBBAPICallInvalid", :message => "BBB API call invalid." } + else + meeting_id = (Digest::SHA1.hexdigest("Rails.application.secrets.secret_key_base"+meeting_token)).to_s + + #See if the meeting is running + begin + bbb_meeting_info = bbb.get_meeting_info( meeting_id, nil ) + rescue BigBlueButton::BigBlueButtonException => exc + logger.info "Message for the log file #{exc.key}: #{exc.message}" + #This means that is not created, so create the meeting + logout_url = "#{request.base_url}/bbb/close" #Closes the window after correct logout + moderator_password = random_password(12) + viewer_password = random_password(12) + meeting_options = {:record => meeting_recorded.to_s, :logoutURL => logout_url, :moderatorPW => moderator_password, :attendeePW => viewer_password } + bbb.create_meeting(meeting_token, meeting_id, meeting_options) + + #And then get meeting info + bbb_meeting_info = bbb.get_meeting_info( meeting_id, nil ) + end + + #Get the join url + if (user_is_moderator) + password = bbb_meeting_info[:moderatorPW] + else + passord = bbb_meeting_info[:attendeePW] + end + join_url = bbb.join_meeting_url(meeting_id, user_fullname, password ) + return { :returncode => true, :join_url => join_url, :messageKey => "", :message => "" } + end + end + +end diff --git a/app/views/bbb/end.html.erb b/app/views/bbb/end.html.erb new file mode 100644 index 00000000..ad2b2d3f --- /dev/null +++ b/app/views/bbb/end.html.erb @@ -0,0 +1,2 @@ +

Bbb#end

+

Find me in app/views/bbb/end.html.erb

diff --git a/app/views/bbb/join.html.erb b/app/views/bbb/join.html.erb new file mode 100644 index 00000000..55f29286 --- /dev/null +++ b/app/views/bbb/join.html.erb @@ -0,0 +1,2 @@ +

Bbb#join

+

Find me in app/views/bbb/join.html.erb

diff --git a/app/views/errors/error.html.erb b/app/views/errors/error.html.erb new file mode 100644 index 00000000..f3066b91 --- /dev/null +++ b/app/views/errors/error.html.erb @@ -0,0 +1,2 @@ +

Errors#error

+

Find me in app/views/errors/error.html.erb

diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb index 18eee059..9334ddba 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -13,13 +13,13 @@ -
-
+
+
- - + +
- +
@@ -38,11 +38,31 @@ - - - + - \ No newline at end of file + + + diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 00000000..e72a9fec --- /dev/null +++ b/config/config.yml @@ -0,0 +1,3 @@ +default: + bbb_endpoint: <%= ENV['BIGBLUEBUTTON_ENDPOINT'] %> + bbb_secret: <%= ENV['BIGBLUEBUTTON_SECRET'] %> diff --git a/config/initializers/load_config.rb b/config/initializers/load_config.rb new file mode 100644 index 00000000..46b175b5 --- /dev/null +++ b/config/initializers/load_config.rb @@ -0,0 +1 @@ +APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env] \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 57c3044e..4da8b4c6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + get 'bbb/join/:id', to: 'bbb#join', as: :bbb_join + get 'bbb/close' + get 'meeting(/:id)', to: 'landing#index' root to: 'landing#index' diff --git a/sample.env b/sample.env new file mode 100644 index 00000000..132c23d3 --- /dev/null +++ b/sample.env @@ -0,0 +1,8 @@ +# This is a sample of the environment variables you will need for development +# To use, copy this file to .env `cp sample.env .env` + +RAILS_ENV=development + +# BigBlueButton +BIGBLUEBUTTON_ENDPOINT=http://test-install.blindsidenetworks.com/bigbluebutton/ +BIGBLUEBUTTON_SECRET=8cd8ef52e8e101574e400365b55e11a6 \ No newline at end of file diff --git a/test/controllers/bbb_controller_test.rb b/test/controllers/bbb_controller_test.rb new file mode 100644 index 00000000..4c017be1 --- /dev/null +++ b/test/controllers/bbb_controller_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class BbbControllerTest < ActionDispatch::IntegrationTest + test "should get join" do + get bbb_join_url + assert_response :success + end + + test "should get end" do + get bbb_end_url + assert_response :success + end + +end