|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+/* global APP, $, config, interfaceConfig */
|
|
|
2
|
+/*
|
|
|
3
|
+ * Copyright @ 2015 Atlassian Pty Ltd
|
|
|
4
|
+ *
|
|
|
5
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
6
|
+ * you may not use this file except in compliance with the License.
|
|
|
7
|
+ * You may obtain a copy of the License at
|
|
|
8
|
+ *
|
|
|
9
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
10
|
+ *
|
|
|
11
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
12
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
13
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
14
|
+ * See the License for the specific language governing permissions and
|
|
|
15
|
+ * limitations under the License.
|
|
|
16
|
+ */
|
|
|
17
|
+import UIEvents from "../../../service/UI/UIEvents";
|
|
|
18
|
+import UIUtil from '../util/UIUtil';
|
|
|
19
|
+
|
|
|
20
|
+/**
|
|
|
21
|
+ * Recording.
|
|
|
22
|
+ */
|
|
|
23
|
+let recordingToaster = null;
|
|
|
24
|
+
|
|
|
25
|
+function _isRecordingButtonEnabled() {
|
|
|
26
|
+ return interfaceConfig.TOOLBAR_BUTTONS.indexOf("recording") !== -1
|
|
|
27
|
+ && config.enableRecording;
|
|
|
28
|
+}
|
|
|
29
|
+
|
|
|
30
|
+/**
|
|
|
31
|
+ * Request live stream token from the user.
|
|
|
32
|
+ * @returns {Promise}
|
|
|
33
|
+ */
|
|
|
34
|
+function _requestLiveStreamId() {
|
|
|
35
|
+ let msg = APP.translation.generateTranslationHTML("dialog.liveStreaming");
|
|
|
36
|
+ let token = APP.translation.translateString("dialog.streamKey");
|
|
|
37
|
+ return new Promise(function (resolve, reject) {
|
|
|
38
|
+ APP.UI.messageHandler.openTwoButtonDialog(
|
|
|
39
|
+ null, null, null,
|
|
|
40
|
+ `<h2>${msg}</h2>
|
|
|
41
|
+ <input name="streamId" type="text"
|
|
|
42
|
+ data-i18n="[placeholder]dialog.streamKey"
|
|
|
43
|
+ placeholder="${token}" autofocus>`,
|
|
|
44
|
+ false, "dialog.startLiveStreaming",
|
|
|
45
|
+ function (e, v, m, f) {
|
|
|
46
|
+ if (v && f.streamId) {
|
|
|
47
|
+ resolve(UIUtil.escapeHtml(f.streamId));
|
|
|
48
|
+ } else {
|
|
|
49
|
+ reject();
|
|
|
50
|
+ }
|
|
|
51
|
+ },
|
|
|
52
|
+ null,
|
|
|
53
|
+ function () { },
|
|
|
54
|
+ ':input:first'
|
|
|
55
|
+ );
|
|
|
56
|
+ });
|
|
|
57
|
+}
|
|
|
58
|
+
|
|
|
59
|
+/**
|
|
|
60
|
+ * Request recording token from the user.
|
|
|
61
|
+ * @returns {Promise}
|
|
|
62
|
+ */
|
|
|
63
|
+function _requestRecordingToken () {
|
|
|
64
|
+ let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
|
|
|
65
|
+ let token = APP.translation.translateString("dialog.token");
|
|
|
66
|
+
|
|
|
67
|
+ return new Promise(function (resolve, reject) {
|
|
|
68
|
+ APP.UI.messageHandler.openTwoButtonDialog(
|
|
|
69
|
+ null, null, null,
|
|
|
70
|
+ `<h2>${msg}</h2>
|
|
|
71
|
+ <input name="recordingToken" type="text"
|
|
|
72
|
+ data-i18n="[placeholder]dialog.token"
|
|
|
73
|
+ placeholder="${token}" autofocus>`,
|
|
|
74
|
+ false, "dialog.Save",
|
|
|
75
|
+ function (e, v, m, f) {
|
|
|
76
|
+ if (v && f.recordingToken) {
|
|
|
77
|
+ resolve(UIUtil.escapeHtml(f.recordingToken));
|
|
|
78
|
+ } else {
|
|
|
79
|
+ reject();
|
|
|
80
|
+ }
|
|
|
81
|
+ },
|
|
|
82
|
+ null,
|
|
|
83
|
+ function () { },
|
|
|
84
|
+ ':input:first'
|
|
|
85
|
+ );
|
|
|
86
|
+ });
|
|
|
87
|
+}
|
|
|
88
|
+
|
|
|
89
|
+function _showStopRecordingPrompt (recordingType) {
|
|
|
90
|
+ var title;
|
|
|
91
|
+ var message;
|
|
|
92
|
+ var buttonKey;
|
|
|
93
|
+ if (recordingType === "jibri") {
|
|
|
94
|
+ title = "dialog.liveStreaming";
|
|
|
95
|
+ message = "dialog.stopStreamingWarning";
|
|
|
96
|
+ buttonKey = "dialog.stopLiveStreaming";
|
|
|
97
|
+ }
|
|
|
98
|
+ else {
|
|
|
99
|
+ title = "dialog.recording";
|
|
|
100
|
+ message = "dialog.stopRecordingWarning";
|
|
|
101
|
+ buttonKey = "dialog.stopRecording";
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ return new Promise(function (resolve, reject) {
|
|
|
105
|
+ APP.UI.messageHandler.openTwoButtonDialog(
|
|
|
106
|
+ title,
|
|
|
107
|
+ null,
|
|
|
108
|
+ message,
|
|
|
109
|
+ null,
|
|
|
110
|
+ false,
|
|
|
111
|
+ buttonKey,
|
|
|
112
|
+ function(e,v,m,f) {
|
|
|
113
|
+ if (v) {
|
|
|
114
|
+ resolve();
|
|
|
115
|
+ } else {
|
|
|
116
|
+ reject();
|
|
|
117
|
+ }
|
|
|
118
|
+ }
|
|
|
119
|
+ );
|
|
|
120
|
+ });
|
|
|
121
|
+}
|
|
|
122
|
+
|
|
|
123
|
+function moveToCorner(selector, move) {
|
|
|
124
|
+ let moveToCornerClass = "moveToCorner";
|
|
|
125
|
+
|
|
|
126
|
+ if (move && !selector.hasClass(moveToCornerClass))
|
|
|
127
|
+ selector.addClass(moveToCornerClass);
|
|
|
128
|
+ else
|
|
|
129
|
+ selector.removeClass(moveToCornerClass);
|
|
|
130
|
+}
|
|
|
131
|
+
|
|
|
132
|
+var Recording = {
|
|
|
133
|
+ /**
|
|
|
134
|
+ * Initializes the recording UI.
|
|
|
135
|
+ */
|
|
|
136
|
+ init (emitter, recordingType) {
|
|
|
137
|
+ this.eventEmitter = emitter;
|
|
|
138
|
+
|
|
|
139
|
+ this.initRecordingButton(recordingType);
|
|
|
140
|
+ },
|
|
|
141
|
+
|
|
|
142
|
+ initRecordingButton(recordingType) {
|
|
|
143
|
+ let selector = $('#toolbar_button_record');
|
|
|
144
|
+
|
|
|
145
|
+ if (recordingType === 'jibri') {
|
|
|
146
|
+ this.baseClass = "fa fa-play-circle";
|
|
|
147
|
+ this.recordingOnKey = "liveStreaming.on";
|
|
|
148
|
+ this.recordingOffKey = "liveStreaming.off";
|
|
|
149
|
+ this.recordingPendingKey = "liveStreaming.pending";
|
|
|
150
|
+ this.failedToStartKey = "liveStreaming.failedToStart";
|
|
|
151
|
+ }
|
|
|
152
|
+ else {
|
|
|
153
|
+ this.baseClass = "icon-recEnable";
|
|
|
154
|
+ this.recordingOnKey = "recording.on";
|
|
|
155
|
+ this.recordingOffKey = "recording.off";
|
|
|
156
|
+ this.recordingPendingKey = "recording.pending";
|
|
|
157
|
+ this.failedToStartKey = "recording.failedToStart";
|
|
|
158
|
+ }
|
|
|
159
|
+
|
|
|
160
|
+ selector.addClass(this.baseClass);
|
|
|
161
|
+
|
|
|
162
|
+ var self = this;
|
|
|
163
|
+ selector.click(function () {
|
|
|
164
|
+ console.log("BUTTON CLICKED", self.currentState);
|
|
|
165
|
+ switch (self.currentState) {
|
|
|
166
|
+ case "on": {
|
|
|
167
|
+ _showStopRecordingPrompt(recordingType).then(() =>
|
|
|
168
|
+ self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED));
|
|
|
169
|
+ }
|
|
|
170
|
+ break;
|
|
|
171
|
+ case "available":
|
|
|
172
|
+ case "off": {
|
|
|
173
|
+ if (recordingType === 'jibri')
|
|
|
174
|
+ _requestLiveStreamId().then((streamId) => {
|
|
|
175
|
+ self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
176
|
+ {streamId: streamId});
|
|
|
177
|
+ });
|
|
|
178
|
+ else {
|
|
|
179
|
+ if (self.predefinedToken) {
|
|
|
180
|
+ self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
181
|
+ {token: self.predefinedToken});
|
|
|
182
|
+ return;
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
|
185
|
+ _requestRecordingToken().then((token) => {
|
|
|
186
|
+ self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
|
|
|
187
|
+ {token: token});
|
|
|
188
|
+ });
|
|
|
189
|
+ }
|
|
|
190
|
+ }
|
|
|
191
|
+ break;
|
|
|
192
|
+ default: {
|
|
|
193
|
+ APP.UI.messageHandler.openMessageDialog(
|
|
|
194
|
+ "dialog.liveStreaming",
|
|
|
195
|
+ "liveStreaming.unavailable"
|
|
|
196
|
+ );
|
|
|
197
|
+ }
|
|
|
198
|
+ }
|
|
|
199
|
+ });
|
|
|
200
|
+ },
|
|
|
201
|
+
|
|
|
202
|
+ // Shows or hides the 'recording' button.
|
|
|
203
|
+ showRecordingButton (show) {
|
|
|
204
|
+ if (_isRecordingButtonEnabled() && show) {
|
|
|
205
|
+ $('#toolbar_button_record').css({display: "inline-block"});
|
|
|
206
|
+ } else {
|
|
|
207
|
+ $('#toolbar_button_record').css({display: "none"});
|
|
|
208
|
+ }
|
|
|
209
|
+ },
|
|
|
210
|
+
|
|
|
211
|
+ updateRecordingState(recordingState) {
|
|
|
212
|
+ // If there's no state change, we ignore the update.
|
|
|
213
|
+ if (this.currentState === recordingState)
|
|
|
214
|
+ return;
|
|
|
215
|
+
|
|
|
216
|
+ this.setRecordingButtonState(recordingState);
|
|
|
217
|
+ },
|
|
|
218
|
+
|
|
|
219
|
+ // Sets the state of the recording button
|
|
|
220
|
+ setRecordingButtonState (recordingState) {
|
|
|
221
|
+ let buttonSelector = $('#toolbar_button_record');
|
|
|
222
|
+ let labelSelector = $('#recordingLabel');
|
|
|
223
|
+
|
|
|
224
|
+ // TODO: handle recording state=available
|
|
|
225
|
+ if (recordingState === 'on') {
|
|
|
226
|
+
|
|
|
227
|
+ buttonSelector.removeClass(this.baseClass);
|
|
|
228
|
+ buttonSelector.addClass(this.baseClass + " active");
|
|
|
229
|
+
|
|
|
230
|
+ labelSelector.attr("data-i18n", this.recordingOnKey);
|
|
|
231
|
+ moveToCorner(labelSelector, true, 3000);
|
|
|
232
|
+ labelSelector
|
|
|
233
|
+ .text(APP.translation.translateString(this.recordingOnKey));
|
|
|
234
|
+ } else if (recordingState === 'off'
|
|
|
235
|
+ || recordingState === 'unavailable') {
|
|
|
236
|
+
|
|
|
237
|
+ // We don't want to do any changes if this is
|
|
|
238
|
+ // an availability change.
|
|
|
239
|
+ if (this.currentState === "available"
|
|
|
240
|
+ || this.currentState === "unavailable")
|
|
|
241
|
+ return;
|
|
|
242
|
+
|
|
|
243
|
+ buttonSelector.removeClass(this.baseClass + " active");
|
|
|
244
|
+ buttonSelector.addClass(this.baseClass);
|
|
|
245
|
+
|
|
|
246
|
+ moveToCorner(labelSelector, false);
|
|
|
247
|
+ let messageKey;
|
|
|
248
|
+ if (this.currentState === "pending")
|
|
|
249
|
+ messageKey = this.failedToStartKey;
|
|
|
250
|
+ else
|
|
|
251
|
+ messageKey = this.recordingOffKey;
|
|
|
252
|
+
|
|
|
253
|
+ labelSelector.attr("data-i18n", messageKey);
|
|
|
254
|
+ labelSelector.text(APP.translation.translateString(messageKey));
|
|
|
255
|
+
|
|
|
256
|
+ setTimeout(function(){
|
|
|
257
|
+ $('#recordingLabel').css({display: "none"});
|
|
|
258
|
+ }, 5000);
|
|
|
259
|
+ }
|
|
|
260
|
+ else if (recordingState === 'pending') {
|
|
|
261
|
+
|
|
|
262
|
+ buttonSelector.removeClass(this.baseClass + " active");
|
|
|
263
|
+ buttonSelector.addClass(this.baseClass);
|
|
|
264
|
+
|
|
|
265
|
+ moveToCorner(labelSelector, false);
|
|
|
266
|
+ labelSelector
|
|
|
267
|
+ .attr("data-i18n", this.recordingPendingKey);
|
|
|
268
|
+ labelSelector
|
|
|
269
|
+ .text(APP.translation.translateString(
|
|
|
270
|
+ this.recordingPendingKey));
|
|
|
271
|
+ }
|
|
|
272
|
+
|
|
|
273
|
+ this.currentState = recordingState;
|
|
|
274
|
+
|
|
|
275
|
+ if (!labelSelector.is(":visible"))
|
|
|
276
|
+ labelSelector.css({display: "inline-block"});
|
|
|
277
|
+ },
|
|
|
278
|
+ // checks whether recording is enabled and whether we have params
|
|
|
279
|
+ // to start automatically recording
|
|
|
280
|
+ checkAutoRecord () {
|
|
|
281
|
+ if (_isRecordingButtonEnabled && config.autoRecord) {
|
|
|
282
|
+ this.predefinedToken = UIUtil.escapeHtml(config.autoRecordToken);
|
|
|
283
|
+ this.eventEmitter.emit(UIEvents.RECORDING_TOGGLED,
|
|
|
284
|
+ this.predefinedToken);
|
|
|
285
|
+ }
|
|
|
286
|
+ }
|
|
|
287
|
+};
|
|
|
288
|
+
|
|
|
289
|
+export default Recording;
|