forked from External/greenlight
refactor bbb helper and implement wait for mod
This commit is contained in:
parent
dadaa52387
commit
3aeef0a4cf
|
@ -33,16 +33,22 @@
|
|||
var link = window.location.protocol +
|
||||
'//' +
|
||||
window.location.hostname +
|
||||
'/' +
|
||||
'meetings/' +
|
||||
'/meetings/' +
|
||||
Math.trunc(Math.random() * 1000000000);
|
||||
|
||||
$('.meeting-url').val(link);
|
||||
});
|
||||
|
||||
|
||||
$('.meeting-url').val('');
|
||||
if (meetingId = $('.meeting-url').data('meetingId')) {
|
||||
var link = window.location.protocol +
|
||||
'//' +
|
||||
window.location.hostname +
|
||||
'/meetings/' +
|
||||
meetingId;
|
||||
$('.meeting-url').val(link)
|
||||
} else {
|
||||
$('.generate-link').click();
|
||||
}
|
||||
};
|
||||
|
||||
var initRooms = function() {
|
||||
|
|
|
@ -1,33 +1,40 @@
|
|||
class BbbController < ApplicationController
|
||||
|
||||
# GET /join
|
||||
# GET /join.json
|
||||
# GET /:resource/:id/join
|
||||
def join
|
||||
if ( !params.has_key?(:id) )
|
||||
if ( !params[:id] )
|
||||
render_response("missing_parameter", "meeting token was not included", :bad_request)
|
||||
elsif ( !params.has_key?(:name) )
|
||||
elsif ( !params[:name] )
|
||||
render_response("missing_parameter", "user name was not included", :bad_request)
|
||||
else
|
||||
bbb_join_url = helpers.bbb_join_url(params[:id], false, params[:name], false, "#{request.base_url}/#{params[:resource]}/#{params[:id]}")
|
||||
if bbb_join_url[:returncode]
|
||||
logger.info "#Execute the redirect"
|
||||
render_response("ok", "execute the redirect", :ok, {:join_url => bbb_join_url[:join_url]})
|
||||
user = User.find_by username: params[:id]
|
||||
|
||||
options = if user
|
||||
{
|
||||
wait_for_moderator: true,
|
||||
user_is_moderator: current_user == user
|
||||
}
|
||||
else
|
||||
render_response("bigbluebutton_error", "join url could not be created", :internal_server_error)
|
||||
{}
|
||||
end
|
||||
options[:meeting_logout_url] = "#{request.base_url}/#{params[:resource]}/#{params[:id]}"
|
||||
|
||||
bbb_res = helpers.bbb_join_url(
|
||||
params[:id],
|
||||
params[:name],
|
||||
options
|
||||
)
|
||||
|
||||
render_response bbb_res[:messageKey], bbb_res[:message], bbb_res[:status], bbb_res[:response]
|
||||
end
|
||||
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
|
||||
@messageKey = messageKey
|
||||
@message = message
|
||||
@status = status
|
||||
@response = response
|
||||
render status: @status && return
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,7 @@ class LandingController < ApplicationController
|
|||
private
|
||||
|
||||
def render_meeting
|
||||
@meeting_id = params[:id]
|
||||
params[:action] = 'meetings'
|
||||
render :action => 'meeting'
|
||||
end
|
||||
|
|
|
@ -13,10 +13,15 @@ module BbbHelper
|
|||
return password
|
||||
end
|
||||
|
||||
def bbb_join_url(meeting_token, meeting_recorded=false, user_fullname='User', user_is_moderator=false, meeting_logout_url=nil)
|
||||
def bbb_join_url(meeting_token, full_name, options={})
|
||||
options[:meeting_recorded] ||= false
|
||||
options[:user_is_moderator] ||= false
|
||||
options[:wait_for_moderator] ||= false
|
||||
options[:meeting_logout_url] ||= nil
|
||||
|
||||
bbb ||= BigBlueButton::BigBlueButtonApi.new(bbb_endpoint + "api", bbb_secret, "0.8", true)
|
||||
if !bbb
|
||||
return { :returncode => false, :messageKey => "BBBAPICallInvalid", :message => "BBB API call invalid." }
|
||||
return call_invalid_res
|
||||
else
|
||||
meeting_id = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_token)).to_s
|
||||
|
||||
|
@ -24,14 +29,18 @@ module BbbHelper
|
|||
begin
|
||||
bbb_meeting_info = bbb.get_meeting_info( meeting_id, nil )
|
||||
rescue BigBlueButton::BigBlueButtonException => exc
|
||||
if options[:wait_for_moderator] && !options[:user_is_moderator]
|
||||
return wait_moderator_res
|
||||
end
|
||||
|
||||
# This means that is not created
|
||||
logger.info "Message for the log file #{exc.key}: #{exc.message}"
|
||||
|
||||
# Prepare parameters for create
|
||||
logout_url = meeting_logout_url || logout_url = "#{request.base_url}"
|
||||
logout_url = options[:meeting_logout_url] || "#{request.base_url}"
|
||||
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 }
|
||||
meeting_options = {:record => options[:meeting_recorded].to_s, :logoutURL => logout_url, :moderatorPW => moderator_password, :attendeePW => viewer_password }
|
||||
|
||||
# Create the meeting
|
||||
bbb.create_meeting(meeting_token, meeting_id, meeting_options)
|
||||
|
@ -40,14 +49,48 @@ module BbbHelper
|
|||
bbb_meeting_info = bbb.get_meeting_info( meeting_id, nil )
|
||||
end
|
||||
|
||||
if options[:wait_for_moderator] && !options[:user_is_moderator] && bbb_meeting_info[:moderatorCount] <= 0
|
||||
return wait_moderator_res
|
||||
end
|
||||
|
||||
# Get the join url
|
||||
if (user_is_moderator)
|
||||
if (options[:user_is_moderator])
|
||||
password = bbb_meeting_info[:moderatorPW]
|
||||
else
|
||||
password = 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 => "" }
|
||||
join_url = bbb.join_meeting_url(meeting_id, full_name, password )
|
||||
return success_res(join_url)
|
||||
end
|
||||
end
|
||||
|
||||
def success_res(join_url)
|
||||
{
|
||||
returncode: true,
|
||||
messageKey: "ok",
|
||||
message: "Execute the redirect",
|
||||
status: :ok,
|
||||
response: {
|
||||
join_url: join_url
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def wait_moderator_res
|
||||
{
|
||||
returncode: false,
|
||||
messageKey: "WaitModerator",
|
||||
message: "Waiting for moderator",
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
|
||||
def call_invalid_res
|
||||
{
|
||||
returncode: false,
|
||||
messageKey: "BBBAPICallInvalid",
|
||||
message: "BBB API call invalid.",
|
||||
status: :internal_server_error
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
<h1>Bbb#end</h1>
|
||||
<p>Find me in app/views/bbb/end.html.erb</p>
|
|
@ -1,2 +0,0 @@
|
|||
<h1>Bbb#join</h1>
|
||||
<p>Find me in app/views/bbb/join.html.erb</p>
|
|
@ -0,0 +1,8 @@
|
|||
json.messageKey @messageKey
|
||||
json.message @message
|
||||
json.status @status
|
||||
if @response
|
||||
json.response do
|
||||
json.join_url(@response[:join_url]) if @response[:join_url]
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
<div <%= "hidden" if hidden %> class="meetin-url-wrapper">
|
||||
<div <%= "hidden" if hidden %> class="meeting-url-wrapper">
|
||||
<div class="input-group">
|
||||
<input type="text" readonly="readonly" class="form-control meeting-url" data-path="<%= @user.room_url if @user %>"/>
|
||||
<input type="text" readonly="readonly" class="form-control meeting-url" data-meeting-id="<%= @meeting_id %>" data-path="<%= @user.room_url if @user %>"/>
|
||||
<span class="input-group-btn">
|
||||
<button type="button" class="btn btn-default meeting-url-copy">
|
||||
<i class="fa fa-paperclip" aria-hidden="true"></i>
|
||||
|
|
|
@ -8,7 +8,7 @@ Rails.application.routes.draw do
|
|||
# meetings offer a landing page for NON authenticated users to create and join session in BigBlueButton
|
||||
# rooms offer a customized landing page for authenticated users to create and join session in BigBlueButton
|
||||
get '/:resource(/:id)', to: 'landing#index', as: :resource
|
||||
get '/:resource/:id/join', to: 'bbb#join', as: :bbb_join
|
||||
get '/:resource/:id/join', to: 'bbb#join', as: :bbb_join, defaults: { :format => 'json' }
|
||||
|
||||
root to: 'landing#index', :resource => "meetings"
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
|
|
Loading…
Reference in New Issue