Skip to content

Commit 416bd29

Browse files
committed
Fixed issue #4
1 parent c6748de commit 416bd29

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

recordrtc.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function get_output() {
5555
$out = '<div class="container-fluid">'."\n";
5656
$out = ' <div class="row">'."\n";
5757
$out = ' <div class="col-md-16">'."\n";
58-
$out .= ' <div id="alert" class="alert h5 hide">Use Firefox for best experience</div>'."\n";
58+
$out .= ' <div id="alert-info" class="alert alert-info h5 hide">Use Firefox for best experience</div>'."\n";
59+
$out .= ' <div id="alert-danger" class="alert alert-danger h5 hide"></div>'."\n";
5960
$out .= ' <div class="recordrtc">'."\n";
6061
$out .= ' <div class="header">'."\n";
6162
$out .= ' <select class="recording-media" style="display:none">'."\n";
@@ -89,4 +90,4 @@ function get_output() {
8990
$out .= '</script>'."\n";
9091

9192
return $out;
92-
}
93+
}

tinymce/js/module.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ M.tinymce_recordrtc.view_init = function(Y) {
5858
var button = this;
5959
button.disabled = true;
6060

61-
if ( button.innerHTML === 'Start Recording' || button.innerHTML === 'Record Again' ) {
61+
if ( button.innerHTML.indexOf('Start Recording') >= 0 || button.innerHTML.indexOf('Record Again') >= 0 ) {
62+
// Hide alert-danger if shown
63+
var alert = document.querySelector('div[id=alert-danger]');
64+
alert.innerHTML == "";
65+
alert.classList.add('hide');
66+
// Make sure the upload button is not shown
67+
recordingDIV.querySelector('#upload-to-server').parentNode.style.display = 'none';
6268
// Hide current audio, if any
6369
var selected = recordingDIV.querySelectorAll('audio.selected');
6470
if ( selected.length > 0 ) {
6571
selected[0].classList.remove('selected');
6672
selected[0].classList.add('hide');
6773
}
68-
// Make sure the upload button is not shown
69-
recordingDIV.querySelector('#upload-to-server').parentNode.style.display = 'none';
7074

7175
var commonConfig = {
7276
onMediaCaptured: function(stream) {
@@ -81,14 +85,15 @@ M.tinymce_recordrtc.view_init = function(Y) {
8185
countdownSeconds = 120;
8286
countdownTicker = setInterval(M.tinymce_recordrtc.setTime, 1000);
8387
},
84-
onMediaStopped: function() {
85-
button.innerHTML = 'Start Recording';
88+
onMediaStopped: function(btnLabel) {
89+
button.innerHTML = btnLabel;
8690

8791
if (!button.disableStateWaiting) {
8892
button.disabled = false;
8993
}
9094
},
9195
onMediaCapturingFailed: function(error) {
96+
var btnLabel = 'Start Recording';
9297
if (error.name === 'PermissionDeniedError' && !!navigator.mozGetUserMedia) {
9398
InstallTrigger.install({
9499
'Foo': {
@@ -99,9 +104,22 @@ M.tinymce_recordrtc.view_init = function(Y) {
99104
}
100105
}
101106
});
107+
} else if (error.name === 'DevicesNotFoundError') {
108+
// Show alert
109+
var alert = document.querySelector('div[id=alert-danger]');
110+
alert.classList.remove('hide');
111+
alert.innerHTML = "There is no input device enabled";
112+
// Update button
113+
if ( button.innerHTML.indexOf('Start Recording') >= 0 ) {
114+
btnLabel = 'Start Recording failed, try again';
115+
} else {
116+
btnLabel = 'Record Again failed, try once more';
117+
}
118+
// Send alert to the development console
119+
console.info(alert.innerHTML);
102120
}
103121

104-
commonConfig.onMediaStopped();
122+
commonConfig.onMediaStopped(btnLabel);
105123
}
106124
};
107125

@@ -206,9 +224,8 @@ M.tinymce_recordrtc.view_init = function(Y) {
206224

207225
//// Initialization for recordingMedia
208226
if ( webrtcDetectedBrowser !== 'firefox' ) {
209-
var alert = document.querySelector('div[id=alert]');
227+
var alert = document.querySelector('div[id=alert-info]');
210228
alert.innerHTML == "Use Firefox for best experience";
211-
alert.classList.add('alert-danger');
212229
alert.classList.remove('hide');
213230
}
214231
if (webrtcDetectedBrowser === 'edge') {
@@ -235,11 +252,12 @@ M.tinymce_recordrtc.captureAudio = function(config) {
235252
config.onMediaCaptured(audioStream);
236253

237254
audioStream.onended = function() {
238-
config.onMediaStopped();
255+
config.onMediaStopped('Start Recording');
239256
};
240257
},
241258
// error callback
242259
function(error) {
260+
console.info("MediaCapturingFailed: " + error.name);
243261
config.onMediaCapturingFailed(error);
244262
}
245263
);

0 commit comments

Comments
 (0)