|
1
|
|
|
// This file is part of Moodle - http://moodle.org/ |
|
2
|
|
|
// |
|
3
|
|
|
// Moodle is free software: you can redistribute it and/or modify |
|
4
|
|
|
// it under the terms of the GNU General Public License as published by |
|
5
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
|
6
|
|
|
// (at your option) any later version. |
|
7
|
|
|
// |
|
8
|
|
|
// Moodle is distributed in the hope that it will be useful, |
|
9
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11
|
|
|
// GNU General Public License for more details. |
|
12
|
|
|
// |
|
13
|
|
|
// You should have received a copy of the GNU General Public License |
|
14
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
15
|
|
|
|
|
16
|
|
|
/** global: M */ |
|
17
|
|
|
/** global: Y */ |
|
18
|
|
|
/** global: opener */ |
|
19
|
|
|
|
|
20
|
|
|
M.mod_bigbluebuttonbn = M.mod_bigbluebuttonbn || {}; |
|
21
|
|
|
|
|
22
|
|
|
M.mod_bigbluebuttonbn.rooms = { |
|
23
|
|
|
|
|
24
|
|
|
datasource: null, |
|
25
|
|
|
bigbluebuttonbn: {}, |
|
26
|
|
|
panel: null, |
|
27
|
|
|
pinginterval: null, |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initialise the broker code. |
|
31
|
|
|
* |
|
32
|
|
|
* @method init |
|
33
|
|
|
* @param {object} bigbluebuttonbn |
|
34
|
|
|
*/ |
|
35
|
|
|
init: function(bigbluebuttonbn) { |
|
36
|
|
|
this.datasource = new Y.DataSource.Get({ |
|
37
|
|
|
source: M.cfg.wwwroot + "/mod/bigbluebuttonbn/bbb_broker.php?" |
|
38
|
|
|
}); |
|
39
|
|
|
this.bigbluebuttonbn = bigbluebuttonbn; |
|
40
|
|
|
this.pinginterval = bigbluebuttonbn.ping_interval; |
|
41
|
|
|
if (this.pinginterval === 0) { |
|
42
|
|
|
this.pinginterval = 10000; |
|
43
|
|
|
} |
|
44
|
|
|
if (this.bigbluebuttonbn.profile_features.indexOf('all') != -1 || |
|
45
|
|
|
this.bigbluebuttonbn.profile_features.indexOf('showroom') != -1) { |
|
46
|
|
|
this.initRoom(); |
|
47
|
|
|
} |
|
48
|
|
|
}, |
|
49
|
|
|
|
|
50
|
|
|
initRoom: function() { |
|
51
|
|
|
if (this.bigbluebuttonbn.activity !== 'open') { |
|
52
|
|
|
var statusBar = [M.util.get_string('view_message_conference_has_ended', 'bigbluebuttonbn')]; |
|
53
|
|
|
if (this.bigbluebuttonbn.activity !== 'ended') { |
|
54
|
|
|
statusBar = [ |
|
55
|
|
|
M.util.get_string('view_message_conference_not_started', 'bigbluebuttonbn'), |
|
56
|
|
|
this.bigbluebuttonbn.opening, |
|
57
|
|
|
this.bigbluebuttonbn.closing |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
Y.DOM.addHTML(Y.one('#status_bar'), this.initStatusBar(statusBar)); |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
this.updateRoom(); |
|
64
|
|
|
}, |
|
65
|
|
|
|
|
66
|
|
|
updateRoom: function(f) { |
|
67
|
|
|
var updatecache = 'false'; |
|
68
|
|
|
if (typeof f !== 'undefined' && f) { |
|
69
|
|
|
updatecache = 'true'; |
|
70
|
|
|
} |
|
71
|
|
|
var id = this.bigbluebuttonbn.meetingid; |
|
72
|
|
|
var bnid = this.bigbluebuttonbn.bigbluebuttonbnid; |
|
73
|
|
|
this.datasource.sendRequest({ |
|
74
|
|
|
request: 'action=meeting_info&id=' + id + '&bigbluebuttonbn=' + bnid + '&updatecache=' + updatecache, |
|
75
|
|
|
callback: { |
|
76
|
|
|
success: function(e) { |
|
77
|
|
|
Y.DOM.addHTML(Y.one('#status_bar'), |
|
78
|
|
|
M.mod_bigbluebuttonbn.rooms.initStatusBar(e.data.status.message)); |
|
79
|
|
|
Y.DOM.addHTML(Y.one('#control_panel'), |
|
80
|
|
|
M.mod_bigbluebuttonbn.rooms.initControlPanel(e.data)); |
|
81
|
|
|
if (typeof e.data.status.can_join != 'undefined') { |
|
82
|
|
|
Y.DOM.addHTML(Y.one('#join_button'), |
|
83
|
|
|
M.mod_bigbluebuttonbn.rooms.initJoinButton(e.data.status)); |
|
84
|
|
|
} |
|
85
|
|
|
if (typeof e.data.status.can_end != 'undefined' && e.data.status.can_end) { |
|
86
|
|
|
Y.DOM.addHTML(Y.one('#end_button'), |
|
87
|
|
|
M.mod_bigbluebuttonbn.rooms.initEndButton(e.data.status)); |
|
88
|
|
|
} |
|
89
|
|
|
if (!e.data.status.can_join) { |
|
90
|
|
|
M.mod_bigbluebuttonbn.rooms.waitModerator({ |
|
91
|
|
|
id: id, |
|
92
|
|
|
bnid: bnid |
|
93
|
|
|
}); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
}); |
|
98
|
|
|
}, |
|
99
|
|
|
|
|
100
|
|
|
initStatusBar: function(statusMessage) { |
|
101
|
|
|
var statusBarSpan = Y.DOM.create('<span id="status_bar_span">'); |
|
102
|
|
|
if (statusMessage.constructor !== Array) { |
|
103
|
|
|
Y.DOM.setText(statusBarSpan, statusMessage); |
|
104
|
|
|
return statusBarSpan; |
|
105
|
|
|
} |
|
106
|
|
|
for (var message in statusMessage) { |
|
107
|
|
|
if (!statusMessage.hasOwnProperty(message)) { |
|
108
|
|
|
continue; // Skip keys from the prototype. |
|
109
|
|
|
} |
|
110
|
|
|
var statusBarSpanSpan = Y.DOM.create('<span id="status_bar_span_span">'); |
|
111
|
|
|
Y.DOM.setText(statusBarSpanSpan, statusMessage[message]); |
|
112
|
|
|
Y.DOM.addHTML(statusBarSpan, statusBarSpanSpan); |
|
113
|
|
|
Y.DOM.addHTML(statusBarSpan, Y.DOM.create('<br>')); |
|
114
|
|
|
} |
|
115
|
|
|
return statusBarSpan; |
|
116
|
|
|
}, |
|
117
|
|
|
|
|
118
|
|
|
initControlPanel: function(data) { |
|
119
|
|
|
var controlPanelDiv = Y.DOM.create('<div>'); |
|
120
|
|
|
Y.DOM.setAttribute(controlPanelDiv, 'id', 'control_panel_div'); |
|
121
|
|
|
var controlPanelDivHtml = ''; |
|
122
|
|
|
if (data.running) { |
|
123
|
|
|
controlPanelDivHtml += this.msgStartedAt(data.info.startTime) + ' '; |
|
124
|
|
|
controlPanelDivHtml += this.msgAttendeesIn(data.info.moderatorCount, data.info.participantCount); |
|
125
|
|
|
} |
|
126
|
|
|
Y.DOM.addHTML(controlPanelDiv, controlPanelDivHtml); |
|
127
|
|
|
return (controlPanelDiv); |
|
128
|
|
|
}, |
|
129
|
|
|
|
|
130
|
|
|
msgStartedAt: function(startTime) { |
|
131
|
|
|
var startTimestamp = (parseInt(startTime, 10) - parseInt(startTime, 10) % 1000); |
|
132
|
|
|
var date = new Date(startTimestamp); |
|
133
|
|
|
var hours = date.getHours(); |
|
134
|
|
|
var minutes = date.getMinutes(); |
|
135
|
|
|
var startedAt = M.util.get_string('view_message_session_started_at', 'bigbluebuttonbn'); |
|
136
|
|
|
return startedAt + ' <b>' + hours + ':' + (minutes < 10 ? '0' : '') + minutes + '</b>.'; |
|
137
|
|
|
}, |
|
138
|
|
|
|
|
139
|
|
|
msgModeratorsIn: function(moderators) { |
|
140
|
|
|
var msgModerators = M.util.get_string('view_message_moderators', 'bigbluebuttonbn'); |
|
141
|
|
|
if (moderators == 1) { |
|
142
|
|
|
msgModerators = M.util.get_string('view_message_moderator', 'bigbluebuttonbn'); |
|
143
|
|
|
} |
|
144
|
|
|
return msgModerators; |
|
145
|
|
|
}, |
|
146
|
|
|
|
|
147
|
|
|
msgViewersIn: function(viewers) { |
|
148
|
|
|
var msgViewers = M.util.get_string('view_message_viewers', 'bigbluebuttonbn'); |
|
149
|
|
|
if (viewers == 1) { |
|
150
|
|
|
msgViewers = M.util.get_string('view_message_viewer', 'bigbluebuttonbn'); |
|
151
|
|
|
} |
|
152
|
|
|
return msgViewers; |
|
153
|
|
|
}, |
|
154
|
|
|
|
|
155
|
|
|
msgAttendeesIn: function(moderators, participants) { |
|
156
|
|
|
var msgModerators, viewers, msgViewers, msg; |
|
157
|
|
|
if (!this.hasParticipants(participants)) { |
|
158
|
|
|
return M.util.get_string('view_message_session_no_users', 'bigbluebuttonbn') + '.'; |
|
159
|
|
|
} |
|
160
|
|
|
msgModerators = this.msgModeratorsIn(moderators); |
|
161
|
|
|
viewers = participants - moderators; |
|
162
|
|
|
msgViewers = this.msgViewersIn(viewers); |
|
163
|
|
|
msg = M.util.get_string('view_message_session_has_users', 'bigbluebuttonbn'); |
|
164
|
|
|
if (participants > 1) { |
|
165
|
|
|
return msg + ' <b>' + moderators + '</b> ' + msgModerators + ' and <b>' + viewers + '</b> ' + msgViewers + '.'; |
|
166
|
|
|
} |
|
167
|
|
|
msg = M.util.get_string('view_message_session_has_user', 'bigbluebuttonbn'); |
|
168
|
|
|
if (moderators > 0) { |
|
169
|
|
|
return msg + ' <b>1</b> ' + msgModerators + '.'; |
|
170
|
|
|
} |
|
171
|
|
|
return msg + ' <b>1</b> ' + msgViewers + '.'; |
|
172
|
|
|
}, |
|
173
|
|
|
|
|
174
|
|
|
hasParticipants: function(participants) { |
|
175
|
|
|
return (typeof participants != 'undefined' && participants > 0); |
|
176
|
|
|
}, |
|
177
|
|
|
|
|
178
|
|
|
initJoinButton: function(status) { |
|
179
|
|
|
var joinButtonInput = Y.DOM.create('<input>'); |
|
180
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'id', 'join_button_input'); |
|
181
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'type', 'button'); |
|
182
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'value', status.join_button_text); |
|
183
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'class', 'btn btn-primary'); |
|
184
|
|
|
var inputHtml = 'M.mod_bigbluebuttonbn.rooms.join(\'' + status.join_url + '\');'; |
|
185
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'onclick', inputHtml); |
|
186
|
|
|
if (!status.can_join) { |
|
187
|
|
|
// Disable join button. |
|
188
|
|
|
Y.DOM.setAttribute(joinButtonInput, 'disabled', true); |
|
189
|
|
|
var statusBarSpan = Y.one('#status_bar_span'); |
|
190
|
|
|
// Create a img element. |
|
191
|
|
|
var spinningWheel = Y.DOM.create('<img>'); |
|
192
|
|
|
Y.DOM.setAttribute(spinningWheel, 'id', 'spinning_wheel'); |
|
193
|
|
|
Y.DOM.setAttribute(spinningWheel, 'src', 'pix/i/processing16.gif'); |
|
194
|
|
|
// Add the spinning wheel. |
|
195
|
|
|
Y.DOM.addHTML(statusBarSpan, ' '); |
|
196
|
|
|
Y.DOM.addHTML(statusBarSpan, spinningWheel); |
|
197
|
|
|
} |
|
198
|
|
|
return joinButtonInput; |
|
199
|
|
|
}, |
|
200
|
|
|
|
|
201
|
|
|
initEndButton: function(status) { |
|
202
|
|
|
var endButtonInput = Y.DOM.create('<input>'); |
|
203
|
|
|
Y.DOM.setAttribute(endButtonInput, 'id', 'end_button_input'); |
|
204
|
|
|
Y.DOM.setAttribute(endButtonInput, 'type', 'button'); |
|
205
|
|
|
Y.DOM.setAttribute(endButtonInput, 'value', status.end_button_text); |
|
206
|
|
|
Y.DOM.setAttribute(endButtonInput, 'class', 'btn btn-secondary'); |
|
207
|
|
|
if (status.can_end) { |
|
208
|
|
|
Y.DOM.setAttribute(endButtonInput, 'onclick', 'M.mod_bigbluebuttonbn.broker.endMeeting();'); |
|
209
|
|
|
} |
|
210
|
|
|
return endButtonInput; |
|
211
|
|
|
}, |
|
212
|
|
|
|
|
213
|
|
|
endMeeting: function() { |
|
214
|
|
|
Y.one('#control_panel_div').remove(); |
|
215
|
|
|
Y.one('#join_button').hide(); |
|
216
|
|
|
Y.one('#end_button').hide(); |
|
217
|
|
|
}, |
|
218
|
|
|
|
|
219
|
|
|
remoteUpdate: function(delay) { |
|
220
|
|
|
setTimeout(function() { |
|
221
|
|
|
M.mod_bigbluebuttonbn.rooms.cleanRoom(); |
|
222
|
|
|
M.mod_bigbluebuttonbn.rooms.updateRoom(true); |
|
223
|
|
|
}, delay); |
|
224
|
|
|
}, |
|
225
|
|
|
|
|
226
|
|
|
cleanRoom: function() { |
|
227
|
|
|
Y.one('#status_bar_span').remove(); |
|
228
|
|
|
Y.one('#control_panel_div').remove(); |
|
229
|
|
|
Y.one('#join_button').setContent(''); |
|
230
|
|
|
Y.one('#end_button').setContent(''); |
|
231
|
|
|
}, |
|
232
|
|
|
|
|
233
|
|
|
windowClose: function() { |
|
234
|
|
|
window.onunload = function() { |
|
235
|
|
|
opener.M.mod_bigbluebuttonbn.rooms.remoteUpdate(5000); |
|
236
|
|
|
}; |
|
237
|
|
|
window.close(); |
|
238
|
|
|
}, |
|
239
|
|
|
|
|
240
|
|
|
waitModerator: function(payload) { |
|
241
|
|
|
var pooling = setInterval(function() { |
|
242
|
|
|
M.mod_bigbluebuttonbn.rooms.datasource.sendRequest({ |
|
243
|
|
|
request: "action=meeting_info&id=" + payload.id + "&bigbluebuttonbn=" + payload.bnid, |
|
244
|
|
|
callback: { |
|
245
|
|
|
success: function(e) { |
|
246
|
|
|
if (e.data.running) { |
|
247
|
|
|
M.mod_bigbluebuttonbn.rooms.cleanRoom(); |
|
248
|
|
|
M.mod_bigbluebuttonbn.rooms.updateRoom(); |
|
249
|
|
|
clearInterval(pooling); |
|
250
|
|
|
return; |
|
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
}, |
|
253
|
|
|
failure: function(e) { |
|
254
|
|
|
payload.message = e.error.message; |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
}); |
|
258
|
|
|
}, this.pinginterval); |
|
259
|
|
|
}, |
|
260
|
|
|
|
|
261
|
|
|
join: function(joinUrl) { |
|
262
|
|
|
M.mod_bigbluebuttonbn.broker.joinRedirect(joinUrl); |
|
263
|
|
|
// Update view. |
|
264
|
|
|
setTimeout(function() { |
|
265
|
|
|
M.mod_bigbluebuttonbn.rooms.cleanRoom(); |
|
266
|
|
|
M.mod_bigbluebuttonbn.rooms.updateRoom(true); |
|
267
|
|
|
}, 15000); |
|
268
|
|
|
} |
|
269
|
|
|
}; |
|
270
|
|
|
|