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
|
|
|
// JSHint directives. |
28
|
|
|
/*jshint es5: true */ |
29
|
|
|
/*jshint onevar: false */ |
30
|
|
|
/*jshint shadow: true */ |
31
|
|
|
/*global M */ |
32
|
|
|
|
33
|
|
|
// Scrutinizer CI directives. |
34
|
|
|
/** global: M */ |
35
|
|
|
/** global: Y */ |
36
|
|
|
|
37
|
|
|
M.atto_recordrtc = M.atto_recordrtc || {}; |
38
|
|
|
|
39
|
|
|
// Shorten access to module namespaces. |
40
|
|
|
var cm = M.atto_recordrtc.commonmodule; |
41
|
|
|
|
42
|
|
|
M.atto_recordrtc.commonmodule = { |
43
|
|
|
// Unitialized variables to be used by the other modules. |
44
|
|
|
editorScope: null, |
45
|
|
|
alertWarning: null, |
46
|
|
|
alertDanger: null, |
47
|
|
|
player: null, |
48
|
|
|
playerDOM: null, // Used to manipulate DOM directly. |
49
|
|
|
startStopBtn: null, |
50
|
|
|
uploadBtn: null, |
51
|
|
|
recType: null, |
52
|
|
|
stream: null, |
53
|
|
|
mediaRecorder: null, |
54
|
|
|
olderMoodle: null, |
55
|
|
|
|
56
|
|
|
// A helper for making a Moodle alert appear. |
57
|
|
|
// Subject is the content of the alert (which error ther alert is for). |
58
|
|
|
// Possibility to add on-alert-close event. |
59
|
|
|
show_alert: function(subject, onCloseEvent) { |
60
|
|
|
Y.use('moodle-core-notification-alert', function() { |
61
|
|
|
var dialogue = new M.core.alert({ |
62
|
|
|
title: M.util.get_string(subject + '_title', 'atto_recordrtc'), |
63
|
|
|
message: M.util.get_string(subject, 'atto_recordrtc') |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
if (onCloseEvent) { |
67
|
|
|
dialogue.after('complete', onCloseEvent); |
68
|
|
|
} |
69
|
|
|
}); |
70
|
|
|
}, |
71
|
|
|
|
72
|
|
|
// Notify and redirect user if plugin is used from insecure location. |
73
|
|
|
check_secure: function() { |
74
|
|
|
var isSecureOrigin = (window.location.protocol === 'https:') || |
75
|
|
|
(window.location.host.indexOf('localhost') !== -1); |
76
|
|
|
|
77
|
|
|
if (!isSecureOrigin) { |
78
|
|
|
cm.alertDanger.ancestor().ancestor().removeClass('hide'); |
79
|
|
|
} |
80
|
|
|
}, |
81
|
|
|
|
82
|
|
|
// Display "consider switching browsers" message if not using: |
83
|
|
|
// - Firefox 29+; |
84
|
|
|
// - Chrome 49+; |
85
|
|
|
// - Opera 36+. |
86
|
|
|
check_browser: function() { |
87
|
|
|
if (!((window.bowser.firefox && window.bowser.version >= 29) || |
88
|
|
|
(window.bowser.chrome && window.bowser.version >= 49) || |
89
|
|
|
(window.bowser.opera && window.bowser.version >= 36))) { |
90
|
|
|
cm.alertWarning.ancestor().ancestor().removeClass('hide'); |
91
|
|
|
} |
92
|
|
|
}, |
93
|
|
|
|
94
|
|
|
// Capture webcam/microphone stream. |
95
|
|
|
capture_user_media: function(mediaConstraints, successCallback, errorCallback) { |
96
|
|
|
window.navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback); |
97
|
|
|
}, |
98
|
|
|
|
99
|
|
|
// Generates link to recorded annotation to be inserted. |
100
|
|
|
create_annotation: function(type, recording_url) { |
101
|
|
|
var linkText = window.prompt(M.util.get_string('annotationprompt', 'atto_recordrtc'), |
102
|
|
|
M.util.get_string('annotation:' + type, 'atto_recordrtc')); |
103
|
|
|
|
104
|
|
|
// Return HTML for annotation link, if user did not press "Cancel". |
105
|
|
|
if (!linkText) { |
106
|
|
|
return undefined; |
107
|
|
|
} else { |
108
|
|
|
var annotation = '<a target="_blank" href="' + recording_url + '">' + linkText + '</a>'; |
109
|
|
|
return annotation; |
110
|
|
|
} |
111
|
|
|
}, |
112
|
|
|
|
113
|
|
|
// Inserts link to annotation in editor text area. |
114
|
|
|
insert_annotation: function(type, recording_url) { |
115
|
|
|
var annotation = cm.create_annotation(type, recording_url); |
116
|
|
|
|
117
|
|
|
// Insert annotation link. |
118
|
|
|
// If user pressed "Cancel", just go back to main recording screen. |
119
|
|
|
if (!annotation) { |
120
|
|
|
cm.uploadBtn.set('textContent', M.util.get_string('attachrecording', 'atto_recordrtc')); |
121
|
|
|
} else { |
122
|
|
|
cm.editorScope.setLink(cm.editorScope, annotation); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
}; |
126
|
|
|
|