add end meeting to bbb controller

This commit is contained in:
Zachary Chai 2016-11-04 16:32:10 -04:00
parent c9aaf2346a
commit e11098c7a9
4 changed files with 57 additions and 16 deletions

View File

@ -1,7 +1,8 @@
class BbbController < ApplicationController class BbbController < ApplicationController
include BbbApi include BbbApi
before_action :authorize_owner_recording, only: [:update_recordings, :delete_recordings] before_action :authorize_recording_owner!, only: [:update_recordings, :delete_recordings]
before_action :load_and_authorize_room_owner!, only: [:end]
# GET /:resource/:id/join # GET /:resource/:id/join
def join def join
@ -36,12 +37,17 @@ class BbbController < ApplicationController
end end
end end
# DELETE /rooms/:id/end
def end
load_and_authorize_room_owner!
bbb_res = bbb_end_meeting @user.username
render_bbb_response bbb_res
end
# GET /rooms/:id/recordings # GET /rooms/:id/recordings
def recordings def recordings
@user = User.find_by username: params[:id] load_room!
if !@user
render head(:not_found) && return
end
bbb_res = bbb_get_recordings @user.username bbb_res = bbb_get_recordings @user.username
render_bbb_response bbb_res, bbb_res[:recordings] render_bbb_response bbb_res, bbb_res[:recordings]
@ -64,18 +70,27 @@ class BbbController < ApplicationController
private private
def authorize_owner_recording def load_room!
user = User.find_by username: params[:id] @user = User.find_by username: params[:id]
if !user if !@user
render head(:not_found) && return render head(:not_found) && return
elsif !current_user || current_user != user end
end
def load_and_authorize_room_owner!
load_room!
if !current_user || current_user != @user
render head(:unauthorized) && return render head(:unauthorized) && return
end end
end
def authorize_recording_owner!
load_and_authorize_room_owner!
recordings = bbb_get_recordings(params[:id])[:recordings] recordings = bbb_get_recordings(params[:id])[:recordings]
recordings.each do |recording| recordings.each do |recording|
if recording[:recordID] == params[:record_id] if recording[:recordID] == params[:record_id]
@user = user
return true return true
end end
end end
@ -87,6 +102,6 @@ class BbbController < ApplicationController
@message = bbb_res[:message] @message = bbb_res[:message]
@status = bbb_res[:status] @status = bbb_res[:status]
@response = response @response = response
render status: @status && return render status: @status
end end
end end

View File

@ -11,6 +11,10 @@ module BbbApi
@bbb ||= BigBlueButton::BigBlueButtonApi.new(bbb_endpoint + "api", bbb_secret, "0.8", true) @bbb ||= BigBlueButton::BigBlueButtonApi.new(bbb_endpoint + "api", bbb_secret, "0.8", true)
end end
def bbb_meeting_id(id)
Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+id).to_s
end
def random_password(length) def random_password(length)
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
password = (0...length).map { o[rand(o.length)] }.join password = (0...length).map { o[rand(o.length)] }.join
@ -26,7 +30,7 @@ module BbbApi
if !bbb if !bbb
return call_invalid_res return call_invalid_res
else else
meeting_id = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_token)).to_s meeting_id = bbb_meeting_id(meeting_token)
# See if the meeting is running # See if the meeting is running
begin begin
@ -63,7 +67,7 @@ module BbbApi
password = bbb_meeting_info[:attendeePW] password = bbb_meeting_info[:attendeePW]
end end
join_url = bbb.join_meeting_url(meeting_id, full_name, password ) join_url = bbb.join_meeting_url(meeting_id, full_name, password )
return success_res(join_url) return success_join_res(join_url)
end end
end end
@ -124,6 +128,22 @@ module BbbApi
res res
end end
def bbb_end_meeting(id)
# get meeting info for moderator password
meeting_id = bbb_meeting_id(id)
bbb_meeting_info = bbb.get_meeting_info(meeting_id, nil)
response_data = if bbb_meeting_info.is_a?(Hash) && bbb_meeting_info[:moderatorPW]
bbb.end_meeting(meeting_id, bbb_meeting_info[:moderatorPW])
else
{}
end
response_data[:status] = :ok
response_data
rescue BigBlueButton::BigBlueButtonException => exc
response_data = bbb_exception_res exc
end
def bbb_update_recordings(id, published) def bbb_update_recordings(id, published)
bbb_safe_execute :publish_recordings, id, published bbb_safe_execute :publish_recordings, id, published
end end
@ -147,7 +167,7 @@ module BbbApi
response_data response_data
end end
def success_res(join_url) def success_join_res(join_url)
{ {
returncode: true, returncode: true,
messageKey: "ok", messageKey: "ok",
@ -178,11 +198,15 @@ module BbbApi
end end
def bbb_exception_res(exc) def bbb_exception_res(exc)
{ res = {
returncode: false, returncode: false,
messageKey: 'BBB'+exc.key.capitalize.underscore, messageKey: 'BBB'+exc.key.capitalize.underscore,
message: exc.message, message: exc.message,
status: :internal_server_error status: :unprocessable_entity
} }
if res[:messageKey] == 'BBBnotfound'
res[:status] = :not_found
end
res
end end
end end

View File

@ -0,0 +1 @@
json.partial! 'bbb', messageKey: @messageKey, message: @message, status: @status

View File

@ -13,6 +13,7 @@ Rails.application.routes.draw do
get '/:resource/:id', to: 'landing#index', as: :resource get '/:resource/:id', to: 'landing#index', as: :resource
get '/:resource/:id/join', to: 'bbb#join', as: :bbb_join, defaults: {format: 'json'} get '/:resource/:id/join', to: 'bbb#join', as: :bbb_join, defaults: {format: 'json'}
get '/:resource/:id/wait', to: 'landing#wait_for_moderator' get '/:resource/:id/wait', to: 'landing#wait_for_moderator'
delete '/rooms/:id/end', to: 'bbb#end', defaults: {format: 'json'}
get '/rooms/:id/recordings', to: 'bbb#recordings', defaults: {format: 'json'} get '/rooms/:id/recordings', to: 'bbb#recordings', defaults: {format: 'json'}
patch '/rooms/:id/recordings/:record_id', to: 'bbb#update_recordings', defaults: {format: 'json'} patch '/rooms/:id/recordings/:record_id', to: 'bbb#update_recordings', defaults: {format: 'json'}
delete '/rooms/:id/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {format: 'json'} delete '/rooms/:id/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {format: 'json'}