diff --git a/app/models/room.rb b/app/models/room.rb index 82650001..e657fd12 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -85,7 +85,7 @@ class Room < ApplicationRecord # Generates a uid for the room and BigBlueButton. 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.bbb_id = unique_bbb_id self.moderator_pw = RandomPassword.generate(length: 12) self.attendee_pw = RandomPassword.generate(length: 12) end @@ -100,4 +100,12 @@ class Room < ApplicationRecord def random_room_uid [owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase end + + # Generates a unique bbb_id based on uuid. + def unique_bbb_id + loop do + bbb_id = SecureRandom.hex(20) + break bbb_id unless Room.exists?(bbb_id: bbb_id) + end + end end