Class: BigbluebuttonRoom
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BigbluebuttonRoom
- Includes:
- ActiveModel::ForbiddenAttributesProtection
- Defined in:
- app/models/bigbluebutton_room.rb
Instance Attribute Summary collapse
-
#attendees ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#end_time ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#full_logout_url ⇒ Object
the full logout_url used when logout_url is a relative path.
-
#has_been_forcibly_ended ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#moderator_count ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#participant_count ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#request_headers ⇒ Object
HTTP headers that will be passed to the BigBlueButtonApi object to send in all GET/POST requests to a webconf server.
-
#running ⇒ Object
Note: these params need to be fetched from the server before being accessed.
-
#start_time ⇒ Object
Note: these params need to be fetched from the server before being accessed.
Instance Method Summary collapse
-
#add_domain_to_logout_url(protocol, host) ⇒ Object
add a domain name and/or protocol to the logout_url if needed it doesn’t save in the db, just updates the instance.
-
#attr_equal?(o) ⇒ Boolean
A more complete equal? method, comparing also the attibutes and the instance variables.
-
#create_meeting(user = nil, request = nil, user_opts = {}) ⇒ Object
The create logic.
-
#fetch_is_running? ⇒ Boolean
Fetches the BBB server to see if the meeting is running.
-
#fetch_meeting_info ⇒ Object
Fetches info from BBB about this room.
-
#fetch_new_token ⇒ Object
Gets a ‘configToken’ to use when joining the room.
-
#finish_meetings ⇒ Object
Sets all meetings related to this room as not running.
-
#get_current_meeting ⇒ Object
Returns the current meeting running on this room, if any.
-
#instance_variables_compare(o) ⇒ Object
Compare the instance variables of two models to define if they are equal Returns a hash with the variables with different values or an empty hash if they are have all equal values.
-
#is_running? ⇒ Boolean
Convenience method to access the attribute
running. -
#join_url(username, role, password = nil, options = {}) ⇒ Object
Returns the URL to join this room.
-
#room_options_with_initialize ⇒ Object
In case there’s no room_options created yet, build one (happens usually when an old database is migrated).
-
#send_create(user = nil, user_opts = {}) ⇒ Object
Sends a call to the BBB server to create the meeting.
-
#send_end ⇒ Object
Sends a call to the BBB server to end the meeting.
- #to_param ⇒ Object
- #unique_meetingid ⇒ Object
-
#update_current_meeting(metadata = nil) ⇒ Object
Updates the current meeting associated with this room.
-
#user_role(params) ⇒ Object
Returns the role of the user based on the password given.
Instance Attribute Details
#attendees ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def attendees @attendees end |
#end_time ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def end_time @end_time end |
#full_logout_url ⇒ Object
the full logout_url used when logout_url is a relative path
72 73 74 |
# File 'app/models/bigbluebutton_room.rb', line 72 def full_logout_url @full_logout_url end |
#has_been_forcibly_ended ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def has_been_forcibly_ended @has_been_forcibly_ended end |
#moderator_count ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def moderator_count @moderator_count end |
#participant_count ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def participant_count @participant_count end |
#request_headers ⇒ Object
HTTP headers that will be passed to the BigBlueButtonApi object to send in all GET/POST requests to a webconf server. Currently used to send the client’s IP to the load balancer.
77 78 79 |
# File 'app/models/bigbluebutton_room.rb', line 77 def request_headers @request_headers end |
#running ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def running @running end |
#start_time ⇒ Object
Note: these params need to be fetched from the server before being accessed
63 64 65 |
# File 'app/models/bigbluebutton_room.rb', line 63 def start_time @start_time end |
Instance Method Details
#add_domain_to_logout_url(protocol, host) ⇒ Object
add a domain name and/or protocol to the logout_url if needed it doesn’t save in the db, just updates the instance
263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'app/models/bigbluebutton_room.rb', line 263 def add_domain_to_logout_url(protocol, host) unless logout_url.nil? url = logout_url.downcase unless url.nil? or url =~ /^[a-z]+:\/\// # matches the protocol unless url =~ /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*/ # matches the host domain url = host + url end url = protocol + url end self.full_logout_url = url.downcase end end |
#attr_equal?(o) ⇒ Boolean
A more complete equal? method, comparing also the attibutes and the instance variables
237 238 239 240 241 |
# File 'app/models/bigbluebutton_room.rb', line 237 def attr_equal?(o) self == o and self.instance_variables_compare(o).empty? and self.attributes == o.attributes end |
#create_meeting(user = nil, request = nil, user_opts = {}) ⇒ Object
The create logic. Will create the meeting in this room unless it is already running. Returns true if the meeting was created.
250 251 252 253 254 255 256 257 258 259 |
# File 'app/models/bigbluebutton_room.rb', line 250 def create_meeting(user=nil, request=nil, user_opts={}) fetch_is_running? unless is_running? add_domain_to_logout_url(request.protocol, request.host_with_port) unless request.nil? send_create(user, user_opts) true else false end end |
#fetch_is_running? ⇒ Boolean
Fetches the BBB server to see if the meeting is running. Sets running
Triggers API call: isMeetingRunning.
134 135 136 137 |
# File 'app/models/bigbluebutton_room.rb', line 134 def fetch_is_running? require_server @running = self.server.api.is_meeting_running?(self.meetingid) end |
#fetch_meeting_info ⇒ Object
Fetches info from BBB about this room. The response is parsed and stored in the model. You can access it using attributes such as:
room.participant_count
room.attendees[0].full_name
The attributes changed are:
-
participant_count -
moderator_count -
running -
has_been_forcibly_ended -
start_time -
end_time -
attendees(array ofBigbluebuttonAttendee)
Triggers API call: getMeetingInfo.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/models/bigbluebutton_room.rb', line 107 def fetch_meeting_info require_server response = self.server.api.get_meeting_info(self.meetingid, self.moderator_password) @participant_count = response[:participantCount] @moderator_count = response[:moderatorCount] @running = response[:running] @has_been_forcibly_ended = response[:hasBeenForciblyEnded] @start_time = response[:startTime] @end_time = response[:endTime] @attendees = [] response[:attendees].each do |att| attendee = BigbluebuttonAttendee.new attendee.from_hash(att) @attendees << attendee end # a 'shortcut' to update meetings since we have all information we need update_current_meeting(response[:metadata]) response end |
#fetch_new_token ⇒ Object
Gets a ‘configToken’ to use when joining the room. Returns a string with the token generated or nil if there’s no need for a token (the options set in the room are the default options or there are no options set in the room) or if an error occurred.
The entire process consists in these steps:
-
Go to the server get the default config.xml;
-
Modify the config.xml based on the room options set in the room;
-
Go to the server set the new config.xml;
-
Get the token identifier and return it.
Triggers API call: getDefaultConfigXML. Triggers API call: setConfigXML.
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'app/models/bigbluebutton_room.rb', line 347 def fetch_new_token if self..is_modified? # get the default XML we will use to create a new one config_xml = self.server.api.get_default_config_xml # set the options on the XML # returns true if something was changed config_xml = self..set_on_config_xml(config_xml) if config_xml # get the new token for the room, and return it self.server.api.set_config_xml(self.meetingid, config_xml) else nil end else nil end end |
#finish_meetings ⇒ Object
Sets all meetings related to this room as not running
328 329 330 331 332 |
# File 'app/models/bigbluebutton_room.rb', line 328 def finish_meetings BigbluebuttonMeeting.where(:running => true) .find_by_room_id(room_id) .update_attributes(:running => false) end |
#get_current_meeting ⇒ Object
Returns the current meeting running on this room, if any.
284 285 286 287 288 289 290 |
# File 'app/models/bigbluebutton_room.rb', line 284 def get_current_meeting unless self.start_time.nil? BigbluebuttonMeeting.find_by_room_id_and_start_time(self.id, self.start_time.utc) else nil end end |
#instance_variables_compare(o) ⇒ Object
Compare the instance variables of two models to define if they are equal Returns a hash with the variables with different values or an empty hash if they are have all equal values. From: alicebobandmallory.com/articles/2009/11/02/comparing-instance-variables-in-ruby
227 228 229 230 231 232 233 |
# File 'app/models/bigbluebutton_room.rb', line 227 def instance_variables_compare(o) vars = [ :@running, :@participant_count, :@moderator_count, :@attendees, :@has_been_forcibly_ended, :@start_time, :@end_time ] Hash[*vars.map { |v| self.instance_variable_get(v)!=o.instance_variable_get(v) ? [v,o.instance_variable_get(v)] : []}.flatten] end |
#is_running? ⇒ Boolean
Convenience method to access the attribute running
87 88 89 |
# File 'app/models/bigbluebutton_room.rb', line 87 def is_running? @running end |
#join_url(username, role, password = nil, options = {}) ⇒ Object
Returns the URL to join this room.
- username
-
Name of the user
- role
-
Role of the user in this room. Can be
[:moderator, :attendee] - password
-
Password to be use (in case role == nil)
- options
-
Additional options to use when generating the URL
Uses the API but does not require a request to the server.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/bigbluebutton_room.rb', line 190 def join_url(username, role, password=nil, ={}) require_server case role when :moderator r = self.server.api.join_meeting_url(self.meetingid, username, self.moderator_password, ) when :attendee r = self.server.api.join_meeting_url(self.meetingid, username, self.attendee_password, ) else r = self.server.api.join_meeting_url(self.meetingid, username, password, ) end r.strip! unless r.nil? r end |
#room_options_with_initialize ⇒ Object
In case there’s no room_options created yet, build one (happens usually when an old database is migrated).
81 82 83 |
# File 'app/models/bigbluebutton_room.rb', line 81 def || end |
#send_create(user = nil, user_opts = {}) ⇒ Object
Sends a call to the BBB server to create the meeting. ‘user’ is the object that represents the user that is creating the meeting. ‘user_opts’ is a hash of parameters to override the parameters sent in the create
request. Can be passed by the application to enforce some values over the values
that are taken from the database.
Will trigger ‘select_server’ to select a server where the meeting will be created. If a server is selected, the model is saved.
With the response, updates the following attributes:
-
attendee_password -
moderator_password
Triggers API call: create.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/models/bigbluebutton_room.rb', line 166 def send_create(user=nil, user_opts={}) # updates the server whenever a meeting will be created and guarantees it has a meetingid self.server = select_server self.meetingid = unique_meetingid() if self.meetingid.nil? self.save unless self.new_record? require_server response = internal_create_meeting(user, user_opts) unless response.nil? self.attendee_password = response[:attendeePW] self.moderator_password = response[:moderatorPW] self.save unless self.new_record? end response end |
#send_end ⇒ Object
Sends a call to the BBB server to end the meeting.
Triggers API call: end.
142 143 144 145 146 147 148 149 150 |
# File 'app/models/bigbluebutton_room.rb', line 142 def send_end require_server response = self.server.api.end_meeting(self.meetingid, self.moderator_password) # enqueue an update in the meetings for later on Resque.enqueue(::BigbluebuttonMeetingUpdater, self.id, 15.seconds) response end |
#to_param ⇒ Object
243 244 245 |
# File 'app/models/bigbluebutton_room.rb', line 243 def to_param self.param end |
#unique_meetingid ⇒ Object
276 277 278 279 280 281 |
# File 'app/models/bigbluebutton_room.rb', line 276 def unique_meetingid # GUID # Has to be globally unique in case more that one bigbluebutton_rails application is using # the same web conference server. "#{SecureRandom.uuid}-#{Time.now.to_i}" end |
#update_current_meeting(metadata = nil) ⇒ Object
Updates the current meeting associated with this room
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'app/models/bigbluebutton_room.rb', line 293 def update_current_meeting(=nil) unless self.start_time.nil? attrs = { :server => self.server, :meetingid => self.meetingid, :name => self.name, :record => self.record, :running => self.running } unless .nil? begin attrs[:creator_id] = [BigbluebuttonRails.].to_i attrs[:creator_name] = [BigbluebuttonRails.] rescue attrs[:creator_id] = nil attrs[:creator_name] = nil end end meeting = self.get_current_meeting if !meeting.nil? meeting.update_attributes(attrs) # only create a new meeting if it is running elsif self.running attrs.merge!({ :room => self, :start_time => self.start_time.utc }) meeting = BigbluebuttonMeeting.create(attrs) end else # TODO: not enough information to find the meeting, do what? end end |
#user_role(params) ⇒ Object
Returns the role of the user based on the password given. The return value can be :moderator, :attendee, or nil if the password given does not match any of the room passwords.
- params
-
Hash with a key :password
211 212 213 214 215 216 217 218 219 220 221 |
# File 'app/models/bigbluebutton_room.rb', line 211 def user_role(params) role = nil if params && params.has_key?(:password) if self.moderator_password == params[:password] role = :moderator elsif self.attendee_password == params[:password] role = :attendee end end role end |