-
Notifications
You must be signed in to change notification settings - Fork 1
/
bigbluebuttonbn.php
324 lines (287 loc) · 16.1 KB
/
bigbluebuttonbn.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
<?php
/**
* @package tinymce_bigbluebuttonbn
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
* @copyright 2016 Blindside Networks Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
$contextid = required_param('contextid', PARAM_INT);
$content = optional_param('content', '', PARAM_RAW);
$action = optional_param('action', '', PARAM_TEXT);
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
require_sesskey();
$PAGE->set_context($context);
$PAGE->set_url(MOODLE_TINYMCE_BIGBLUEBUTTONBN_URL);
$PAGE->set_cacheable(false);
$title = isset($cm->name)? $cm->name: '';
$PAGE->set_title($title);
$PAGE->set_heading($title);
// Reset page layout for inside editor.
$PAGE->set_pagelayout('popup');
if ( $action != '' && isset($SESSION->bigbluebuttonbn_bbbsession) && !is_null($SESSION->bigbluebuttonbn_bbbsession) ) {
$bbbsession = $SESSION->bigbluebuttonbn_bbbsession;
} else {
////////////////////////////////////////////////
///// BigBlueButton Session Setup Starts /////
////////////////////////////////////////////////
// User data
$bbbsession['username'] = get_string('fullnamedisplay', 'moodle', $USER);
$bbbsession['userID'] = $USER->id;
$bbbsession['moderator'] = true;
$bbbsession['managerecordings'] = true;
// BigBlueButton server data
$bbbsession['endpoint'] = bigbluebuttonbn_get_cfg_server_url();
$bbbsession['shared_secret'] = bigbluebuttonbn_get_cfg_shared_secret();
// Server data
$bbbsession['modPW'] = bigbluebuttonbn_random_password(12);
$bbbsession['viewerPW'] = bigbluebuttonbn_random_password(12);
// Database info related to the activity
$bbbsession['meetingid'] = sha1($CFG->wwwroot.$cm->id.$USER->id.$bbbsession['shared_secret']);
if ( isset($cm->modname) ) {
$cm_module = $DB->get_record($cm->modname, array('id' => $cm->instance));
$bbbsession['meetingname'] = $cm->name;
$bbbsession['meetingdescription'] = bigbluebuttonbn_html2text($cm_module->intro, 64);
} else {
$bbbsession['meetingname'] = "";
$bbbsession['meetingdescription'] = "";
}
$bbbsession['record'] = true;
// Additional info related to the course
$bbbsession['context'] = $context;
$bbbsession['course'] = $course;
$bbbsession['cm'] = $cm;
// Metadata (origin)
$bbbsession['origin'] = "Moodle";
$bbbsession['originVersion'] = $CFG->release;
$parsedUrl = parse_url($CFG->wwwroot);
$bbbsession['originServerName'] = $parsedUrl['host'];
$bbbsession['originServerUrl'] = $CFG->wwwroot;
$bbbsession['originServerCommonName'] = '';
$bbbsession['originTag'] = 'moodle-tinymce_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')';
// Metadata (context)
$bbbsession['contextActivityName'] = $bbbsession['meetingname'];
$bbbsession['contextActivityDescription'] = $bbbsession['meetingdescription'];
$bbbsession['contextActivityTags'] = "";
// Operation URLs
$sesskey = sesskey();
$bbbsession['logoutURL'] = $CFG->wwwroot.MOODLE_TINYMCE_BIGBLUEBUTTONBN_URL.'?contextid='.$contextid.'&content='.urlencode($content).'&sesskey='.$sesskey.'&action=logout';
$bbbsession['launchURL'] = $CFG->wwwroot.MOODLE_TINYMCE_BIGBLUEBUTTONBN_URL.'?contextid='.$contextid.'&content='.urlencode($content).'&sesskey='.$sesskey.'&action=launch';
//$bbbsession['recordingReadyURL'] = $CFG->wwwroot.'/mod/bigbluebuttonbn/bbb_broker.php?action=recording_ready';
$SESSION->bigbluebuttonbn_bbbsession = $bbbsession;
////////////////////////////////////////////////
///// BigBlueButton Session Setup Ends /////
////////////////////////////////////////////////
}
echo $OUTPUT->header();
//$mform->display();
$recordings = bigbluebuttonbn_getRecordingsArray( $bbbsession['meetingid'], $bbbsession['endpoint'], $bbbsession['shared_secret'] );
//If not annotated and no recordings or action=launch proceed with the login
if ( $action == 'launch' || $action != 'logout' && !bigbluebuttonbn_is_annotated($content) && empty($recordings) ) {
// Try to join BigBlueButton directly.
$error = array();
$meeting = bigbluebuttonbn_getMeetingArray( $bbbsession['meetingid'], $bbbsession['endpoint'], $bbbsession['shared_secret'] );
if ( $meeting ) {
$password = $meeting['moderatorPW'];
} else {
//// Create the meeting
////// Prepare metadata
$metadata = array("meta_bn-origin" => $bbbsession['origin'],
"meta_bbb-origin-version" => $bbbsession['originVersion'],
"meta_bbb-origin-server-name" => $bbbsession['originServerName'],
"meta_bbb-origin-server-common-name" => $bbbsession['originServerCommonName'],
"meta_bbb-origin-tag" => $bbbsession['originTag'],
"meta_bbb-context" => $bbbsession['course']->fullname,
"meta_bbb-recording-name" => $bbbsession['contextActivityName'],
"meta_bbb-recording-description" => $bbbsession['contextActivityDescription'],
"meta_bbb-recording-tags" => $bbbsession['contextActivityTags'],
);
////// Execute the create command
$response = bigbluebuttonbn_getCreateMeetingArray(
$bbbsession['meetingname'],
$bbbsession['meetingid'],
'', //welcome
$bbbsession['modPW'],
$bbbsession['viewerPW'],
$bbbsession['shared_secret'],
$bbbsession['endpoint'],
$bbbsession['logoutURL'],
'true', //record
0, //durationtime
0, //voicebridge
0, //userlimit
$metadata
);
if (!$response) {
//////// If the server is unreachable, then prompts the user of the necessary action
error_log("If the server is unreachable, then prompts the user of the necessary action");
$error = array('messageKey' => $response['messageKey'], 'message' => $response['message']);
} else if( $response['returncode'] == "FAILED" ) {
//////// The meeting was not created
error_log("The meeting was not created");
$error = array('messageKey' => $response['messageKey'], 'message' => $response['message']);
} else if ($response['hasBeenForciblyEnded'] == "true"){
//////// Meeting has been forcibely ended
error_log("Meeting has been forcibely ended");
$error = array('messageKey' => $response['messageKey'], 'message' => $response['message']);
} else {
//////// Meeting was successfuly created
}
$password = $bbbsession['modPW'];
}
if ( empty($error) ) {
// get defaul config XML
$defaultConfigXML = bigbluebuttonbn_getDefaultConfigXML($bbbsession['endpoint'], $bbbsession['shared_secret']);
if ( isset($defaultConfigXML->returncode) ) {
error_log("Default config XML could not be retrieved");
$error = array('messageKey' => $defaultConfigXML->response['messageKey'], 'message' => $defaultConfigXML->response['message']);
$configToken = null;
} else {
error_log("Default config XML successfuly retrieved");
//prepare configXML
$defaultConfigXMLTrimmed = str_replace("\n", '', preg_replace('~\s*(<([^-->]*)>[^<]*<!--\2-->|<[^>]*>)\s*~','$1', str_replace("<?xml version=\"1.0\"?>\n", '', $defaultConfigXML->asXML())));
$dom = new DOMDocument();
$dom->loadXML($defaultConfigXMLTrimmed);
$xpath = new DOMXPath($dom);
//// set layout bbb.layout.name.videochat
$element = $xpath->query('//layout')->item(0);
$element->setAttribute('defaultLayout', 'bbb.layout.name.videochat');
$element->setAttribute('showLayoutTools', 'false');
$element->setAttribute('confirmLogout', 'false');
$element->setAttribute('showRecordingNotification', 'false');
//// remove desktop sharing
$element = $xpath->query('//modules/module[@name=\'DeskShareModule\']')->item(0);
if ( $element != null ) {
$element->setAttribute('showButton', 'false');
} else {
$element = $xpath->query('//modules/module[@name=\'ScreenshareModule\']')->item(0);
if ( $element != null ) {
$element->setAttribute('showButton', 'false');
}
}
//// remove layout menu
$element = $xpath->query('//modules/module[@name=\'LayoutModule\']')->item(0);
$element->setAttribute('enableEdit', 'false');
//// remove PhoneModule button
$element = $xpath->query('//modules/module[@name=\'PhoneModule\']')->item(0);
$element->setAttribute('showButton', 'true');
$element->setAttribute('skipCheck', 'true');
$element->setAttribute('listenOnlyMode', 'false');
//// remove VideoconfModule button
$element = $xpath->query('//modules/module[@name=\'VideoconfModule\']')->item(0);
$element->setAttribute('autoStart', 'true');
$element->setAttribute('showButton', 'true');
$element->setAttribute('skipCamSettingsCheck', 'true');
// set config XML
$configXML = str_replace("<?xml version=\"1.0\"?>\n", '', $dom->saveXML());
$configToken = bigbluebuttonbn_bbb_broker_set_config_xml($bbbsession['meetingid'], $configXML);
}
// obtain join_url
$join_url = bigbluebuttonbn_getJoinURL($bbbsession['meetingid'], $bbbsession['username'], $password, $bbbsession['shared_secret'], $bbbsession['endpoint'], $bbbsession['logoutURL'], $configToken);
// render javascript for executing the redirect
echo "<script language=\"javascript\">//<![CDATA[\n";
echo "window.location = '".$join_url."';";
echo "//]]\n";
echo "</script>\n";
} else {
print $error['message'];
}
} else {
if ( $action == 'logout' ) {
//Execute end command
$meeting_info = bigbluebuttonbn_bbb_broker_do_end_meeting($bbbsession['meetingid'], $bbbsession['modPW']);
}
// Recording ready (or annotation deleted manually). Show UI for annotate/cancel based on the existent recording.
$out = "\n";
$out .= '<style>'."\n";
$out .= ' div.show-recording {'."\n";
$out .= ' position: relative;'."\n";
$out .= ' float:left;'."\n";
$out .= ' margin:5px;'."\n";
$out .= ' }'."\n";
$out .= ' div.show-recording:hover img{'."\n";
$out .= ' opacity:0.5;'."\n";
$out .= ' }'."\n";
$out .= ' div.show-recording:hover input {'."\n";
$out .= ' display: block;'."\n";
$out .= ' }'."\n";
$out .= ' div.show-recording input {'."\n";
$out .= ' position:absolute;'."\n";
$out .= ' display:none;'."\n";
$out .= ' }'."\n";
$out .= ' div.show-recording input.delete {'."\n";
$out .= ' top:0;'."\n";
$out .= ' left:79%;'."\n";
$out .= ' }'."\n";
$out .= '</style>'."\n";
$out .= '<script type="text/javascript">'."\n";
// Because there is no relative path to TinyMCE, we have to use JavaScript
// to work out correct path from the .js files from TinyMCE. Only files
// inside this plugin can be included with relative path (below).
$out .= ' var editor_tinymce_include = function(path) {'."\n";
$out .= ' document.write(\'<script type="text/javascript" src="\' + parent.tinyMCE.baseURL + \'/\' + path + \'"></\' + \'script>\');'."\n";
$out .= ' };'."\n";
$out .= ' editor_tinymce_include(\'tiny_mce_popup.js\');'."\n";
$out .= ' editor_tinymce_include(\'utils/validate.js\');'."\n";
$out .= ' editor_tinymce_include(\'utils/form_utils.js\');'."\n";
$out .= ' editor_tinymce_include(\'utils/editable_selects.js\');'."\n";
$out .= '</script>'."\n";
$out .= '<div><center>'."\n";
//// Recordings
$out .= html_writer::start_tag('div', array('id' => 'recording_selector', 'class' => 'btn-group', 'role' => 'group'));
$rec_img_src = $CFG->wwwroot.'/mod/bigbluebuttonbn/pix/bigbluebutton-80.png';
$rec_img_lbl = get_string('recording_ready', 'tinymce_bigbluebuttonbn');
foreach ( $recordings as $recording ) {
// If recording is the one used in the annotation add class 'active'
$rec_lnk_att = array('onclick' => 'M.tinymce_bigbluebuttonbn.view_select(this);', 'type' => 'button', 'class' => 'btn btn-secondary recording', 'ondblclick' => 'window.open(\''.$recording['playbacks']['presentation']['url'].'\');return false;', 'id' => $recording['recordID'], 'title' => $rec_img_lbl, 'data-url' => $recording['playbacks']['presentation']['url']);
$rec_btn = html_writer::tag('button', html_writer::img($rec_img_src, $rec_img_lbl), $rec_lnk_att);
$out .= '<div id="'.$recording['recordID'].'" class="show-recording">'.$rec_btn.'<input class="delete" type="button" value="x" onclick="M.tinymce_bigbluebuttonbn.view_delete(\''.$recording['recordID'].'\');" /></div>';
}
$out .= html_writer::end_tag('div');
//// Create a button for adding a new recording to the selection panel
$add_rec_icon = $OUTPUT->pix_icon('t/add', get_string('add'), null, array('title' => get_string('add'), 'class' => 'icon'));
$add_rec_lnk_att = array('id' => 'recording_add', 'onclick' => 'window.location.replace(\''.$bbbsession['launchURL'].'\');return false;');
//// If logout, add a processing recording resource
if ( $action == 'logout' ) {
////// Button for adding a new recording is hidden
$add_rec_lnk_att['class'] = 'hidden';
////// Add the spinning wheel
$poll_img_src = $CFG->wwwroot.'/mod/bigbluebuttonbn/pix/processing64.gif';
$poll_img_lbl =get_string('recording_processing', 'tinymce_bigbluebuttonbn');
$poll_img_att = array('id' => 'recording_polling', 'title' => get_string('recording_processing', 'tinymce_bigbluebuttonbn'));
$out .= ' '.html_writer::img($poll_img_src, $poll_img_lbl, $poll_img_att);
}
//// Add the button for adding a new recording to the selection panel
$out .= ' '.html_writer::tag('button', $add_rec_icon, $add_rec_lnk_att);
// Button for Annotate
$text = get_string('action_annotation_annotate', 'tinymce_bigbluebuttonbn');
$linkatt = array('onclick' => 'M.tinymce_bigbluebuttonbn.view_annotate();', 'class' => 'hidden-print');
$button = html_writer::tag('button', $text, $linkatt);
$out .= '<br><br>'.$button;
// Button for Cancel
$text = get_string('action_annotation_cancel', 'tinymce_bigbluebuttonbn');
$linkatt = array('onclick' => 'M.tinymce_bigbluebuttonbn.view_cancel();', 'class' => 'hidden-print');
$button = html_writer::tag('button', $text, $linkatt);
$out .= ' '.$button;
$out .= "\n".'</center></div>'."\n";
print $out;
$ping_interval = bigbluebuttonbn_get_cfg_waitformoderator_ping_interval();
$jsVars = array(
'meetingid' => $bbbsession['meetingid'],
'ping_interval' => ($ping_interval > 0? $ping_interval * 1000: 15000),
'action' => $action,
'recording_ready' => get_string('recording_ready', 'tinymce_bigbluebuttonbn'),
'recording_icon80' => $CFG->wwwroot.'/mod/bigbluebuttonbn/pix/bigbluebutton-80.png',
'recording_icon32' => $CFG->wwwroot.'/mod/bigbluebuttonbn/pix/bigbluebutton-32.png'
);
$PAGE->requires->data_for_js('bigbluebuttonbn', $jsVars);
$jsmodule = array(
'name' => 'tinymce_bigbluebuttonbn',
'fullpath' => MOODLE_TINYMCE_BIGBLUEBUTTONBN_ROOT.'tinymce_module.js',
'requires' => array('datasource-get', 'datasource-jsonschema', 'datasource-polling'),
);
$PAGE->requires->js_init_call('M.tinymce_bigbluebuttonbn.view_init', array(), false, $jsmodule);
}
echo $OUTPUT->footer();