refactor bbb helper and implement wait for mod

This commit is contained in:
Zachary Chai
2016-10-26 13:41:55 -04:00
parent dadaa52387
commit 3aeef0a4cf
9 changed files with 98 additions and 37 deletions

View File

@ -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