handle errors and fix join form

This commit is contained in:
Josh
2018-06-11 13:05:54 -04:00
parent 2b0f75e62b
commit 2b065eb7fa
23 changed files with 114 additions and 239 deletions

View File

@ -7,7 +7,6 @@ class Room < ApplicationRecord
belongs_to :owner, class_name: 'User', foreign_key: :user_id
has_one :meeting
ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
RETURNCODE_SUCCESS = "SUCCESS"
# Determines if a user owns a room.
@ -21,19 +20,6 @@ class Room < ApplicationRecord
bbb.is_meeting_running?(bbb_id)
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Determines the invite URL for the room.
def invite_path
"/r/#{uid}"
@ -68,7 +54,7 @@ class Room < ApplicationRecord
end
# Returns a URL to join a user into a meeting.
def join_path(user, options = {})
def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running.
start_session(options) unless is_running?
@ -95,10 +81,10 @@ class Room < ApplicationRecord
end
# Generate the join URL.
if user.is_a?(User)
bbb.join_meeting_url(bbb_id, user.name, password, {userID: user.uid})
if uid
bbb.join_meeting_url(bbb_id, name, password, {userID: uid})
else
bbb.join_meeting_url(bbb_id, user, password)
bbb.join_meeting_url(bbb_id, name, password)
end
end
@ -109,6 +95,19 @@ class Room < ApplicationRecord
})
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Fetches all recordings for a meeting.
def recordings
res = bbb.get_recordings(meetingID: bbb_id)
@ -168,8 +167,6 @@ class Room < ApplicationRecord
def setup
self.uid = [owner.firstname, (0...9).map { (65 + rand(26)).chr }.join].join('-').downcase
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
self.icon = ROOM_ICONS.sample
end
# Rereives the loadbalanced BigBlueButton credentials for a user.