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 for function abstractions
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
// ESLint directives.
28
/* eslint-disable camelcase */
29
 
30
// Scrutinizer CI directives.
31
/** global: M */
32
/** global: Y */
33
 
34
M.atto_recordrtc = M.atto_recordrtc || {};
35
 
36
// Shorten access to module namespaces.
37
var cm = M.atto_recordrtc.commonmodule,
38
    am = M.atto_recordrtc.abstractmodule;
39
 
40
M.atto_recordrtc.abstractmodule = {
41
    // A helper for making a Moodle alert appear.
42
    // Subject is the content of the alert (which error ther alert is for).
43
    // Possibility to add on-alert-close event.
44
    show_alert: function(subject, onCloseEvent) {
45
        Y.use('moodle-core-notification-alert', function() {
46
            var dialogue = new M.core.alert({
47
                title: M.util.get_string(subject + '_title', 'atto_recordrtc'),
48
                message: M.util.get_string(subject, 'atto_recordrtc')
49
            });
50
 
51
            if (onCloseEvent) {
52
                dialogue.after('complete', onCloseEvent);
53
            }
54
        });
55
    },
56
 
57
    // Handle getUserMedia errors.
58
    handle_gum_errors: function(error, commonConfig) {
59
        var btnLabel = M.util.get_string('recordingfailed', 'atto_recordrtc'),
60
            treatAsStopped = function() {
61
                commonConfig.onMediaStopped(btnLabel);
62
            };
63
 
64
        // Changes 'CertainError' -> 'gumcertain' to match language string names.
65
        var stringName = 'gum' + error.name.replace('Error', '').toLowerCase();
66
 
67
        // After alert, proceed to treat as stopped recording, or close dialogue.
68
        if (stringName !== 'gumsecurity') {
69
            am.show_alert(stringName, treatAsStopped);
70
        } else {
71
            am.show_alert(stringName, function() {
72
                cm.editorScope.closeDialogue(cm.editorScope);
73
            });
74
        }
75
    },
76
 
77
    // Select best options for the recording codec.
78
    select_rec_options: function(recType) {
79
        var types, options;
80
 
81
        if (recType === 'audio') {
82
            types = [
83
                // Firefox supports webm and ogg but Chrome only supports ogg.
84
                // So we use ogg to maximize the compatibility.
85
                'audio/ogg;codecs=opus',
86
 
87
                // Safari supports mp4.
88
                'audio/mp4;codecs=opus',
89
                'audio/mp4;codecs=wav',
90
                'audio/mp4;codecs=mp3',
91
            ];
92
            options = {
93
                audioBitsPerSecond: window.parseInt(cm.editorScope.get('audiobitrate'))
94
            };
95
        } else {
96
            types = [
97
                // Support webm as a preference.
98
                // This container supports both vp9, and vp8.
99
                // It does not support AVC1/h264 at all.
100
                // It is supported by Chromium, and Firefox browsers, but not Safari.
101
                'video/webm;codecs=vp9,opus',
102
                'video/webm;codecs=vp8,opus',
103
 
104
                // Fall back to mp4 if webm is not available.
105
                // The mp4 container supports v9, and h264 but neither of these are supported for recording on other
106
                // browsers.
107
                // In addition to this, we can record in v9, but VideoJS does not support an mp4 containern with v9 codec
108
                // for playback. We leave it as a final option as a just-in-case.
109
                'video/mp4;codecs=h264,opus',
110
                'video/mp4;codecs=h264,wav',
111
                'video/mp4;codecs=v9,opus',
112
            ];
113
            options = {
114
                audioBitsPerSecond: window.parseInt(cm.editorScope.get('audiobitrate')),
115
                videoBitsPerSecond: window.parseInt(cm.editorScope.get('videobitrate'))
116
            };
117
        }
118
 
119
        var possibleTypes = types.reduce(function(result, type) {
120
            result.push(type);
121
            // Safari seems to use codecs: instead of codecs=.
122
            // It is safe to add both, so we do, but we want them to remain in order.
123
            result.push(type.replace('=', ':'));
124
            return result;
125
        }, []);
126
 
127
        var compatTypes = possibleTypes.filter(function(type) {
128
            return window.MediaRecorder.isTypeSupported(type);
129
        });
130
 
131
        if (compatTypes.length !== 0) {
132
            options.mimeType = compatTypes[0];
133
        }
134
 
135
        return options;
136
    }
137
};