2016-03-29 18:10:31 +00:00
|
|
|
/* global APP, $, config, interfaceConfig */
|
|
|
|
/*
|
|
|
|
* Copyright @ 2015 Atlassian Pty Ltd
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
import UIEvents from "../../../service/UI/UIEvents";
|
|
|
|
import UIUtil from '../util/UIUtil';
|
|
|
|
|
|
|
|
/**
|
2016-03-29 22:26:39 +00:00
|
|
|
* Indicates if the recording button should be enabled.
|
|
|
|
*
|
|
|
|
* @returns {boolean} {true} if the
|
|
|
|
* @private
|
2016-03-29 18:10:31 +00:00
|
|
|
*/
|
|
|
|
function _isRecordingButtonEnabled() {
|
|
|
|
return interfaceConfig.TOOLBAR_BUTTONS.indexOf("recording") !== -1
|
|
|
|
&& config.enableRecording;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request live stream token from the user.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
function _requestLiveStreamId() {
|
2016-03-29 21:07:01 +00:00
|
|
|
const msg = APP.translation.generateTranslationHTML("dialog.liveStreaming");
|
|
|
|
const token = APP.translation.translateString("dialog.streamKey");
|
|
|
|
const cancelButton
|
|
|
|
= APP.translation.generateTranslationHTML("dialog.Cancel");
|
|
|
|
const backButton = APP.translation.generateTranslationHTML("dialog.Back");
|
|
|
|
const startStreamingButton
|
|
|
|
= APP.translation.generateTranslationHTML("dialog.startLiveStreaming");
|
|
|
|
const streamIdRequired
|
|
|
|
= APP.translation.generateTranslationHTML(
|
|
|
|
"liveStreaming.streamIdRequired");
|
|
|
|
|
2016-03-29 18:10:31 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
2016-03-29 21:07:01 +00:00
|
|
|
let dialog = APP.UI.messageHandler.openDialogWithStates({
|
|
|
|
state0: {
|
|
|
|
html:
|
|
|
|
`<h2>${msg}</h2>
|
|
|
|
<input name="streamId" type="text"
|
2016-03-29 18:10:31 +00:00
|
|
|
data-i18n="[placeholder]dialog.streamKey"
|
|
|
|
placeholder="${token}" autofocus>`,
|
2016-03-29 21:07:01 +00:00
|
|
|
persistent: false,
|
|
|
|
buttons: [
|
|
|
|
{title: cancelButton, value: false},
|
|
|
|
{title: startStreamingButton, value: true}
|
|
|
|
],
|
|
|
|
focus: ':input:first',
|
|
|
|
defaultButton: 1,
|
|
|
|
submit: function (e, v, m, f) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
if (f.streamId && f.streamId.length > 0) {
|
|
|
|
resolve(UIUtil.escapeHtml(f.streamId));
|
|
|
|
dialog.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dialog.goToState('state1');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
dialog.close();
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-29 18:10:31 +00:00
|
|
|
}
|
|
|
|
},
|
2016-03-29 21:07:01 +00:00
|
|
|
|
|
|
|
state1: {
|
|
|
|
html: `<h2>${msg}</h2> ${streamIdRequired}`,
|
|
|
|
persistent: false,
|
|
|
|
buttons: [
|
|
|
|
{title: cancelButton, value: false},
|
|
|
|
{title: backButton, value: true}
|
|
|
|
],
|
|
|
|
focus: ':input:first',
|
|
|
|
defaultButton: 1,
|
|
|
|
submit: function (e, v, m, f) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (v === 0) {
|
|
|
|
reject();
|
|
|
|
dialog.close();
|
|
|
|
} else {
|
|
|
|
dialog.goToState('state0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-29 18:10:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request recording token from the user.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
function _requestRecordingToken () {
|
|
|
|
let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
|
|
|
|
let token = APP.translation.translateString("dialog.token");
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
APP.UI.messageHandler.openTwoButtonDialog(
|
|
|
|
null, null, null,
|
|
|
|
`<h2>${msg}</h2>
|
|
|
|
<input name="recordingToken" type="text"
|
|
|
|
data-i18n="[placeholder]dialog.token"
|
|
|
|
placeholder="${token}" autofocus>`,
|
|
|
|
false, "dialog.Save",
|
|
|
|
function (e, v, m, f) {
|
|
|
|
if (v && f.recordingToken) {
|
|
|
|
resolve(UIUtil.escapeHtml(f.recordingToken));
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
function () { },
|
|
|
|
':input:first'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function _showStopRecordingPrompt (recordingType) {
|
|
|
|
var title;
|
|
|
|
var message;
|
|
|
|
var buttonKey;
|
|
|
|
if (recordingType === "jibri") {
|
|
|
|
title = "dialog.liveStreaming";
|
|
|
|
message = "dialog.stopStreamingWarning";
|
|
|
|
buttonKey = "dialog.stopLiveStreaming";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
title = "dialog.recording";
|
|
|
|
message = "dialog.stopRecordingWarning";
|
|
|
|
buttonKey = "dialog.stopRecording";
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
APP.UI.messageHandler.openTwoButtonDialog(
|
|
|
|
title,
|
|
|
|
null,
|
|
|
|
message,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
buttonKey,
|
|
|
|
function(e,v,m,f) {
|
|
|
|
if (v) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveToCorner(selector, move) {
|
|
|
|
let moveToCornerClass = "moveToCorner";
|
|
|
|
|
|
|
|
if (move && !selector.hasClass(moveToCornerClass))
|
|
|
|
selector.addClass(moveToCornerClass);
|
|
|
|
else
|
|
|
|
selector.removeClass(moveToCornerClass);
|
|
|
|
}
|
|
|
|
|
2016-03-29 21:07:01 +00:00
|
|
|
var Status = {
|
|
|
|
ON: "on",
|
|
|
|
OFF: "off",
|
|
|
|
AVAILABLE: "available",
|
|
|
|
UNAVAILABLE: "unavailable",
|
|
|
|
PENDING: "pending"
|
2016-03-29 21:30:08 +00:00
|
|
|
};
|
2016-03-29 21:07:01 +00:00
|
|
|
|
2016-03-29 18:10:31 +00:00
|
|
|
var Recording = {
|
|
|
|
/**
|
|
|
|
* Initializes the recording UI.
|
|
|
|
*/
|
|
|
|
init (emitter, recordingType) {
|
|
|
|
this.eventEmitter = emitter;
|
2016-03-29 21:07:01 +00:00
|
|
|
// Use recorder states directly from the library.
|
|
|
|
this.currentState = Status.UNAVAILABLE;
|
2016-03-29 18:10:31 +00:00
|
|
|
|
|
|
|
this.initRecordingButton(recordingType);
|
|
|
|
},
|
|
|
|
|
|
|
|
initRecordingButton(recordingType) {
|
|
|
|
let selector = $('#toolbar_button_record');
|
|
|
|
|
|
|
|
if (recordingType === 'jibri') {
|
|
|
|
this.baseClass = "fa fa-play-circle";
|
|
|
|
this.recordingOnKey = "liveStreaming.on";
|
|
|
|
this.recordingOffKey = "liveStreaming.off";
|
|
|
|
this.recordingPendingKey = "liveStreaming.pending";
|
|
|
|
this.failedToStartKey = "liveStreaming.failedToStart";
|
2016-03-29 21:07:01 +00:00
|
|
|
this.recordingButtonTooltip = "liveStreaming.buttonTooltip";
|
2016-03-29 18:10:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.baseClass = "icon-recEnable";
|
|
|
|
this.recordingOnKey = "recording.on";
|
|
|
|
this.recordingOffKey = "recording.off";
|
|
|
|
this.recordingPendingKey = "recording.pending";
|
|
|
|
this.failedToStartKey = "recording.failedToStart";
|
2016-03-29 21:07:01 +00:00
|
|
|
this.recordingButtonTooltip = "recording.buttonTooltip";
|
2016-03-29 18:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selector.addClass(this.baseClass);
|
2016-03-29 21:07:01 +00:00
|
|
|
selector.attr("data-i18n", "[content]" + this.recordingButtonTooltip);
|
|
|
|
selector.attr("content",
|
|
|
|
APP.translation.translateString(this.recordingButtonTooltip));
|
2016-03-29 18:10:31 +00:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
selector.click(function () {
|
|
|
|
switch (self.currentState) {
|
2016-03-29 21:07:01 +00:00
|
|
|
case Status.ON:
|
|
|
|
case Status.PENDING: {
|
2016-03-29 18:10:31 +00:00
|
|
|
_showStopRecordingPrompt(recordingType).then(() =>
|
|
|
|
self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED));
|
|
|
|
break;
|
2016-03-29 21:07:01 +00:00
|
|
|
}
|
|
|
|
case Status.AVAILABLE:
|
|
|
|
case Status.OFF: {
|
2016-03-29 18:10:31 +00:00
|
|
|
if (recordingType === 'jibri')
|
|
|
|
_requestLiveStreamId().then((streamId) => {
|
|
|
|
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
|
{streamId: streamId});
|
|
|
|
});
|
|
|
|
else {
|
|
|
|
if (self.predefinedToken) {
|
|
|
|
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
|
{token: self.predefinedToken});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_requestRecordingToken().then((token) => {
|
|
|
|
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
|
{token: token});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2016-03-29 21:07:01 +00:00
|
|
|
}
|
2016-03-29 18:10:31 +00:00
|
|
|
default: {
|
|
|
|
APP.UI.messageHandler.openMessageDialog(
|
|
|
|
"dialog.liveStreaming",
|
|
|
|
"liveStreaming.unavailable"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Shows or hides the 'recording' button.
|
|
|
|
showRecordingButton (show) {
|
|
|
|
if (_isRecordingButtonEnabled() && show) {
|
|
|
|
$('#toolbar_button_record').css({display: "inline-block"});
|
|
|
|
} else {
|
|
|
|
$('#toolbar_button_record').css({display: "none"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRecordingState(recordingState) {
|
2016-03-29 22:26:39 +00:00
|
|
|
// I'm the recorder, so I don't want to see any UI related to states.
|
|
|
|
if (config.iAmRecorder)
|
|
|
|
return;
|
|
|
|
|
2016-03-29 18:46:10 +00:00
|
|
|
// If there's no state change, we ignore the update.
|
|
|
|
if (this.currentState === recordingState)
|
|
|
|
return;
|
|
|
|
|
2016-03-29 18:10:31 +00:00
|
|
|
this.setRecordingButtonState(recordingState);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sets the state of the recording button
|
|
|
|
setRecordingButtonState (recordingState) {
|
|
|
|
let buttonSelector = $('#toolbar_button_record');
|
|
|
|
let labelSelector = $('#recordingLabel');
|
|
|
|
|
|
|
|
// TODO: handle recording state=available
|
2016-03-29 21:07:01 +00:00
|
|
|
if (recordingState === Status.ON) {
|
2016-03-29 18:10:31 +00:00
|
|
|
|
|
|
|
buttonSelector.removeClass(this.baseClass);
|
|
|
|
buttonSelector.addClass(this.baseClass + " active");
|
|
|
|
|
|
|
|
labelSelector.attr("data-i18n", this.recordingOnKey);
|
|
|
|
moveToCorner(labelSelector, true, 3000);
|
|
|
|
labelSelector
|
|
|
|
.text(APP.translation.translateString(this.recordingOnKey));
|
2016-03-29 21:07:01 +00:00
|
|
|
} else if (recordingState === Status.OFF
|
|
|
|
|| recordingState === Status.UNAVAILABLE) {
|
2016-03-29 18:46:10 +00:00
|
|
|
|
|
|
|
// We don't want to do any changes if this is
|
|
|
|
// an availability change.
|
2016-03-29 21:30:08 +00:00
|
|
|
if (this.currentState !== Status.ON
|
|
|
|
&& this.currentState !== Status.PENDING)
|
2016-03-29 18:46:10 +00:00
|
|
|
return;
|
2016-03-29 18:10:31 +00:00
|
|
|
|
|
|
|
buttonSelector.removeClass(this.baseClass + " active");
|
|
|
|
buttonSelector.addClass(this.baseClass);
|
|
|
|
|
|
|
|
moveToCorner(labelSelector, false);
|
|
|
|
let messageKey;
|
2016-03-29 21:07:01 +00:00
|
|
|
if (this.currentState === Status.PENDING)
|
2016-03-29 18:10:31 +00:00
|
|
|
messageKey = this.failedToStartKey;
|
|
|
|
else
|
|
|
|
messageKey = this.recordingOffKey;
|
|
|
|
|
|
|
|
labelSelector.attr("data-i18n", messageKey);
|
|
|
|
labelSelector.text(APP.translation.translateString(messageKey));
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
$('#recordingLabel').css({display: "none"});
|
|
|
|
}, 5000);
|
2016-03-29 18:46:10 +00:00
|
|
|
}
|
2016-03-29 21:07:01 +00:00
|
|
|
else if (recordingState === Status.PENDING) {
|
2016-03-29 18:10:31 +00:00
|
|
|
|
|
|
|
buttonSelector.removeClass(this.baseClass + " active");
|
|
|
|
buttonSelector.addClass(this.baseClass);
|
|
|
|
|
|
|
|
moveToCorner(labelSelector, false);
|
|
|
|
labelSelector
|
|
|
|
.attr("data-i18n", this.recordingPendingKey);
|
|
|
|
labelSelector
|
|
|
|
.text(APP.translation.translateString(
|
|
|
|
this.recordingPendingKey));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentState = recordingState;
|
|
|
|
|
2016-03-29 21:30:08 +00:00
|
|
|
// We don't show the label for available state.
|
|
|
|
if (recordingState !== Status.AVAILABLE
|
|
|
|
&& !labelSelector.is(":visible"))
|
2016-03-29 18:10:31 +00:00
|
|
|
labelSelector.css({display: "inline-block"});
|
|
|
|
},
|
|
|
|
// checks whether recording is enabled and whether we have params
|
|
|
|
// to start automatically recording
|
|
|
|
checkAutoRecord () {
|
|
|
|
if (_isRecordingButtonEnabled && config.autoRecord) {
|
|
|
|
this.predefinedToken = UIUtil.escapeHtml(config.autoRecordToken);
|
|
|
|
this.eventEmitter.emit(UIEvents.RECORDING_TOGGLED,
|
|
|
|
this.predefinedToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Recording;
|