|
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
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Atto recordrtc library functions |
|
19
|
|
|
* |
|
20
|
|
|
* @package atto_recordrtc |
|
21
|
|
|
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
|
22
|
|
|
* @author Jacob Prud'homme (jacob [dt] prudhomme [at] blindsidenetworks [dt] com) |
|
23
|
|
|
* @copyright 2017 Blindside Networks Inc. |
|
24
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @module moodle-atto_recordrtc-button |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Atto text editor recordrtc plugin. |
|
33
|
|
|
* |
|
34
|
|
|
* @namespace M.atto_recordrtc |
|
35
|
|
|
* @class button |
|
36
|
|
|
* @extends M.editor_atto.EditorPlugin |
|
37
|
|
|
*/ |
|
38
|
|
|
|
|
39
|
|
|
// ESLint directives. |
|
40
|
|
|
/* eslint-disable camelcase, spaced-comment */ |
|
41
|
|
|
|
|
42
|
|
|
// JSHint directives. |
|
43
|
|
|
/*global M */ |
|
44
|
|
|
/*jshint onevar: false */ |
|
45
|
|
|
|
|
46
|
|
|
// Scrutinizer CI directives. |
|
47
|
|
|
/** global: Y */ |
|
48
|
|
|
/** global: M */ |
|
49
|
|
|
|
|
50
|
|
|
var PLUGINNAME = 'atto_recordrtc', |
|
51
|
|
|
TEMPLATE = '' + |
|
52
|
|
|
'<div class="{{PLUGINNAME}} container-fluid">' + |
|
53
|
|
|
'<div class="{{bs_row}} hide">' + |
|
54
|
|
|
'<div class="{{bs_col}}12">' + |
|
55
|
|
|
'<div id="alert-warning" class="alert {{bs_al_warn}}">' + |
|
56
|
|
|
'<strong>{{browseralert_title}}</strong> {{browseralert}}' + |
|
57
|
|
|
'</div>' + |
|
58
|
|
|
'</div>' + |
|
59
|
|
|
'</div>' + |
|
60
|
|
|
'<div class="{{bs_row}} hide">' + |
|
61
|
|
|
'<div class="{{bs_col}}12">' + |
|
62
|
|
|
'<div id="alert-danger" class="alert {{bs_al_dang}}">' + |
|
63
|
|
|
'<strong>{{insecurealert_title}}</strong> {{insecurealert}}' + |
|
64
|
|
|
'</div>' + |
|
65
|
|
|
'</div>' + |
|
66
|
|
|
'</div>' + |
|
67
|
|
|
'<div class="{{bs_row}} hide">' + |
|
68
|
|
|
'{{#if isAudio}}' + |
|
69
|
|
|
'<div class="{{bs_col}}1"></div>' + |
|
70
|
|
|
'<div class="{{bs_col}}10">' + |
|
71
|
|
|
'<audio id="player"></audio>' + |
|
72
|
|
|
'</div>' + |
|
73
|
|
|
'<div class="{{bs_col}}1"></div>' + |
|
74
|
|
|
'{{else}}' + |
|
75
|
|
|
'<div class="{{bs_col}}12">' + |
|
76
|
|
|
'<video id="player"></video>' + |
|
77
|
|
|
'</div>' + |
|
78
|
|
|
'{{/if}}' + |
|
79
|
|
|
'</div>' + |
|
80
|
|
|
'<div class="{{bs_row}}">' + |
|
81
|
|
|
'<div class="{{bs_col}}1"></div>' + |
|
82
|
|
|
'<div class="{{bs_col}}10">' + |
|
83
|
|
|
'<button id="start-stop" class="{{bs_ss_btn}}">{{startrecording}}</button>' + |
|
84
|
|
|
'</div>' + |
|
85
|
|
|
'<div class="{{bs_col}}1"></div>' + |
|
86
|
|
|
'</div>' + |
|
87
|
|
|
'<div class="{{bs_row}} hide">' + |
|
88
|
|
|
'<div class="{{bs_col}}3"></div>' + |
|
89
|
|
|
'<div class="{{bs_col}}6">' + |
|
90
|
|
|
'<button id="upload" class="btn btn-primary btn-block">{{attachrecording}}</button>' + |
|
91
|
|
|
'</div>' + |
|
92
|
|
|
'<div class="{{bs_col}}3"></div>' + |
|
93
|
|
|
'</div>' + |
|
94
|
|
|
'</div>'; |
|
95
|
|
|
|
|
96
|
|
|
Y.namespace('M.atto_recordrtc').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { |
|
97
|
|
|
/** |
|
98
|
|
|
* The current language by default. |
|
99
|
|
|
*/ |
|
100
|
|
|
_lang: 'en', |
|
101
|
|
|
|
|
102
|
|
|
initializer: function() { |
|
103
|
|
|
if (this.get('host').canShowFilepicker('media')) { |
|
104
|
|
|
// Add audio and/or video buttons depending on the settings. |
|
105
|
|
|
var allowedtypes = this.get('allowedtypes'); |
|
106
|
|
|
if (allowedtypes === 'both' || allowedtypes === 'audio') { |
|
107
|
|
|
this._addButton('audio', this._audio); |
|
108
|
|
|
} |
|
109
|
|
|
if (allowedtypes === 'both' || allowedtypes === 'video') { |
|
110
|
|
|
this._addButton('video', this._video); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// Initialize the dialogue box. |
|
114
|
|
|
var dialogue = this.getDialogue({ |
|
115
|
|
|
width: 1000, |
|
116
|
|
|
focusAfterHide: null |
|
117
|
|
|
}); |
|
118
|
|
|
|
|
119
|
|
|
// If dialogue is closed during recording, do the following. |
|
120
|
|
|
dialogue.after('visibleChange', function() { |
|
121
|
|
|
var closed = !dialogue.get('visible'), |
|
122
|
|
|
m = M.atto_recordrtc.commonmodule; |
|
123
|
|
|
|
|
124
|
|
|
if (closed) { |
|
125
|
|
|
window.clearInterval(m.countdownTicker); |
|
126
|
|
|
|
|
127
|
|
|
if (m.mediaRecorder && m.mediaRecorder.state !== 'inactive') { |
|
128
|
|
|
m.mediaRecorder.stop(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (m.stream) { |
|
132
|
|
|
m.stream.getTracks().forEach(function(track) { |
|
133
|
|
|
if (track.readyState !== 'ended') { |
|
134
|
|
|
track.stop(); |
|
135
|
|
|
} |
|
136
|
|
|
}); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
}); |
|
141
|
|
|
|
|
142
|
|
|
dialogue.on('click', function() { |
|
143
|
|
|
this.centered(); |
|
144
|
|
|
}); |
|
145
|
|
|
|
|
146
|
|
|
// Require Bowser and adapter.js libraries. |
|
147
|
|
|
window.require(['atto_recordrtc/adapter'], function(adapter) { |
|
148
|
|
|
window.adapter = adapter; |
|
149
|
|
|
}); |
|
150
|
|
|
window.require(['atto_recordrtc/bowser'], function(bowser) { |
|
151
|
|
|
window.bowser = bowser; |
|
152
|
|
|
}); |
|
153
|
|
|
} |
|
154
|
|
|
}, |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Add the buttons to the Atto toolbar. |
|
158
|
|
|
* |
|
159
|
|
|
* @method _addButton |
|
160
|
|
|
* @param {string} type |
|
161
|
|
|
* @param {callback} callback |
|
162
|
|
|
* @private |
|
163
|
|
|
*/ |
|
164
|
|
|
_addButton: function(type, callback) { |
|
165
|
|
|
this.addButton({ |
|
166
|
|
|
buttonName: type, |
|
167
|
|
|
icon: this.get(type + 'rtcicon'), |
|
168
|
|
|
iconComponent: PLUGINNAME, |
|
169
|
|
|
callback: callback, |
|
170
|
|
|
title: type + 'rtc', |
|
171
|
|
|
tags: type + 'rtc', |
|
172
|
|
|
tagMatchRequiresAll: false |
|
173
|
|
|
}); |
|
174
|
|
|
}, |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Toggle audiortc and normal display mode |
|
178
|
|
|
* |
|
179
|
|
|
* @method _audio |
|
180
|
|
|
* @private |
|
181
|
|
|
*/ |
|
182
|
|
|
_audio: function() { |
|
183
|
|
|
var dialogue = this.getDialogue(); |
|
184
|
|
|
|
|
185
|
|
|
dialogue.set('headerContent', M.util.get_string('audiortc', 'atto_recordrtc')); |
|
186
|
|
|
dialogue.set('bodyContent', this._createContent('audio')); |
|
187
|
|
|
|
|
188
|
|
|
dialogue.show(); |
|
189
|
|
|
|
|
190
|
|
|
M.atto_recordrtc.audiomodule.init(this); |
|
191
|
|
|
}, |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Toggle videortc and normal display mode |
|
195
|
|
|
* |
|
196
|
|
|
* @method _video |
|
197
|
|
|
* @private |
|
198
|
|
|
*/ |
|
199
|
|
|
_video: function() { |
|
200
|
|
|
var dialogue = this.getDialogue(); |
|
201
|
|
|
|
|
202
|
|
|
dialogue.set('headerContent', M.util.get_string('videortc', 'atto_recordrtc')); |
|
203
|
|
|
dialogue.set('bodyContent', this._createContent('video')); |
|
204
|
|
|
|
|
205
|
|
|
dialogue.show(); |
|
206
|
|
|
|
|
207
|
|
|
M.atto_recordrtc.videomodule.init(this); |
|
208
|
|
|
}, |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Create the HTML to be displayed in the dialogue box |
|
212
|
|
|
* |
|
213
|
|
|
* @method _createContent |
|
214
|
|
|
* @param {string} type |
|
215
|
|
|
* @returns {Object} |
|
216
|
|
|
* @private |
|
217
|
|
|
*/ |
|
218
|
|
|
_createContent: function(type) { |
|
219
|
|
|
var isAudio = (type === 'audio'), |
|
220
|
|
|
bsRow = this.get('oldermoodle') ? 'row-fluid' : 'row', |
|
221
|
|
|
bsCol = this.get('oldermoodle') ? 'span' : 'col-xs-', |
|
222
|
|
|
bsAlWarn = this.get('oldermoodle') ? '' : 'alert-warning', |
|
223
|
|
|
bsAlDang = this.get('oldermoodle') ? 'alert-error' : 'alert-danger', |
|
224
|
|
|
bsSsBtn = this.get('oldermoodle') ? 'btn btn-large btn-danger btn-block' |
|
225
|
|
|
: 'btn btn-lg btn-outline-danger btn-block'; |
|
226
|
|
|
|
|
227
|
|
|
var bodyContent = Y.Handlebars.compile(TEMPLATE)({ |
|
228
|
|
|
PLUGINNAME: PLUGINNAME, |
|
229
|
|
|
isAudio: isAudio, |
|
230
|
|
|
bs_row: bsRow, |
|
231
|
|
|
bs_col: bsCol, |
|
232
|
|
|
bs_al_warn: bsAlWarn, |
|
233
|
|
|
bs_al_dang: bsAlDang, |
|
234
|
|
|
bs_ss_btn: bsSsBtn, |
|
235
|
|
|
bs_ul_btn: 'btn btn-primary btn-block', |
|
236
|
|
|
browseralert_title: M.util.get_string('browseralert_title', 'atto_recordrtc'), |
|
237
|
|
|
browseralert: M.util.get_string('browseralert', 'atto_recordrtc'), |
|
238
|
|
|
insecurealert_title: M.util.get_string('insecurealert_title', 'atto_recordrtc'), |
|
239
|
|
|
insecurealert: M.util.get_string('insecurealert', 'atto_recordrtc'), |
|
240
|
|
|
startrecording: M.util.get_string('startrecording', 'atto_recordrtc'), |
|
241
|
|
|
attachrecording: M.util.get_string('attachrecording', 'atto_recordrtc') |
|
242
|
|
|
}); |
|
243
|
|
|
|
|
244
|
|
|
return bodyContent; |
|
245
|
|
|
}, |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Close the dialogue without further action. |
|
249
|
|
|
* |
|
250
|
|
|
* @method closeDialogue |
|
251
|
|
|
* @param {Object} scope The "this" context of the editor. |
|
252
|
|
|
*/ |
|
253
|
|
|
closeDialogue: function(scope) { |
|
254
|
|
|
scope.getDialogue().hide(); |
|
255
|
|
|
|
|
256
|
|
|
scope.editor.focus(); |
|
257
|
|
|
}, |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Insert the annotation link in the editor. |
|
261
|
|
|
* |
|
262
|
|
|
* @method setLink |
|
263
|
|
|
* @param {Object} scope The "this" context of the editor. |
|
264
|
|
|
* @param {string} annotation The HTML link to the recording. |
|
265
|
|
|
*/ |
|
266
|
|
|
setLink: function(scope, annotation) { |
|
267
|
|
|
scope.getDialogue().hide(); |
|
268
|
|
|
|
|
269
|
|
|
scope.editor.focus(); |
|
270
|
|
|
scope.get('host').insertContentAtFocusPoint(annotation); |
|
271
|
|
|
scope.markUpdated(); |
|
272
|
|
|
} |
|
273
|
|
|
}, { |
|
274
|
|
|
ATTRS: { |
|
275
|
|
|
/** |
|
276
|
|
|
* The contextid to use when generating this recordrtc. |
|
277
|
|
|
* |
|
278
|
|
|
* @attribute contextid |
|
279
|
|
|
* @type String |
|
280
|
|
|
*/ |
|
281
|
|
|
contextid: { |
|
282
|
|
|
value: null |
|
283
|
|
|
}, |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* The sesskey to use when generating this recordrtc. |
|
287
|
|
|
* |
|
288
|
|
|
* @attribute sesskey |
|
289
|
|
|
* @type String |
|
290
|
|
|
*/ |
|
291
|
|
|
sesskey: { |
|
292
|
|
|
value: null |
|
293
|
|
|
}, |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* The allowedtypes to use when generating this recordrtc. |
|
297
|
|
|
* |
|
298
|
|
|
* @attribute allowedtypes |
|
299
|
|
|
* @type String |
|
300
|
|
|
*/ |
|
301
|
|
|
allowedtypes: { |
|
302
|
|
|
value: null |
|
303
|
|
|
}, |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* The audiobitrate to use when generating this recordrtc. |
|
307
|
|
|
* |
|
308
|
|
|
* @attribute audiobitrate |
|
309
|
|
|
* @type String |
|
310
|
|
|
*/ |
|
311
|
|
|
audiobitrate: { |
|
312
|
|
|
value: null |
|
313
|
|
|
}, |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* The videobitrate to use when generating this recordrtc. |
|
317
|
|
|
* |
|
318
|
|
|
* @attribute videobitrate |
|
319
|
|
|
* @type String |
|
320
|
|
|
*/ |
|
321
|
|
|
videobitrate: { |
|
322
|
|
|
value: null |
|
323
|
|
|
}, |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* The timelimit to use when generating this recordrtc. |
|
327
|
|
|
* |
|
328
|
|
|
* @attribute timelimit |
|
329
|
|
|
* @type String |
|
330
|
|
|
*/ |
|
331
|
|
|
timelimit: { |
|
332
|
|
|
value: null |
|
333
|
|
|
}, |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* The audiortcicon to use when generating this recordrtc. |
|
337
|
|
|
* |
|
338
|
|
|
* @attribute audiortcicon |
|
339
|
|
|
* @type String |
|
340
|
|
|
*/ |
|
341
|
|
|
audiortcicon: { |
|
342
|
|
|
value: null |
|
343
|
|
|
}, |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* The videortcicon to use when generating this recordrtc. |
|
347
|
|
|
* |
|
348
|
|
|
* @attribute videortcicon |
|
349
|
|
|
* @type String |
|
350
|
|
|
*/ |
|
351
|
|
|
videortcicon: { |
|
352
|
|
|
value: null |
|
353
|
|
|
}, |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* True if Moodle is version < 3.2. |
|
357
|
|
|
* |
|
358
|
|
|
* @attribute oldermoodle |
|
359
|
|
|
* @type Boolean |
|
360
|
|
|
*/ |
|
361
|
|
|
oldermoodle: { |
|
362
|
|
|
value: null |
|
363
|
|
|
}, |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* Maximum upload size set on server, in MB. |
|
367
|
|
|
* |
|
368
|
|
|
* @attribute maxrecsize |
|
369
|
|
|
* @type String |
|
370
|
|
|
*/ |
|
371
|
|
|
maxrecsize: { |
|
372
|
|
|
value: null |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
}); |
|
376
|
|
|
|