forked from External/greenlight
GRN2-129: Added server recordings and refactored adminsitrator panel (#662)
* Added server recordings and refactored adminsitrator panel * Fixed some issues * Fixed issue with owner email search * Fixed issue with edit user
This commit is contained in:
committed by
Jesus Federico
parent
8c63f793a5
commit
a055b88eb7
136
app/controllers/concerns/recorder.rb
Normal file
136
app/controllers/concerns/recorder.rb
Normal file
@ -0,0 +1,136 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
|
||||
#
|
||||
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Lesser General Public License as published by the Free Software
|
||||
# Foundation; either version 3.0 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License along
|
||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module Recorder
|
||||
extend ActiveSupport::Concern
|
||||
include ::BbbApi
|
||||
|
||||
# Fetches all recordings for a room.
|
||||
def recordings(room_bbb_id, provider, search_params = {}, ret_search_params = false)
|
||||
res = bbb(provider).get_recordings(meetingID: room_bbb_id)
|
||||
|
||||
format_recordings(res, search_params, ret_search_params)
|
||||
end
|
||||
|
||||
# Fetches a rooms public recordings.
|
||||
def public_recordings(room_bbb_id, provider, search_params = {}, ret_search_params = false)
|
||||
search, order_col, order_dir, recs = recordings(room_bbb_id, provider, search_params, ret_search_params)
|
||||
[search, order_col, order_dir, recs.select { |r| r[:metadata][:"gl-listed"] == "true" }]
|
||||
end
|
||||
|
||||
# Makes paginated API calls to get recordings
|
||||
def all_recordings(room_bbb_ids, provider, search_params = {}, ret_search_params = false, search_name = false)
|
||||
pag_num = Rails.configuration.pagination_number
|
||||
|
||||
pag_loops = room_bbb_ids.length / pag_num - 1
|
||||
|
||||
res = { recordings: [] }
|
||||
|
||||
(0..pag_loops).each do |i|
|
||||
pag_rooms = room_bbb_ids[pag_num * i, pag_num]
|
||||
|
||||
# bbb.get_recordings returns an object
|
||||
# take only the array portion of the object that is returned
|
||||
full_res = bbb(provider).get_recordings(meetingID: pag_rooms)
|
||||
res[:recordings].push(*full_res[:recordings])
|
||||
end
|
||||
|
||||
last_pag_room = room_bbb_ids[pag_num * (pag_loops + 1), room_bbb_ids.length % pag_num]
|
||||
|
||||
full_res = bbb(provider).get_recordings(meetingID: last_pag_room)
|
||||
res[:recordings].push(*full_res[:recordings])
|
||||
|
||||
format_recordings(res, search_params, ret_search_params, search_name)
|
||||
end
|
||||
|
||||
# Format, filter, and sort recordings to match their current use in the app
|
||||
def format_recordings(api_res, search_params, ret_search_params, search_name = false)
|
||||
search = search_params[:search] || ""
|
||||
order_col = search_params[:column] && search_params[:direction] != "none" ? search_params[:column] : "end_time"
|
||||
order_dir = search_params[:column] && search_params[:direction] != "none" ? search_params[:direction] : "desc"
|
||||
|
||||
search = search.downcase
|
||||
|
||||
api_res[:recordings].each do |r|
|
||||
next if r.key?(:error)
|
||||
# Format playbacks in a more pleasant way.
|
||||
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
|
||||
|
||||
recs = filter_recordings(api_res, search, search_name)
|
||||
recs = sort_recordings(recs, order_col, order_dir)
|
||||
|
||||
if ret_search_params
|
||||
[search, order_col, order_dir, recs]
|
||||
else
|
||||
recs
|
||||
end
|
||||
end
|
||||
|
||||
def filter_recordings(api_res, search, search_name = false)
|
||||
api_res[:recordings].select do |r|
|
||||
(!r[:metadata].nil? && ((!r[:metadata][:name].nil? &&
|
||||
r[:metadata][:name].downcase.include?(search)) ||
|
||||
(r[:metadata][:"gl-listed"] == "true" && search == "public") ||
|
||||
(r[:metadata][:"gl-listed"] == "false" && search == "unlisted"))) ||
|
||||
((r[:metadata].nil? || r[:metadata][:name].nil?) &&
|
||||
r[:name].downcase.include?(search)) ||
|
||||
r[:participants].include?(search) ||
|
||||
!r[:playbacks].select { |p| p[:type].downcase.include?(search) }.empty? ||
|
||||
(search_name && Room.find_by(bbb_id: r[:meetingID]).owner.email.downcase.include?(search))
|
||||
end
|
||||
end
|
||||
|
||||
def sort_recordings(recs, order_col, order_dir)
|
||||
recs = case order_col
|
||||
when "end_time"
|
||||
recs.sort_by { |r| r[:endTime] }
|
||||
when "name"
|
||||
recs.sort_by do |r|
|
||||
if !r[:metadata].nil? && !r[:metadata][:name].nil?
|
||||
r[:metadata][:name].downcase
|
||||
else
|
||||
r[:name].downcase
|
||||
end
|
||||
end
|
||||
when "length"
|
||||
recs.sort_by { |r| r[:playbacks].reject { |p| p[:type] == "statistics" }.first[:length] }
|
||||
when "users"
|
||||
recs.sort_by { |r| r[:participants] }
|
||||
when "visibility"
|
||||
recs.sort_by { |r| r[:metadata][:"gl-listed"] }
|
||||
when "formats"
|
||||
recs.sort_by { |r| r[:playbacks].first[:type].downcase }
|
||||
else
|
||||
recs.sort_by { |r| r[:endTime] }
|
||||
end
|
||||
|
||||
if order_dir == 'asc'
|
||||
recs
|
||||
else
|
||||
recs.reverse
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user