Persist password (#393)

* never hold the owner of the room on the waiting screen

* persist room passwords so we can always call create meeting, even if it's already running, to avoid any inconsistency or race condition when joining a meeting

* Fixed issues in migration, room attribute updates, random_password and tests
This commit is contained in:
Jesus Federico
2019-03-12 17:54:57 -04:00
committed by GitHub
parent 3195bb4429
commit 08f6f32779
7 changed files with 39 additions and 20 deletions

View File

@ -51,19 +51,20 @@ class Room < ApplicationRecord
create_options = {
record: options[:meeting_recorded].to_s,
logoutURL: options[:meeting_logout_url] || '',
moderatorPW: random_password(12),
attendeePW: random_password(12),
moderatorPW: moderator_pw,
attendeePW: attendee_pw,
moderatorOnlyMessage: options[:moderator_message],
muteOnStart: options[:mute_on_start] || false,
"meta_#{META_LISTED}": false,
}
# Update session info.
update_attributes(sessions: sessions + 1, last_session: DateTime.now)
# Send the create request.
begin
bbb.create_meeting(name, bbb_id, create_options)
meeting = bbb.create_meeting(name, bbb_id, create_options)
# Update session info.
unless meeting[:messageKey] == 'duplicateWarning'
update_attributes(sessions: sessions + 1, last_session: DateTime.now)
end
rescue BigBlueButton::BigBlueButtonException => exc
puts "BigBlueButton failed on create: #{exc.key}: #{exc.message}"
raise exc
@ -72,8 +73,8 @@ class Room < ApplicationRecord
# Returns a URL to join a user into a meeting.
def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running.
start_session(options) unless running?
# Create the meeting, even if it's running
start_session(options)
# Set meeting options.
options[:meeting_logout_url] ||= nil
@ -145,6 +146,8 @@ class Room < ApplicationRecord
def setup
self.uid = random_room_uid
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
self.moderator_pw = RandomPassword.generate(length: 12)
self.attendee_pw = RandomPassword.generate(length: 12)
end
# Deletes all recordings associated with the room.
@ -163,10 +166,4 @@ class Room < ApplicationRecord
def random_room_uid
[owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase
end
# Generates a random password for a meeting.
def random_password(length)
charset = ("a".."z").to_a + ("A".."Z").to_a
((0...length).map { charset[rand(charset.length)] }).join
end
end