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
|
|
|
'audio/webm;codecs=opus', |
84
|
|
|
'audio/ogg;codecs=opus' |
85
|
|
|
]; |
86
|
|
|
options = { |
87
|
|
|
audioBitsPerSecond: window.parseInt(cm.editorScope.get('audiobitrate')) |
88
|
|
|
}; |
89
|
|
|
} else { |
90
|
|
|
types = [ |
91
|
|
|
'video/webm;codecs=vp9,opus', |
92
|
|
|
'video/webm;codecs=h264,opus', |
93
|
|
|
'video/webm;codecs=vp8,opus' |
94
|
|
|
]; |
95
|
|
|
options = { |
96
|
|
|
audioBitsPerSecond: window.parseInt(cm.editorScope.get('audiobitrate')), |
97
|
|
|
videoBitsPerSecond: window.parseInt(cm.editorScope.get('videobitrate')) |
98
|
|
|
}; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
var compatTypes = types.filter(function(type) { |
102
|
|
|
return window.MediaRecorder.isTypeSupported(type); |
103
|
|
|
}); |
104
|
|
|
|
105
|
|
|
if (compatTypes.length !== 0) { |
106
|
|
|
options.mimeType = compatTypes[0]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return options; |
110
|
|
|
} |
111
|
|
|
}; |
112
|
|
|
|