forked from External/greenlight
GRN2-180: First stages of refactoring code for v2.4 (#748)
* Email rescues and authenticator concern * Application controller and helper clean up * Moved controller code out of helpers * More helper and email clean up * Cleaned up remaining helpers and create omniauth_options * Controller code clean up * restructured views structure * Restructured role code * Restructured profile and code clean up * Master merge * Added bbb server concern to deal with bbb calls * Bug fixes and changes after changes * rspec * More rubocop fixes
This commit is contained in:
@ -19,128 +19,28 @@
|
||||
require 'bbb_api'
|
||||
|
||||
class Room < ApplicationRecord
|
||||
include ::BbbApi
|
||||
|
||||
before_create :setup
|
||||
|
||||
before_destroy :delete_all_recordings
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
belongs_to :owner, class_name: 'User', foreign_key: :user_id
|
||||
|
||||
META_LISTED = "gl-listed"
|
||||
|
||||
# Determines if a user owns a room.
|
||||
def owned_by?(user)
|
||||
return false if user.nil?
|
||||
user.rooms.include?(self)
|
||||
end
|
||||
|
||||
# Checks if a room is running on the BigBlueButton server.
|
||||
def running?
|
||||
bbb(owner.provider).is_meeting_running?(bbb_id)
|
||||
end
|
||||
|
||||
# Determines the invite path for the room.
|
||||
def invite_path
|
||||
"#{Rails.configuration.relative_url_root}/#{CGI.escape(uid)}"
|
||||
end
|
||||
|
||||
# Creates a meeting on the BigBlueButton server.
|
||||
def start_session(options = {})
|
||||
create_options = {
|
||||
record: options[:meeting_recorded].to_s,
|
||||
logoutURL: options[:meeting_logout_url] || '',
|
||||
moderatorPW: moderator_pw,
|
||||
attendeePW: attendee_pw,
|
||||
moderatorOnlyMessage: options[:moderator_message],
|
||||
muteOnStart: options[:mute_on_start] || false,
|
||||
"meta_#{META_LISTED}": options[:recording_default_visibility] || false,
|
||||
"meta_bbb-origin-version": Greenlight::Application::VERSION,
|
||||
"meta_bbb-origin": "Greenlight",
|
||||
"meta_bbb-origin-server-name": options[:host]
|
||||
}
|
||||
|
||||
create_options[:guestPolicy] = "ASK_MODERATOR" if options[:require_moderator_approval]
|
||||
|
||||
# Send the create request.
|
||||
begin
|
||||
meeting = bbb(owner.provider).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 => e
|
||||
puts "BigBlueButton failed on create: #{e.key}: #{e.message}"
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a URL to join a user into a meeting.
|
||||
def join_path(name, options = {}, uid = nil)
|
||||
# Create the meeting, even if it's running
|
||||
start_session(options)
|
||||
|
||||
# Set meeting options.
|
||||
options[:meeting_logout_url] ||= nil
|
||||
options[:moderator_message] ||= ''
|
||||
options[:user_is_moderator] ||= false
|
||||
options[:meeting_recorded] ||= false
|
||||
|
||||
return call_invalid_res unless bbb(owner.provider)
|
||||
|
||||
# Get the meeting info.
|
||||
meeting_info = bbb(owner.provider).get_meeting_info(bbb_id, nil)
|
||||
|
||||
# Determine the password to use when joining.
|
||||
password = if options[:user_is_moderator]
|
||||
meeting_info[:moderatorPW]
|
||||
else
|
||||
meeting_info[:attendeePW]
|
||||
end
|
||||
|
||||
# Generate the join URL.
|
||||
join_opts = {}
|
||||
join_opts[:userID] = uid if uid
|
||||
join_opts[:join_via_html5] = true
|
||||
|
||||
join_opts[:guest] = true if options[:require_moderator_approval] && !options[:user_is_moderator]
|
||||
|
||||
bbb(owner.provider).join_meeting_url(bbb_id, name, password, join_opts)
|
||||
end
|
||||
|
||||
# Notify waiting users that a meeting has started.
|
||||
def notify_waiting
|
||||
ActionCable.server.broadcast("#{uid}_waiting_channel", action: "started")
|
||||
end
|
||||
|
||||
# Retrieves all the users in a room.
|
||||
def participants
|
||||
res = bbb(owner.provider).get_meeting_info(bbb_id, nil)
|
||||
res[:attendees].map do |att|
|
||||
User.find_by(uid: att[:userID], name: att[:fullName])
|
||||
end
|
||||
rescue BigBlueButton::BigBlueButtonException
|
||||
# The meeting is most likely not running.
|
||||
[]
|
||||
end
|
||||
|
||||
def recording_count
|
||||
bbb(owner.provider).get_recordings(meetingID: bbb_id)[:recordings].length
|
||||
end
|
||||
|
||||
def update_recording(record_id, meta)
|
||||
meta[:recordID] = record_id
|
||||
bbb(owner.provider).send_api_request("updateRecordings", meta)
|
||||
end
|
||||
|
||||
# Deletes a recording from a room.
|
||||
def delete_recording(record_id)
|
||||
bbb(owner.provider).delete_recordings(record_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Generates a uid for the room and BigBlueButton.
|
||||
@ -151,12 +51,6 @@ class Room < ApplicationRecord
|
||||
self.attendee_pw = RandomPassword.generate(length: 12)
|
||||
end
|
||||
|
||||
# Deletes all recordings associated with the room.
|
||||
def delete_all_recordings
|
||||
record_ids = bbb(owner.provider).get_recordings(meetingID: bbb_id)[:recordings].pluck(:recordID)
|
||||
delete_recording(record_ids) unless record_ids.empty?
|
||||
end
|
||||
|
||||
# Generates a three character uid chunk.
|
||||
def uid_chunk
|
||||
charset = ("a".."z").to_a - %w(b i l o s) + ("2".."9").to_a - %w(5 8)
|
||||
|
Reference in New Issue
Block a user