Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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-danger" class="alert {{bs_al_dang}}">' +
56
            '<strong>{{insecurealert_title}}</strong> {{insecurealert}}' +
57
          '</div>' +
58
        '</div>' +
59
      '</div>' +
60
      '<div class="{{bs_row}} hide">' +
61
        '{{#if isAudio}}' +
62
          '<div class="{{bs_col}}1"></div>' +
63
          '<div class="{{bs_col}}10">' +
64
            '<audio id="player"></audio>' +
65
          '</div>' +
66
          '<div class="{{bs_col}}1"></div>' +
67
        '{{else}}' +
68
          '<div class="{{bs_col}}12">' +
69
            '<video id="player"></video>' +
70
          '</div>' +
71
        '{{/if}}' +
72
      '</div>' +
73
      '<div class="{{bs_row}}">' +
74
        '<div class="{{bs_col}}1"></div>' +
75
        '<div class="{{bs_col}}10">' +
76
          '<button id="start-stop" class="{{bs_ss_btn}}">{{startrecording}}</button>' +
77
        '</div>' +
78
        '<div class="{{bs_col}}1"></div>' +
79
      '</div>' +
80
      '<div class="{{bs_row}} hide">' +
81
        '<div class="{{bs_col}}3"></div>' +
82
        '<div class="{{bs_col}}6">' +
83
          '<button id="upload" class="btn btn-primary btn-block">{{attachrecording}}</button>' +
84
        '</div>' +
85
        '<div class="{{bs_col}}3"></div>' +
86
      '</div>' +
87
    '</div>';
88
 
89
Y.namespace('M.atto_recordrtc').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
90
    /**
91
     * The current language by default.
92
     */
93
    _lang: 'en',
94
 
95
    initializer: function() {
96
        if (this.get('host').canShowFilepicker('media')) {
97
            // Add audio and/or video buttons depending on the settings.
98
            var allowedtypes = this.get('allowedtypes'),
99
                buttonadded = false;
100
            if (allowedtypes === 'both' || allowedtypes === 'audio') {
101
                this._addButton('audio', this._audio);
102
                buttonadded = true;
103
            }
104
            if (allowedtypes === 'both' || allowedtypes === 'video') {
105
                this._addButton('video', this._video);
106
                buttonadded = true;
107
            }
108
            if (!buttonadded) {
109
                // Plugin not available here.
110
                return;
111
            }
112
 
113
            // Initialize the dialogue box.
114
            var dialogue = this.getDialogue({
115
                width: 1000,
116
                focusAfterHide: null
117
            });
118
 
119
            dialogue.after('visibleChange', function() {
120
                var closed = !dialogue.get('visible'),
121
                    m = M.atto_recordrtc.commonmodule;
122
 
123
                if (closed) {
124
                    // If dialogue is closed during recording, do the following.
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
                    // Because the player uses ids to identify things (this should be fixed)
140
                    // we must make sure the dialogue contents only exist once in the DOM.
141
                    // Therefore, when a dialogue is closed, we must remove its contents.
142
                    this.getDialogue().set('bodyContent', '');
143
                }
144
 
145
            }, this);
146
 
147
            dialogue.on('click', function() {
148
                this.centered();
149
            });
150
 
151
            // Require adapter.js library.
152
            window.require(['core/adapter'], function(adapter) {
153
                window.adapter = adapter;
154
            });
155
        }
156
    },
157
 
158
    /**
159
     * Add the buttons to the Atto toolbar.
160
     *
161
     * @method _addButton
162
     * @param {string} type
163
     * @param {callback} callback
164
     * @private
165
     */
166
    _addButton: function(type, callback) {
167
        this.addButton({
168
            buttonName: type,
169
            icon: this.get(type + 'rtcicon'),
170
            iconComponent: PLUGINNAME,
171
            callback: callback,
172
            title: type + 'rtc',
173
            tags: type + 'rtc',
174
            tagMatchRequiresAll: false
175
        });
176
    },
177
 
178
    /**
179
     * Toggle audiortc and normal display mode
180
     *
181
     * @method _audio
182
     * @private
183
     */
184
    _audio: function() {
185
        var dialogue = this.getDialogue({
186
            focusAfterHide: 'audio'
187
        });
188
 
189
        dialogue.set('headerContent', M.util.get_string('audiortc', 'atto_recordrtc'));
190
        dialogue.set('bodyContent', this._createContent('audio'));
191
 
192
        dialogue.show();
193
 
194
        M.atto_recordrtc.audiomodule.init(this);
195
    },
196
 
197
    /**
198
     * Toggle videortc and normal display mode
199
     *
200
     * @method _video
201
     * @private
202
     */
203
    _video: function() {
204
        var dialogue = this.getDialogue({
205
            focusAfterHide: 'video'
206
        });
207
 
208
        dialogue.set('headerContent', M.util.get_string('videortc', 'atto_recordrtc'));
209
        dialogue.set('bodyContent', this._createContent('video'));
210
 
211
        dialogue.show();
212
 
213
        M.atto_recordrtc.videomodule.init(this);
214
    },
215
 
216
    /**
217
     * Create the HTML to be displayed in the dialogue box
218
     *
219
     * @method _createContent
220
     * @param {string} type
221
     * @returns {Object}
222
     * @private
223
     */
224
    _createContent: function(type) {
225
        var isAudio = (type === 'audio'),
226
            bsRow = 'row',
227
            bsCol = 'col-',
228
            bsAlDang = 'alert-danger',
229
            bsSsBtn = 'btn btn-lg btn-outline-danger btn-block';
230
 
231
        var bodyContent = Y.Handlebars.compile(TEMPLATE)({
232
            PLUGINNAME: PLUGINNAME,
233
            isAudio: isAudio,
234
            bs_row: bsRow,
235
            bs_col: bsCol,
236
            bs_al_dang: bsAlDang,
237
            bs_ss_btn: bsSsBtn,
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
            focusAfterHide: null
256
        });
257
 
258
        scope.editor.focus();
259
    },
260
 
261
    /**
262
     * Insert the annotation link in the editor.
263
     *
264
     * @method setLink
265
     * @param {Object} scope The "this" context of the editor.
266
     * @param {string} annotation The HTML link to the recording.
267
     */
268
    setLink: function(scope, annotation) {
269
        scope.getDialogue().hide({
270
            focusAfterHide: null
271
        });
272
 
273
        scope.editor.focus();
274
        scope.get('host').insertContentAtFocusPoint(annotation);
275
        scope.markUpdated();
276
    }
277
}, {
278
    ATTRS: {
279
        /**
280
         * The contextid to use when generating this recordrtc.
281
         *
282
         * @attribute contextid
283
         * @type String
284
         */
285
        contextid: {
286
            value: null
287
        },
288
 
289
        /**
290
         * The sesskey to use when generating this recordrtc.
291
         *
292
         * @attribute sesskey
293
         * @type String
294
         */
295
        sesskey: {
296
            value: null
297
        },
298
 
299
        /**
300
         * The allowedtypes to use when generating this recordrtc.
301
         *
302
         * @attribute allowedtypes
303
         * @type String
304
         */
305
        allowedtypes: {
306
            value: null
307
        },
308
 
309
        /**
310
         * The audiobitrate to use when generating this recordrtc.
311
         *
312
         * @attribute audiobitrate
313
         * @type String
314
         */
315
        audiobitrate: {
316
            value: null
317
        },
318
 
319
        /**
320
         * The videobitrate to use when generating this recordrtc.
321
         *
322
         * @attribute videobitrate
323
         * @type String
324
         */
325
        videobitrate: {
326
            value: null
327
        },
328
 
329
        /**
330
         * The audiotimelimit to use when generating this recordrtc.
331
         *
332
         * @attribute audiotimelimit
333
         * @type String
334
         */
335
        audiotimelimit: {
336
            value: null
337
        },
338
 
339
        /**
340
         * The videotimelimit to use when generating this recordrtc.
341
         *
342
         * @attribute videotimelimit
343
         * @type String
344
         */
345
        videotimelimit: {
346
            value: null
347
        },
348
 
349
        /**
350
         * The defaulttimelimit to use when generating this recordrtc.
351
         *
352
         * @attribute defaulttimelimit
353
         * @type String
354
         */
355
        defaulttimelimit: {
356
            value: null
357
        },
358
 
359
        /**
360
         * The audiortcicon to use when generating this recordrtc.
361
         *
362
         * @attribute audiortcicon
363
         * @type String
364
         */
365
        audiortcicon: {
366
            value: null
367
        },
368
 
369
        /**
370
         * The videortcicon to use when generating this recordrtc.
371
         *
372
         * @attribute videortcicon
373
         * @type String
374
         */
375
        videortcicon: {
376
            value: null
377
        },
378
 
379
        /**
380
         * Maximum upload size set on server, in bytes.
381
         *
382
         * @attribute maxrecsize
383
         * @type String
384
         */
385
        maxrecsize: {
386
            value: null
387
        }
388
    }
389
});