GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#11)
by
unknown
01:41
created

tinymce/js/videomodule.js   A

Complexity

Total Complexity 34
Complexity/F 1.89

Size

Lines of Code 245
Function Count 18

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 0
c 5
b 0
f 0
nc 192
dl 0
loc 245
rs 9.2
wmc 34
mnd 3
bc 29
fnc 18
bpm 1.6111
cpm 1.8888
noi 13

5 Functions

Rating   Name   Duplication   Size   Complexity  
A videomodule.js ➔ d 0 3 1
B 0 21 5
A M.tinymce_recordrtc.stopRecording 0 54 1
B M.tinymce_recordrtc.view_init 0 115 1
B M.tinymce_recordrtc.captureAudioVideo 0 29 1
1
// TinyMCE recordrtc library functions.
2
// @package    tinymce_recordrtc.
3
// @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com).
4
// @copyright  2016 to present, Blindside Networks Inc.
5
// @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
6
7
/** global: M */
8
/** global: URL */
9
/** global: params */
10
/** global: initialized variables */
11
12
M.tinymce_recordrtc = M.tinymce_recordrtc || {};
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13
14
// Extract plugin settings to params hash.
15
(function() {
16
    var params = {};
17
    var r = /([^&=]+)=?([^&]*)/g;
18
19
    var d = function(s) {
20
        return decodeURIComponent(s.replace(/\+/g, ' '));
21
    };
22
23
    var search = window.location.search;
24
    var match = r.exec(search.substring(1));
25
    while (match) {
26
        params[d(match[1])] = d(match[2]);
27
28
        if (d(match[2]) === 'true' || d(match[2]) === 'false') {
29
            params[d(match[1])] = d(match[2]) === 'true' ? true : false;
30
        }
31
        match = r.exec(search.substring(1));
32
    }
33
34
    window.params = params;
35
})();
36
37
// Initialize some variables.
38
var player = null;
39
var startStopBtn = null;
40
var uploadBtn = null;
41
var countdownSeconds = null;
42
var countdownTicker = null;
43
var mediaRecorder = null;
44
var chunks = null;
45
46
/**
47
 * This function is initialized from PHP
48
 *
49
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
50
 *            Y YUI instance
51
 */
52
M.tinymce_recordrtc.view_init = function() {
53
    // Assignment of global variables.
54
    player = document.querySelector('video#player');
55
    startStopBtn = document.querySelector('button#start-stop');
56
    uploadBtn = document.querySelector('button#upload');
57
58
    // Show alert if using non-ideal browser.
59
    M.tinymce_recordrtc.check_browser();
60
61
    // Run when user clicks on "record" button.
62
    startStopBtn.onclick = function() {
63
        var btn = this;
64
        btn.disabled = true;
65
66
        // If button is displaying "Start Recording" or "Record Again".
67
        if ((btn.textContent === M.util.get_string('startrecording', 'tinymce_recordrtc')) ||
68
            (btn.textContent === M.util.get_string('recordagain', 'tinymce_recordrtc')) ||
69
            (btn.textContent === M.util.get_string('recordingfailed', 'tinymce_recordrtc'))) {
70
            // Hide alert-danger if it is shown.
71
            var alert = document.querySelector('div[id=alert-danger]');
72
            alert.parentElement.parentElement.classList.add('hide');
73
74
            // Make sure the upload button is not shown.
75
            uploadBtn.parentElement.parentElement.classList.add('hide');
76
77
            // Change look of recording button.
78
            startStopBtn.classList.remove('btn-outline-danger');
79
            startStopBtn.classList.add('btn-danger');
80
81
            // Empty the array containing the previously recorded chunks.
82
            chunks = [];
83
84
            // Initialize common configurations.
85
            var commonConfig = {
86
                // When the stream is captured from the microphone/webcam.
87
                onMediaCaptured: function(stream) {
88
                    // Make video stream available at a higher level by making it a property of btn.
89
                    btn.stream = stream;
90
91
                    if (btn.mediaCapturedCallback) {
92
                        btn.mediaCapturedCallback();
93
                    }
94
                },
95
96
                // Revert button to "Record Again" when recording is stopped.
97
                onMediaStopped: function(btnLabel) {
98
                    btn.textContent = btnLabel;
99
                },
100
101
                // Handle recording errors.
102
                onMediaCapturingFailed: function(error) {
103
                    var btnLabel = null;
104
105
                    // If Firefox and Permission Denied error.
106
                    if ((error.name === 'PermissionDeniedError') && bowser.firefox) {
0 ignored issues
show
Bug introduced by
The variable bowser seems to be never declared. If this is a global, consider adding a /** global: bowser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
107
                        InstallTrigger.install({
0 ignored issues
show
Bug introduced by
The variable InstallTrigger seems to be never declared. If this is a global, consider adding a /** global: InstallTrigger */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
108
                            'Foo': {
109
                                // Link: https://addons.mozilla.org/firefox/downloads/latest/655146/addon-655146...
110
                                // ...-latest.xpi?src=dp-btn-primary.
111
                                URL: 'https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/',
112
                                toString: function() {
113
                                    return this.URL;
114
                                }
115
                            }
116
                        });
117
118
                        btnLabel = M.util.get_string('startrecording', 'tinymce_recordrtc');
119
                    } else if ((error.name === 'DevicesNotFoundError') ||
120
                               (error.name === 'NotFoundError')) { // If Device Not Found error.
121
                        var alert = document.querySelector('div[id=alert-danger]');
122
                        alert.parentElement.parentElement.classList.remove('hide');
123
                        alert.textContent = M.util.get_string('inputdevicealert', 'tinymce_recordrtc') + ' ' + M.util.get_string('inputdevicealert', 'tinymce_recordrtc');
124
125
                        btnLabel = M.util.get_string('recordingfailed', 'tinymce_recordrtc');
126
                    }
127
128
                    // Proceed to treat as a stopped recording.
129
                    commonConfig.onMediaStopped(btnLabel);
130
                }
131
            };
132
133
            // Show video tag without controls to view webcam stream.
134
            player.parentElement.parentElement.classList.remove('hide');
135
            player.controls = false;
136
137
            // Capture audio+video stream from webcam/microphone.
138
            M.tinymce_recordrtc.captureAudioVideo(commonConfig);
139
140
            // When audio+video stream is successfully captured, start recording.
141
            btn.mediaCapturedCallback = function() {
142
                M.tinymce_recordrtc.startRecording(btn.stream);
143
            };
144
145
            return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
146
        } else { // If button is displaying "Stop Recording".
147
            // First of all clears the countdownTicker.
148
            clearInterval(countdownTicker);
149
150
            // Disable "Record Again" button for 1s to allow background processing (closing streams).
151
            setTimeout(function() {
152
                btn.disabled = false;
153
            }, 1000);
154
155
            // Stop recording.
156
            M.tinymce_recordrtc.stopRecording(btn.stream);
157
158
            // Change button to offer to record again.
159
            btn.textContent = M.util.get_string('recordagain', 'tinymce_recordrtc');
160
            startStopBtn.classList.remove('btn-danger');
161
            startStopBtn.classList.add('btn-outline-danger');
162
163
            return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
164
        }
165
    };
166
};
167
168
/////////////////////////
169
// Functions for capturing, recording, and uploading stream.
170
/////////////////////////
171
172
// Setup to get audio+video stream from microphone/webcam.
173
M.tinymce_recordrtc.captureAudioVideo = function(config) {
174
    M.tinymce_recordrtc.captureUserMedia(
175
        // Media constraints.
176
        {
177
            audio: true,
178
            video: {
179
              width: {ideal: 640},
180
              height: {ideal: 480}
181
            }
182
        },
183
184
        // Success callback.
185
        function(audioVideoStream) {
186
            console.log('getUserMedia() got stream:', audioVideoStream);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
187
188
            // Set video player to play microphone+webcam stream.
189
            player.srcObject = audioVideoStream;
190
            player.play();
191
192
            config.onMediaCaptured(audioVideoStream);
193
        },
194
195
        // Error callback.
196
        function(error) {
197
            console.log('getUserMedia() error:', error);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
198
            config.onMediaCapturingFailed(error);
199
        }
200
    );
201
};
202
203
M.tinymce_recordrtc.stopRecording = function(stream) {
204
    mediaRecorder.stop();
205
206
    stream.getTracks().forEach(function(track) {
207
        track.stop();
208
        console.log('MediaTrack stopped:', track);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
209
    });
210
211
    // Set source of video player, then show it with controls enabled.
212
    var blob = new Blob(chunks, {
0 ignored issues
show
Bug introduced by
The variable Blob seems to be never declared. If this is a global, consider adding a /** global: Blob */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
213
        type: 'video/webm;codecs=vp8'
214
    });
215
    player.src = URL.createObjectURL(blob);
216
217
    player.muted = false;
218
    player.controls = true;
219
    player.play();
220
221
    player.onended = function() {
222
        player.pause();
223
    };
224
225
    // Show upload button.
226
    uploadBtn.parentElement.parentElement.classList.remove('hide');
227
    uploadBtn.textContent = M.util.get_string('attachrecording', 'tinymce_recordrtc');
228
    uploadBtn.disabled = false;
229
230
    // Handle when upload button is clicked.
231
    uploadBtn.onclick = function() {
232
        // Trigger error if no recording has been made.
233
        if (!player.src || chunks === []) {
234
            return alert(M.util.get_string('norecordingfound', 'tinymce_recordrtc'));
235
        }
236
237
        var btn = uploadBtn;
238
        btn.disabled = true;
239
240
        // Upload recording to server.
241
        M.tinymce_recordrtc.uploadToServer('video', function(progress, fileURL) {
242
            if (progress === 'ended') {
243
                btn.disabled = false;
244
                M.tinymce_recordrtc.insert_annotation(fileURL);
245
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
246
            } else if (progress === 'upload-failed') {
247
                btn.disabled = false;
248
                btn.textContent = M.util.get_string('uploadfailed', 'tinymce_recordrtc');
249
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
250
            } else {
251
                btn.textContent = progress;
252
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
253
            }
254
        });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
255
    };
256
};
257