forked from External/greenlight
GRN-59: Implemented pagination on the API call (#370)
* Added the env variable and functionality to paginate the call to the bbbapi * Update user.rb
This commit is contained in:
committed by
Jesus Federico
parent
ab6655554c
commit
3195bb4429
@ -17,6 +17,8 @@
|
||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class Room < ApplicationRecord
|
||||
include ::APIConcern
|
||||
|
||||
before_create :setup
|
||||
|
||||
before_destroy :delete_all_recordings
|
||||
@ -118,21 +120,8 @@ class Room < ApplicationRecord
|
||||
# Fetches all recordings for a room.
|
||||
def recordings
|
||||
res = bbb.get_recordings(meetingID: bbb_id)
|
||||
# Format playbacks in a more pleasant way.
|
||||
res[:recordings].each do |r|
|
||||
next if r.key?(:error)
|
||||
r[:playbacks] = if !r[:playback] || !r[:playback][:format]
|
||||
[]
|
||||
elsif r[:playback][:format].is_a?(Array)
|
||||
r[:playback][:format]
|
||||
else
|
||||
[r[:playback][:format]]
|
||||
end
|
||||
|
||||
r.delete(:playback)
|
||||
end
|
||||
|
||||
res[:recordings].sort_by { |rec| rec[:endTime] }.reverse
|
||||
format_recordings(res)
|
||||
end
|
||||
|
||||
# Fetches a rooms public recordings.
|
||||
@ -152,24 +141,6 @@ class Room < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def bbb_endpoint
|
||||
Rails.configuration.bigbluebutton_endpoint
|
||||
end
|
||||
|
||||
def bbb_secret
|
||||
Rails.configuration.bigbluebutton_secret
|
||||
end
|
||||
|
||||
# Sets a BigBlueButtonApi object for interacting with the API.
|
||||
def bbb
|
||||
@bbb ||= if Rails.configuration.loadbalanced_configuration
|
||||
lb_user = retrieve_loadbalanced_credentials(owner.provider)
|
||||
BigBlueButton::BigBlueButtonApi.new(remove_slash(lb_user["apiURL"]), lb_user["secret"], "0.8")
|
||||
else
|
||||
BigBlueButton::BigBlueButtonApi.new(remove_slash(bbb_endpoint), bbb_secret, "0.8")
|
||||
end
|
||||
end
|
||||
|
||||
# Generates a uid for the room and BigBlueButton.
|
||||
def setup
|
||||
self.uid = random_room_uid
|
||||
@ -193,51 +164,6 @@ class Room < ApplicationRecord
|
||||
[owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase
|
||||
end
|
||||
|
||||
# Rereives the loadbalanced BigBlueButton credentials for a user.
|
||||
def retrieve_loadbalanced_credentials(provider)
|
||||
# Include Omniauth accounts under the Greenlight provider.
|
||||
provider = "greenlight" if Rails.configuration.providers.include?(provider.to_sym)
|
||||
|
||||
# Build the URI.
|
||||
uri = encode_bbb_url(
|
||||
Rails.configuration.loadbalancer_endpoint + "getUser",
|
||||
Rails.configuration.loadbalancer_secret,
|
||||
name: provider
|
||||
)
|
||||
|
||||
# Make the request.
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.use_ssl = (uri.scheme == 'https')
|
||||
response = http.get(uri.request_uri)
|
||||
|
||||
unless response.is_a?(Net::HTTPSuccess)
|
||||
raise "Error retrieving provider credentials: #{response.code} #{response.message}"
|
||||
end
|
||||
|
||||
# Parse XML.
|
||||
doc = XmlSimple.xml_in(response.body, 'ForceArray' => false)
|
||||
|
||||
# Return the user credentials if the request succeeded on the loadbalancer.
|
||||
return doc['user'] if doc['returncode'] == RETURNCODE_SUCCESS
|
||||
|
||||
raise "User with provider #{provider} does not exist." if doc['messageKey'] == "noSuchUser"
|
||||
raise "API call #{url} failed with #{doc['messageKey']}."
|
||||
end
|
||||
|
||||
# Builds a request to retrieve credentials from the load balancer.
|
||||
def encode_bbb_url(base_url, secret, params)
|
||||
encoded_params = OAuth::Helper.normalize(params)
|
||||
string = "getUser" + encoded_params + secret
|
||||
checksum = OpenSSL::Digest.digest('sha1', string).unpack("H*").first
|
||||
|
||||
URI.parse("#{base_url}?#{encoded_params}&checksum=#{checksum}")
|
||||
end
|
||||
|
||||
# Removes trailing forward slash from a URL.
|
||||
def remove_slash(s)
|
||||
s.nil? ? nil : s.chomp("/")
|
||||
end
|
||||
|
||||
# Generates a random password for a meeting.
|
||||
def random_password(length)
|
||||
charset = ("a".."z").to_a + ("A".."Z").to_a
|
||||
|
Reference in New Issue
Block a user