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/audiomodule.js   A

Complexity

Total Complexity 34
Complexity/F 1.89

Size

Lines of Code 239
Function Count 18

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
c 3
b 0
f 0
nc 192
dl 0
loc 239
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  
B 0 21 5
A audiomodule.js ➔ d 0 3 1
A M.tinymce_recordrtc.stopRecording 0 55 1
B M.tinymce_recordrtc.captureAudio 0 25 1
B M.tinymce_recordrtc.view_init 0 112 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('audio#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 audio player and upload button is not shown.
75
            player.parentElement.parentElement.classList.add('hide');
76
            uploadBtn.parentElement.parentElement.classList.add('hide');
77
78
            // Change look of recording button.
79
            startStopBtn.classList.remove('btn-outline-danger');
80
            startStopBtn.classList.add('btn-danger');
81
82
            // Empty the array containing the previously recorded chunks.
83
            chunks = [];
84
85
            // Initialize common configurations.
86
            var commonConfig = {
87
                // When the stream is captured from the microphone/webcam.
88
                onMediaCaptured: function(stream) {
89
                    // Make audio stream available at a higher level by making it a property of btn.
90
                    btn.stream = stream;
91
92
                    if (btn.mediaCapturedCallback) {
93
                        btn.mediaCapturedCallback();
94
                    }
95
                },
96
97
                // Revert button to "Record Again" when recording is stopped.
98
                onMediaStopped: function(btnLabel) {
99
                    btn.textContent = btnLabel;
100
                },
101
102
                // Handle recording errors.
103
                onMediaCapturingFailed: function(error) {
104
                    var btnLabel = null;
105
106
                    // If Firefox and Permission Denied error.
107
                    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...
108
                        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...
109
                            'Foo': {
110
                                // Link: https://addons.mozilla.org/firefox/downloads/latest/655146/addon-655146...
111
                                // ...-latest.xpi?src=dp-btn-primary.
112
                                URL: 'https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/',
113
                                toString: function() {
114
                                    return this.URL;
115
                                }
116
                            }
117
                        });
118
119
                        btnLabel = M.util.get_string('startrecording', 'tinymce_recordrtc');
120
                    } else if ((error.name === 'DevicesNotFoundError') ||
121
                               (error.name === 'NotFoundError')) { // If Device Not Found error.
122
                        var alert = document.querySelector('div[id=alert-danger]');
123
                        alert.parentElement.parentElement.classList.remove('hide');
124
                        alert.textContent = M.util.get_string('inputdevicealert_title', 'tinymce_recordrtc') + ' ' + M.util.get_string('inputdevicealert', 'tinymce_recordrtc');
125
126
                        btnLabel = M.util.get_string('recordingfailed', 'tinymce_recordrtc');
127
                    }
128
129
                    // Proceed to treat as a stopped recording.
130
                    commonConfig.onMediaStopped(btnLabel);
131
                }
132
            };
133
134
            // Capture audio stream from microphone.
135
            M.tinymce_recordrtc.captureAudio(commonConfig);
136
137
            // When audio stream is successfully captured, start recording.
138
            btn.mediaCapturedCallback = function() {
139
                M.tinymce_recordrtc.startRecording(btn.stream);
140
            };
141
142
            return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
143
        } else { // If button is displaying "Stop Recording".
144
            // First of all clears the countdownTicker.
145
            clearInterval(countdownTicker);
146
147
            // Disable "Record Again" button for 1s to allow background processing (closing streams).
148
            setTimeout(function() {
149
                btn.disabled = false;
150
            }, 1000);
151
152
            // Stop recording.
153
            M.tinymce_recordrtc.stopRecording(btn.stream);
154
155
            // Change button to offer to record again.
156
            btn.textContent = M.util.get_string('recordagain', 'tinymce_recordrtc');
157
            startStopBtn.classList.remove('btn-danger');
158
            startStopBtn.classList.add('btn-outline-danger');
159
160
            return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
161
        }
162
    };
163
};
164
165
/////////////////////////
166
// Functions for capturing, recording, and uploading stream.
167
/////////////////////////
168
169
// Setup to get audio stream from microphone.
170
M.tinymce_recordrtc.captureAudio = function(config) {
171
    M.tinymce_recordrtc.captureUserMedia(
172
        // Media constraints.
173
        {
174
            audio: true
175
        },
176
177
        // Success callback.
178
        function(audioStream) {
179
            console.log('getUserMedia() got stream:', audioStream);
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...
180
181
            // Set audio player to play microphone stream.
182
            player.srcObject = audioStream;
183
            player.play();
184
185
            config.onMediaCaptured(audioStream);
186
        },
187
188
        // Error callback.
189
        function(error) {
190
            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...
191
            config.onMediaCapturingFailed(error);
192
        }
193
    );
194
};
195
196
M.tinymce_recordrtc.stopRecording = function(stream) {
197
    mediaRecorder.stop();
198
199
    stream.getTracks().forEach(function(track) {
200
        track.stop();
201
        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...
202
    });
203
204
    // Set source of audio player, then show it with controls enabled.
205
    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...
206
        type: 'audio/ogg;codecs=opus'
207
    });
208
    player.src = URL.createObjectURL(blob);
209
210
    player.muted = false;
211
    player.controls = true;
212
    player.parentElement.parentElement.classList.remove('hide');
213
    player.play();
214
215
    player.onended = function() {
216
        player.pause();
217
    };
218
219
    // Show upload button.
220
    uploadBtn.parentElement.parentElement.classList.remove('hide');
221
    uploadBtn.textContent = M.util.get_string('attachrecording', 'tinymce_recordrtc');
222
    uploadBtn.disabled = false;
223
224
    // Handle when upload button is clicked.
225
    uploadBtn.onclick = function() {
226
        // Trigger error if no recording has been made.
227
        if (!player.src || chunks === []) {
228
            return alert(M.util.get_string('norecordingfound', 'tinymce_recordrtc'));
229
        }
230
231
        var btn = uploadBtn;
232
        btn.disabled = true;
233
234
        // Upload recording to server.
235
        M.tinymce_recordrtc.uploadToServer('audio', function(progress, fileURL) {
236
            if (progress === 'ended') {
237
                btn.disabled = false;
238
                M.tinymce_recordrtc.insert_annotation(fileURL);
239
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
240
            } else if (progress === 'upload-failed') {
241
                btn.disabled = false;
242
                btn.textContent = M.util.get_string('uploadfailed', 'tinymce_recordrtc');
243
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
244
            } else {
245
                btn.textContent = progress;
246
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
247
            }
248
        });
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...
249
    };
250
};
251