|
1
|
|
|
# frozen_string_literal: true |
|
2
|
|
|
|
|
3
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
|
4
|
|
|
# |
|
5
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). |
|
6
|
|
|
# |
|
7
|
|
|
# This program is free software; you can redistribute it and/or modify it under the |
|
8
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software |
|
9
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later |
|
10
|
|
|
# version. |
|
11
|
|
|
# |
|
12
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
|
13
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
14
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU Lesser General Public License along |
|
17
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
module Recorder |
|
20
|
|
|
extend ActiveSupport::Concern |
|
21
|
|
|
include ::BbbApi |
|
22
|
|
|
|
|
23
|
|
|
# Fetches all recordings for a room. |
|
24
|
|
|
def recordings(room_bbb_id, provider, search_params = {}, ret_search_params = false) |
|
25
|
|
|
res = bbb(provider).get_recordings(meetingID: room_bbb_id) |
|
26
|
|
|
|
|
27
|
|
|
format_recordings(res, search_params, ret_search_params) |
|
28
|
|
|
end |
|
29
|
|
|
|
|
30
|
|
|
# Fetches a rooms public recordings. |
|
31
|
|
|
def public_recordings(room_bbb_id, provider, search_params = {}, ret_search_params = false) |
|
32
|
|
|
search, order_col, order_dir, recs = recordings(room_bbb_id, provider, search_params, ret_search_params) |
|
33
|
|
|
[search, order_col, order_dir, recs.select { |r| r[:metadata][:"gl-listed"] == "true" }] |
|
34
|
|
|
end |
|
35
|
|
|
|
|
36
|
|
|
# Makes paginated API calls to get recordings |
|
37
|
|
|
def all_recordings(room_bbb_ids, provider, search_params = {}, ret_search_params = false, search_name = false) |
|
38
|
|
|
pag_num = Rails.configuration.pagination_number |
|
39
|
|
|
|
|
40
|
|
|
pag_loops = room_bbb_ids.length / pag_num - 1 |
|
41
|
|
|
|
|
42
|
|
|
res = { recordings: [] } |
|
43
|
|
|
|
|
44
|
|
|
(0..pag_loops).each do |i| |
|
45
|
|
|
pag_rooms = room_bbb_ids[pag_num * i, pag_num] |
|
46
|
|
|
|
|
47
|
|
|
# bbb.get_recordings returns an object |
|
48
|
|
|
# take only the array portion of the object that is returned |
|
49
|
|
|
full_res = bbb(provider).get_recordings(meetingID: pag_rooms) |
|
50
|
|
|
res[:recordings].push(*full_res[:recordings]) |
|
51
|
|
|
end |
|
52
|
|
|
|
|
53
|
|
|
last_pag_room = room_bbb_ids[pag_num * (pag_loops + 1), room_bbb_ids.length % pag_num] |
|
54
|
|
|
|
|
55
|
|
|
full_res = bbb(provider).get_recordings(meetingID: last_pag_room) |
|
56
|
|
|
res[:recordings].push(*full_res[:recordings]) |
|
57
|
|
|
|
|
58
|
|
|
format_recordings(res, search_params, ret_search_params, search_name) |
|
59
|
|
|
end |
|
60
|
|
|
|
|
61
|
|
|
# Format, filter, and sort recordings to match their current use in the app |
|
62
|
|
|
def format_recordings(api_res, search_params, ret_search_params, search_name = false) |
|
63
|
|
|
search = search_params[:search] || "" |
|
64
|
|
|
order_col = search_params[:column] && search_params[:direction] != "none" ? search_params[:column] : "end_time" |
|
65
|
|
|
order_dir = search_params[:column] && search_params[:direction] != "none" ? search_params[:direction] : "desc" |
|
66
|
|
|
|
|
67
|
|
|
search = search.downcase |
|
68
|
|
|
|
|
69
|
|
|
api_res[:recordings].each do |r| |
|
70
|
|
|
next if r.key?(:error) |
|
71
|
|
|
# Format playbacks in a more pleasant way. |
|
72
|
|
|
r[:playbacks] = if !r[:playback] || !r[:playback][:format] |
|
73
|
|
|
[] |
|
74
|
|
|
elsif r[:playback][:format].is_a?(Array) |
|
75
|
|
|
r[:playback][:format] |
|
76
|
|
|
else |
|
77
|
|
|
[r[:playback][:format]] |
|
78
|
|
|
end |
|
79
|
|
|
r.delete(:playback) |
|
80
|
|
|
end |
|
81
|
|
|
|
|
82
|
|
|
recs = filter_recordings(api_res, search, search_name) |
|
83
|
|
|
recs = sort_recordings(recs, order_col, order_dir) |
|
84
|
|
|
|
|
85
|
|
|
if ret_search_params |
|
86
|
|
|
[search, order_col, order_dir, recs] |
|
87
|
|
|
else |
|
88
|
|
|
recs |
|
89
|
|
|
end |
|
90
|
|
|
end |
|
91
|
|
|
|
|
92
|
|
|
def filter_recordings(api_res, search, search_name = false) |
|
93
|
|
|
api_res[:recordings].select do |r| |
|
94
|
|
|
(!r[:metadata].nil? && ((!r[:metadata][:name].nil? && |
|
95
|
|
|
r[:metadata][:name].downcase.include?(search)) || |
|
96
|
|
|
(r[:metadata][:"gl-listed"] == "true" && search == "public") || |
|
97
|
|
|
(r[:metadata][:"gl-listed"] == "false" && search == "unlisted"))) || |
|
98
|
|
|
((r[:metadata].nil? || r[:metadata][:name].nil?) && |
|
99
|
|
|
r[:name].downcase.include?(search)) || |
|
100
|
|
|
r[:participants].include?(search) || |
|
101
|
|
|
!r[:playbacks].select { |p| p[:type].downcase.include?(search) }.empty? || |
|
102
|
|
|
(search_name && Room.find_by(bbb_id: r[:meetingID]).owner.email.downcase.include?(search)) |
|
103
|
|
|
end |
|
104
|
|
|
end |
|
105
|
|
|
|
|
106
|
|
|
def sort_recordings(recs, order_col, order_dir) |
|
107
|
|
|
recs = case order_col |
|
108
|
|
|
when "end_time" |
|
109
|
|
|
recs.sort_by { |r| r[:endTime] } |
|
110
|
|
|
when "name" |
|
111
|
|
|
recs.sort_by do |r| |
|
112
|
|
|
if !r[:metadata].nil? && !r[:metadata][:name].nil? |
|
113
|
|
|
r[:metadata][:name].downcase |
|
114
|
|
|
else |
|
115
|
|
|
r[:name].downcase |
|
116
|
|
|
end |
|
117
|
|
|
end |
|
118
|
|
|
when "length" |
|
119
|
|
|
recs.sort_by { |r| r[:playbacks].reject { |p| p[:type] == "statistics" }.first[:length] } |
|
120
|
|
|
when "users" |
|
121
|
|
|
recs.sort_by { |r| r[:participants] } |
|
122
|
|
|
when "visibility" |
|
123
|
|
|
recs.sort_by { |r| r[:metadata][:"gl-listed"] } |
|
124
|
|
|
when "formats" |
|
125
|
|
|
recs.sort_by { |r| r[:playbacks].first[:type].downcase } |
|
126
|
|
|
else |
|
127
|
|
|
recs.sort_by { |r| r[:endTime] } |
|
128
|
|
|
end |
|
129
|
|
|
|
|
130
|
|
|
if order_dir == 'asc' |
|
131
|
|
|
recs |
|
132
|
|
|
else |
|
133
|
|
|
recs.reverse |
|
134
|
|
|
end |
|
135
|
|
|
end |
|
136
|
|
|
end |
|
137
|
|
|
|