forked from blindsidenetworks-ps/moodle-mod_bigbluebuttonbn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbb_broker.php
822 lines (780 loc) · 30.5 KB
/
bbb_broker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Intermediator for managing actions executed by the BigBlueButton server.
*
* @package mod_bigbluebuttonbn
* @copyright 2010 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
use \Firebase\JWT\JWT;
global $PAGE, $USER, $CFG, $SESSION, $DB;
$params['action'] = optional_param('action', '', PARAM_TEXT);
$params['callback'] = optional_param('callback', '', PARAM_TEXT);
$params['id'] = optional_param('id', '', PARAM_TEXT);
$params['idx'] = optional_param('idx', '', PARAM_TEXT);
$params['bigbluebuttonbn'] = optional_param('bigbluebuttonbn', 0, PARAM_INT);
$params['signed_parameters'] = optional_param('signed_parameters', '', PARAM_TEXT);
$params['updatecache'] = optional_param('updatecache', 'false', PARAM_TEXT);
$params['meta'] = optional_param('meta', '', PARAM_TEXT);
require_login(0, false);
if (empty($params['action'])) {
header('HTTP/1.0 400 Bad Request. Parameter ['.$params['action'].'] was not included');
return;
}
$error = bigbluebuttonbn_broker_validate_parameters($params);
if (!empty($error)) {
header('HTTP/1.0 400 Bad Request. '.$error);
return;
}
if ($params['bigbluebuttonbn']) {
$bbbbrokerinstance = bigbluebuttonbn_view_instance_bigbluebuttonbn($params['bigbluebuttonbn']);
$cm = $bbbbrokerinstance['cm'];
$bigbluebuttonbn = $bbbbrokerinstance['bigbluebuttonbn'];
$context = context_module::instance($cm->id);
}
if ($params['action'] != 'recording_ready' && $params['action'] != 'live_session_events') {
if (!isset($SESSION->bigbluebuttonbn_bbbsession) || is_null($SESSION->bigbluebuttonbn_bbbsession)) {
header('HTTP/1.0 400 Bad Request. No session variable set');
return;
}
$bbbsession = $SESSION->bigbluebuttonbn_bbbsession;
}
$userid = $USER->id;
if (!isloggedin() && $PAGE->course->id == SITEID) {
$userid = guest_user()->id;
}
$hascourseaccess = ($PAGE->course->id == SITEID) || can_access_course($PAGE->course, $userid);
if (!$hascourseaccess) {
header('HTTP/1.0 401 Unauthorized');
return;
}
$type = null;
if (isset($bbbsession['bigbluebuttonbn']->type)) {
$type = $bbbsession['bigbluebuttonbn']->type;
}
$typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
$enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
try {
header('Content-Type: application/javascript; charset=utf-8');
$a = strtolower($params['action']);
if ($a == 'meeting_info') {
$meetinginfo = bigbluebuttonbn_broker_meeting_info($bbbsession, $params, ($params['updatecache'] == 'true'));
echo $meetinginfo;
return;
}
if ($a == 'meeting_end') {
$meetingend = bigbluebuttonbn_broker_meeting_end($bbbsession, $params);
echo $meetingend;
return;
}
if ($a == 'recording_play') {
$recordingplay = bigbluebuttonbn_broker_recording_play($params);
echo $recordingplay;
return;
}
if ($a == 'recording_links') {
$recordinglinks = bigbluebuttonbn_broker_recording_links($bbbsession, $params);
echo $recordinglinks;
return;
}
if ($a == 'recording_info') {
$recordinginfo = bigbluebuttonbn_broker_recording_info($bbbsession, $params, $enabledfeatures['showroom']);
echo $recordinginfo;
return;
}
if ($a == 'recording_publish' || $a == 'recording_unpublish' ||
$a == 'recording_delete' || $a == 'recording_edit' ||
$a == 'recording_protect' || $a == 'recording_unprotect') {
$recordingaction = bigbluebuttonbn_broker_recording_action($bbbsession, $params, $enabledfeatures['showroom']);
echo $recordingaction;
return;
}
if ($a == 'recording_import') {
echo bigbluebuttonbn_broker_recording_import($bbbsession, $params);
return;
}
if ($a == 'recording_ready') {
bigbluebuttonbn_broker_recording_ready($params, $bigbluebuttonbn);
return;
}
if ($a == 'live_session_events') {
bigbluebuttonbn_broker_live_session_events($params, $bigbluebuttonbn, $cm);
return;
}
header('HTTP/1.0 400 Bad request. The action '. $a . ' doesn\'t exist');
return;
} catch (Exception $e) {
header('HTTP/1.0 500 Internal Server Error. '.$e->getMessage());
return;
}
/**
* Callback for meeting info.
*
* @param array $bbbsession
* @param array $params
* @param boolean $updatecache
*
* @return string
*/
function bigbluebuttonbn_broker_meeting_info($bbbsession, $params, $updatecache) {
$callbackresponse = array();
$info = bigbluebuttonbn_get_meeting_info($params['id'], $updatecache);
$callbackresponse['info'] = $info;
$running = false;
if ($info['returncode'] == 'SUCCESS') {
$running = ($info['running'] === 'true');
}
$callbackresponse['running'] = $running;
$status = array();
$status["join_url"] = $bbbsession['joinURL'];
$status["join_button_text"] = get_string('view_conference_action_join', 'bigbluebuttonbn');
$status["end_button_text"] = get_string('view_conference_action_end', 'bigbluebuttonbn');
$participantcount = 0;
if (isset($info['participantCount'])) {
$participantcount = $info['participantCount'];
}
$canjoin = bigbluebuttonbn_broker_meeting_info_can_join($bbbsession, $running, $participantcount);
$status["can_join"] = $canjoin["can_join"];
$status["message"] = $canjoin["message"];
$canend = bigbluebuttonbn_broker_meeting_info_can_end($bbbsession, $running);
$status["can_end"] = $canend["can_end"];
$callbackresponse['status'] = $status;
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Helper for evaluating if meeting can be joined, it is used by meeting info callback.
*
* @param array $bbbsession
* @param boolean $running
* @param boolean $participantcount
*
* @return array
*/
function bigbluebuttonbn_broker_meeting_info_can_join($bbbsession, $running, $participantcount) {
$status = array("can_join" => false);
if ($running) {
$status["message"] = get_string('view_error_userlimit_reached', 'bigbluebuttonbn');
if ($bbbsession['userlimit'] == 0 || $participantcount < $bbbsession['userlimit']) {
$status["message"] = get_string('view_message_conference_in_progress', 'bigbluebuttonbn');
$status["can_join"] = true;
}
return $status;
}
// If user is administrator, moderator or if is viewer and no waiting is required.
$status["message"] = get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn');
if ($bbbsession['administrator'] || $bbbsession['moderator'] || !$bbbsession['wait']) {
$status["message"] = get_string('view_message_conference_room_ready', 'bigbluebuttonbn');
$status["can_join"] = true;
}
return $status;
}
/**
* Helper for evaluating if meeting can be ended, it is used by meeting info callback.
*
* @param array $bbbsession
* @param boolean $running
*
* @return boolean
*/
function bigbluebuttonbn_broker_meeting_info_can_end($bbbsession, $running) {
if ($running && ($bbbsession['administrator'] || $bbbsession['moderator'])) {
return array("can_end" => true);
}
return array("can_end" => false);
}
/**
* Callback for meeting end.
*
* @param array $bbbsession
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_meeting_end($bbbsession, $params) {
if (!$bbbsession['administrator'] && !$bbbsession['moderator']) {
header('HTTP/1.0 401 Unauthorized. User not authorized to execute end command');
return;
}
// Execute the end command.
bigbluebuttonbn_end_meeting($params['id'], $bbbsession['modPW']);
// Moodle event logger: Create an event for meeting ended.
if (isset($bbbsession['bigbluebuttonbn'])) {
bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['meeting_end'], $bbbsession['bigbluebuttonbn']);
}
// Update the cache.
bigbluebuttonbn_get_meeting_info($params['id'], BIGBLUEBUTTONBN_UPDATE_CACHE);
$callbackresponse = array('status' => true);
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Callback for recording links.
*
* @param array $bbbsession
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_recording_links($bbbsession, $params) {
if (!$bbbsession['managerecordings']) {
header('HTTP/1.0 401 Unauthorized. User not authorized to execute update command');
return;
}
$callbackresponse = array('status' => false);
if (isset($params['id']) && $params['id'] != '') {
$importedall = bigbluebuttonbn_get_recording_imported_instances($params['id']);
$callbackresponse['status'] = true;
$callbackresponse['links'] = count($importedall);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Callback for recording info.
*
* @param array $bbbsession
* @param array $params
* @param boolean $showroom
*
* @return string
*/
function bigbluebuttonbn_broker_recording_info($bbbsession, $params, $showroom) {
if (!$bbbsession['managerecordings']) {
header('HTTP/1.0 401 Unauthorized. User not authorized to execute command');
return;
}
$callbackresponse = array('status' => true, 'found' => false);
$courseid = $bbbsession['course']->id;
$bigbluebuttonbnid = null;
if ($showroom) {
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id;
}
$includedeleted = $bbbsession['bigbluebuttonbn']->recordings_deleted;
// Retrieve the array of imported recordings.
$recordings = bigbluebuttonbn_get_allrecordings($courseid, $bigbluebuttonbnid, $showroom, $includedeleted);
if (array_key_exists($params['id'], $recordings)) {
// Look up for an update on the imported recording.
if (!array_key_exists('messageKey', $recordings[$params['id']])) {
// The recording was found.
$callbackresponse = bigbluebuttonbn_broker_recording_info_current($recordings[$params['id']], $params);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
// As the recordingid was not identified as imported recording link, look up for a real recording.
$recordings = bigbluebuttonbn_get_recordings_array($params['idx'], $params['id']);
if (array_key_exists($params['id'], $recordings)) {
// The recording was found.
$callbackresponse = bigbluebuttonbn_broker_recording_info_current($recordings[$params['id']], $params);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Data used as for the callback for recording info.
*
* @param array $recording
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_recording_info_current($recording, $params) {
$callbackresponse['status'] = true;
$callbackresponse['found'] = true;
$callbackresponse['published'] = (string) $recording['published'];
if (!isset($params['meta']) || empty($params['meta'])) {
return $callbackresponse;
}
$meta = json_decode($params['meta'], true);
foreach (array_keys($meta) as $key) {
$callbackresponse[$key] = '';
if (isset($recording[$key])) {
$callbackresponse[$key] = trim($recording[$key]);
}
}
return $callbackresponse;
}
/**
* Callback for recording play.
*
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_recording_play($params) {
$callbackresponse = array('status' => true, 'found' => false);
$recordings = bigbluebuttonbn_get_recordings_array($params['idx'], $params['id']);
if (array_key_exists($params['id'], $recordings)) {
// The recording was found.
$callbackresponse = bigbluebuttonbn_broker_recording_info_current($recordings[$params['id']], $params);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Callback for recording action.
* (publush/unpublish/protect/unprotect/edit/delete)
*
* @param array $bbbsession
* @param array $params
* @param boolean $showroom
*
* @return string
*/
function bigbluebuttonbn_broker_recording_action($bbbsession, $params, $showroom) {
if (!$bbbsession['managerecordings']) {
header('HTTP/1.0 401 Unauthorized. User not authorized to execute end command');
return;
}
// Retrieve array of recordings that includes real and imported.
$bigbluebuttonbnid = null;
if ($showroom) {
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id;
}
$recordings = bigbluebuttonbn_get_allrecordings($bbbsession['course']->id, $bigbluebuttonbnid, $showroom,
$bbbsession['bigbluebuttonbn']->recordings_deleted);
$action = strtolower($params['action']);
// Excecute action.
$callbackresponse = bigbluebuttonbn_broker_recording_action_perform($action, $params, $recordings);
if ($callbackresponse['status']) {
// Moodle event logger: Create an event for action performed on recording.
bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events[$action], $bbbsession['bigbluebuttonbn'],
['other' => $params['id']]);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Helper for performing actions on recordings.
* (publush/unpublish/protect/unprotect/edit/delete)
*
* @param string $action
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_perform($action, $params, $recordings) {
if ($action == 'recording_publish') {
return bigbluebuttonbn_broker_recording_action_publish($params, $recordings);
}
if ($action == 'recording_unpublish') {
return bigbluebuttonbn_broker_recording_action_unpublish($params, $recordings);
}
if ($action == 'recording_edit') {
return bigbluebuttonbn_broker_recording_action_edit($params, $recordings);
}
if ($action == 'recording_delete') {
return bigbluebuttonbn_broker_recording_action_delete($params, $recordings);
}
if ($action == 'recording_protect') {
return bigbluebuttonbn_broker_recording_action_protect($params, $recordings);
}
if ($action == 'recording_unprotect') {
return bigbluebuttonbn_broker_recording_action_unprotect($params, $recordings);
}
}
/**
* Helper for performing publish on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_publish($params, $recordings) {
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute publish on imported recording link, if the real recording is published.
$realrecordings = bigbluebuttonbn_get_recordings_array(
$recordings[$params['id']]['meetingID'], $recordings[$params['id']]['recordID']);
// Only if the physical recording exist and it is published, execute publish on imported recording link.
if (!isset($realrecordings[$params['id']])) {
return array(
'status' => false,
'message' => get_string('view_recording_publish_link_deleted', 'bigbluebuttonbn')
);
}
if ($realrecordings[$params['id']]['published'] !== 'true') {
return array(
'status' => false,
'message' => get_string('view_recording_publish_link_not_published', 'bigbluebuttonbn')
);
}
return array(
'status' => bigbluebuttonbn_publish_recording_imported(
$recordings[$params['id']]['imported'], true
)
);
}
// As the recordingid was not identified as imported recording link, execute actual publish.
return array(
'status' => bigbluebuttonbn_publish_recordings(
$params['id'], 'true'
)
);
}
/**
* Helper for performing unprotect on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_unprotect($params, $recordings) {
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute unprotect on imported recording link, if the real recording is unprotected.
$realrecordings = bigbluebuttonbn_get_recordings_array(
$recordings[$params['id']]['meetingID'], $recordings[$params['id']]['recordID']);
// Only if the physical recording exist and it is published, execute unprotect on imported recording link.
if (!isset($realrecordings[$params['id']])) {
return array(
'status' => false,
'message' => get_string('view_recording_unprotect_link_deleted', 'bigbluebuttonbn')
);
}
if ($realrecordings[$params['id']]['protected'] === 'true') {
return array(
'status' => false,
'message' => get_string('view_recording_unprotect_link_not_unprotected', 'bigbluebuttonbn')
);
}
return array(
'status' => bigbluebuttonbn_protect_recording_imported(
$recordings[$params['id']]['imported'], false
)
);
}
// As the recordingid was not identified as imported recording link, execute actual uprotect.
return array(
'status' => bigbluebuttonbn_update_recordings(
$params['id'], array('protect' => 'false')
)
);
}
/**
* Helper for performing unpublish on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_unpublish($params, $recordings) {
global $DB;
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute unpublish or protect on imported recording link.
return array(
'status' => bigbluebuttonbn_publish_recording_imported(
$recordings[$params['id']]['imported'], false
)
);
}
// As the recordingid was not identified as imported recording link, execute unpublish on a real recording.
// First: Unpublish imported links associated to the recording.
$importedall = bigbluebuttonbn_get_recording_imported_instances($params['id']);
foreach ($importedall as $key => $record) {
$meta = json_decode($record->meta, true);
// Prepare data for the update.
$meta['recording']['published'] = 'false';
$importedall[$key]->meta = json_encode($meta);
// Proceed with the update.
$DB->update_record('bigbluebuttonbn_logs', $importedall[$key]);
}
// Second: Execute the actual unpublish.
return array(
'status' => bigbluebuttonbn_publish_recordings(
$params['id'], 'false'
)
);
}
/**
* Helper for performing protect on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_protect($params, $recordings) {
global $DB;
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute unpublish or protect on imported recording link.
return array(
'status' => bigbluebuttonbn_protect_recording_imported(
$recordings[$params['id']]['imported'], true
)
);
}
// As the recordingid was not identified as imported recording link, execute protect on a real recording.
// First: Protect imported links associated to the recording.
$importedall = bigbluebuttonbn_get_recording_imported_instances($params['id']);
foreach ($importedall as $key => $record) {
$meta = json_decode($record->meta, true);
// Prepare data for the update.
$meta['recording']['protected'] = 'true';
$importedall[$key]->meta = json_encode($meta);
// Proceed with the update.
$DB->update_record('bigbluebuttonbn_logs', $importedall[$key]);
}
// Second: Execute the actual protect.
return array(
'status' => bigbluebuttonbn_update_recordings(
$params['id'], array('protect' => 'true')
)
);
}
/**
* Helper for performing delete on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_delete($params, $recordings) {
global $DB;
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute delete on imported recording link.
return array(
'status' => bigbluebuttonbn_delete_recording_imported(
$recordings[$params['id']]['imported']
)
);
}
// As the recordingid was not identified as imported recording link, execute delete on a real recording.
// First: Delete imported links associated to the recording.
$importedall = bigbluebuttonbn_get_recording_imported_instances($params['id']);
if ($importedall > 0) {
foreach (array_keys($importedall) as $key) {
// Execute delete on imported links.
$DB->delete_records('bigbluebuttonbn_logs', array('id' => $key));
}
}
// Second: Execute the actual delete.
return array(
'status' => bigbluebuttonbn_delete_recordings($params['id'])
);
}
/**
* Helper for performing edit on recordings.
*
* @param array $params
* @param array $recordings
*
* @return array
*/
function bigbluebuttonbn_broker_recording_action_edit($params, $recordings) {
if (bigbluebuttonbn_broker_recording_is_imported($recordings, $params['id'])) {
// Execute update on imported recording link.
return array(
'status' => bigbluebuttonbn_update_recording_imported(
$recordings[$params['id']]['imported'], json_decode($params['meta'], true)
)
);
}
// As the recordingid was not identified as imported recording link, execute update on a real recording.
// (No need to update imported links as the update only affects the actual recording).
// Execute update on actual recording.
return array(
'status' => bigbluebuttonbn_update_recordings(
$params['id'], json_decode($params['meta'])
)
);
}
/**
* Helper for responding when recording ready is performed.
*
* @param array $params
* @param object $bigbluebuttonbn
*
* @return void
*/
function bigbluebuttonbn_broker_recording_ready($params, $bigbluebuttonbn) {
// Decodes the received JWT string.
try {
$decodedparameters = JWT::decode($params['signed_parameters'],
\mod_bigbluebuttonbn\locallib\config::get('shared_secret'), array('HS256'));
} catch (Exception $e) {
$error = 'Caught exception: '.$e->getMessage();
header('HTTP/1.0 400 Bad Request. '.$error);
return;
}
// Validate that the bigbluebuttonbn activity corresponds to the meeting_id received.
$meetingidelements = explode('[', $decodedparameters->meeting_id);
$meetingidelements = explode('-', $meetingidelements[0]);
if (!isset($bigbluebuttonbn) || $bigbluebuttonbn->meetingid != $meetingidelements[0]) {
header('HTTP/1.0 410 Gone. The activity may have been deleted');
return;
}
// Sends the messages.
try {
bigbluebuttonbn_send_notification_recording_ready($bigbluebuttonbn);
header('HTTP/1.0 202 Accepted');
} catch (Exception $e) {
$error = 'Caught exception: '.$e->getMessage();
header('HTTP/1.0 503 Service Unavailable. '.$error);
}
}
/**
* Helper for performing import on recordings.
*
* @param array $bbbsession
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_recording_import($bbbsession, $params) {
global $SESSION;
if (!$bbbsession['managerecordings']) {
header('HTTP/1.0 401 Unauthorized. User not authorized to execute end command');
return;
}
$importrecordings = $SESSION->bigbluebuttonbn_importrecordings;
if (!isset($importrecordings[$params['id']])) {
$error = "Recording {$params['id']} could not be found. It can not be imported";
header('HTTP/1.0 404 Not found. '.$error);
return;
}
$callbackresponse = array('status' => true);
$importrecordings[$params['id']]['imported'] = true;
$overrides = array('meetingid' => $importrecordings[$params['id']]['meetingID']);
$meta = '{"recording":'.json_encode($importrecordings[$params['id']]).'}';
bigbluebuttonbn_log($bbbsession['bigbluebuttonbn'], BIGBLUEBUTTONBN_LOG_EVENT_IMPORT, $overrides, $meta);
// Moodle event logger: Create an event for recording imported.
if (isset($bbbsession['bigbluebutton']) && isset($bbbsession['cm'])) {
bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['recording_import'], $bbbsession['bigbluebuttonbn'],
['other' => $params['id']]);
}
$callbackresponsedata = json_encode($callbackresponse);
return "{$params['callback']}({$callbackresponsedata});";
}
/**
* Helper for responding when storing live session events is requested.
*
* @param array $params
* @param object $bigbluebuttonbn
* @param object $cm
*
* @return void
*/
function bigbluebuttonbn_broker_live_session_events($params, $bigbluebuttonbn, $cm) {
// Decodes the received JWT string.
try {
$decodedparameters = JWT::decode($params['signed_parameters'],
\mod_bigbluebuttonbn\locallib\config::get('shared_secret'), array('HS256'));
} catch (Exception $e) {
$error = 'Caught exception: '.$e->getMessage();
header('HTTP/1.0 400 Bad Request. '.$error);
return;
}
// Validate that the bigbluebuttonbn activity corresponds to the meeting_id received.
$meetingidelements = explode('[', $decodedparameters->meeting_id);
$meetingidelements = explode('-', $meetingidelements[0]);
if (!isset($bigbluebuttonbn) || $bigbluebuttonbn->meetingid != $meetingidelements[0]) {
header('HTTP/1.0 410 Gone. The activity may have been deleted');
return;
}
// Store the events.
try {
foreach ($decodedparameters->events as $event) {
bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['live_session'], $bigbluebuttonbn,
['timecreated' => $event->timestamp, 'userid' => $event->user, 'other' => $event->event]);
}
header('HTTP/1.0 202 Accepted');
} catch (Exception $e) {
$error = "Caught exception: {$e->getMessage()}";
header("HTTP/1.0 503 Service Unavailable. {$error}");
}
}
/**
* Helper for validating the parameters received.
*
* @param array $params
*
* @return string
*/
function bigbluebuttonbn_broker_validate_parameters($params) {
$requiredparams = bigbluebuttonbn_broker_required_parameters();
if (!isset($params['callback'])) {
return 'This call must include a javascript callback.';
}
if (!isset($params['action'])) {
return 'Action parameter must be included.';
}
$action = strtolower($params['action']);
if (!array_key_exists($action, $requiredparams)) {
return 'Action '.$params['action'].' can not be performed.';
}
return bigbluebuttonbn_broker_validate_parameters_message($params, $requiredparams[$action]);
}
/**
* Helper for responding after the parameters received are validated.
*
* @param array $params
* @param array $requiredparams
*
* @return string
*/
function bigbluebuttonbn_broker_validate_parameters_message($params, $requiredparams) {
foreach ($requiredparams as $param => $message) {
if (!array_key_exists($param, $params) || $params[$param] == '') {
return $message;
}
}
}
/**
* Helper for definig rules for validating required parameters.
*/
function bigbluebuttonbn_broker_required_parameters() {
$params['server_ping'] = ['id' => 'The meetingID must be specified.'];
$params['meeting_info'] = ['id' => 'The meetingID must be specified.'];
$params['meeting_end'] = ['id' => 'The meetingID must be specified.'];
$params['recording_play'] = ['id' => 'The recordingID must be specified.'];
$params['recording_info'] = ['id' => 'The recordingID must be specified.'];
$params['recording_links'] = ['id' => 'The recordingID must be specified.'];
$params['recording_publish'] = ['id' => 'The recordingID must be specified.'];
$params['recording_unpublish'] = ['id' => 'The recordingID must be specified.'];
$params['recording_delete'] = ['id' => 'The recordingID must be specified.'];
$params['recording_protect'] = ['id' => 'The recordingID must be specified.'];
$params['recording_unprotect'] = ['id' => 'The recordingID must be specified.'];
$params['recording_edit'] = ['id' => 'The recordingID must be specified.',
'meta' => 'A meta parameter should be included'];
$params['recording_import'] = ['id' => 'The recordingID must be specified.'];
$params['recording_ready'] = [
'signed_parameters' => 'A JWT encoded string must be included as [signed_parameters].'
];
$params['live_session_events'] = [
'signed_parameters' => 'A JWT encoded string must be included as [signed_parameters].'
];
return $params;
}
/**
* Helper for validating if a recording is an imported link or a real one.
*
* @param array $recordings
* @param string $recordingid
*
* @return boolean
*/
function bigbluebuttonbn_broker_recording_is_imported($recordings, $recordingid) {
return (isset($recordings[$recordingid]) && isset($recordings[$recordingid]['imported']));
}