Class: BigbluebuttonServer

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection
Defined in:
app/models/bigbluebutton_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#meetingsObject (readonly)

Array of BigbluebuttonMeeting



54
55
56
# File 'app/models/bigbluebutton_server.rb', line 54

def meetings
  @meetings
end

Instance Method Details

#apiObject

Returns the API object (BigBlueButton::BigBlueButtonAPI defined in bigbluebutton-api-ruby) associated with this server.



73
74
75
76
77
78
79
# File 'app/models/bigbluebutton_server.rb', line 73

def api
  return @api if @api.present?

  version = self.version
  version = set_api_version_from_server if version.blank?
  @api = BigBlueButton::BigBlueButtonApi.new(self.url, self.secret, version.to_s, false)
end

#config_with_initializeObject

In case there’s no config created yet, build one.



66
67
68
# File 'app/models/bigbluebutton_server.rb', line 66

def config_with_initialize
  config_without_initialize || build_config
end

#fetch_meetingsObject

Fetches the meetings currently created in the server (running or not).

Using the response, updates meetings with a list of BigbluebuttonMeeting objects.

Triggers API call: getMeetings.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/bigbluebutton_server.rb', line 87

def fetch_meetings
  response = self.api.get_meetings

  # updates the information in the rooms that are currently in BBB
  @meetings = []
  response[:meetings].each do |attr|
    room = BigbluebuttonRoom.find_by_server_id_and_meetingid(self.id, attr[:meetingID])
    # TODO: there might be more attributes returned by the API, review them all
    if room.nil?
      room = BigbluebuttonRoom.new(:server => self, :meetingid => attr[:meetingID],
                                   :name => attr[:meetingID], :attendee_api_password => attr[:attendeePW],
                                   :moderator_api_password => attr[:moderatorPW], :external => true, :private => true)
    else
      room.update_attributes(:attendee_api_password => attr[:attendeePW],
                             :moderator_api_password => attr[:moderatorPW])
    end
    room.running = attr[:running]
    room.update_current_meeting_record

    @meetings << room
  end
end

#fetch_recordings(filter = nil, full_sync = false) ⇒ Object

Sends a call to the BBB server to get the list of recordings and updates the database with these recordings.

filter

filters to be used, uses the same format accepted by BigBlueButtonApi::get_recordings. Can filter by meetingID and/or metadata values.

Triggers API call: getRecordings.



144
145
146
147
148
149
150
151
# File 'app/models/bigbluebutton_server.rb', line 144

def fetch_recordings(filter=nil, full_sync=false)
  filter ||= {}
  logger.info "Fetching recordings for the server #{self.inspect} with filter: #{filter.inspect}"
  recordings = self.api.get_recordings(filter)
  if recordings and recordings[:recordings]
    BigbluebuttonRecording.sync(self, recordings[:recordings], full_sync)
  end
end

#send_delete_recordings(ids) ⇒ Object

Sends a call to the BBB server to delete a recording or a set or recordings.

ids

IDs of the recordings that will be affected. Accepts the same format accepted by BigBlueButtonApi::delete_recordings

Triggers API call: deleteRecordings.



133
134
135
# File 'app/models/bigbluebutton_server.rb', line 133

def send_delete_recordings(ids)
  self.api.delete_recordings(ids)
end

#send_publish_recordings(ids, publish) ⇒ Object

Sends a call to the BBB server to publish or unpublish a recording or a set of recordings.

ids

IDs of the recordings that will be affected. Accepts the same format accepted by BigBlueButtonApi::publish_recordings

publish

Publish or unpublish the recordings?

Triggers API call: publishRecordings.



117
118
119
120
121
122
123
124
125
126
# File 'app/models/bigbluebutton_server.rb', line 117

def send_publish_recordings(ids, publish)
  self.api.publish_recordings(ids, publish)

  # Update #published in all recordings
  ids = ids.split(",") if ids.instance_of?(String) # "id1,id2" to ["id1", "id2"]
  ids.each do |id|
    recording = BigbluebuttonRecording.find_by_recordid(id.strip)
    recording.update_attributes(:published => publish) unless recording.nil?
  end
end

#set_api_version_from_serverObject



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/models/bigbluebutton_server.rb', line 157

def set_api_version_from_server
  begin
    # creating the object with version=nil makes the gem fetch the version from the server
    api = BigBlueButton::BigBlueButtonApi.new(self.url, self.secret, nil, false)
    self.version = api.version
  rescue BigBlueButton::BigBlueButtonException
    # we just ignore errors in case the server is not responding
    # in these cases, the version will be fetched later on
    Rails.logger.error "Could not fetch the API version from the server #{self.id}. The URL probably incorrect."
    self.version = nil
  end
  self.version
end

#to_paramObject



153
154
155
# File 'app/models/bigbluebutton_server.rb', line 153

def to_param
  self.param
end