選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Recording.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. const logger = require('jitsi-meet-logger').getLogger(__filename);
  18. import UIEvents from '../../../service/UI/UIEvents';
  19. import UIUtil from '../util/UIUtil';
  20. import VideoLayout from '../videolayout/VideoLayout';
  21. import { openDialog } from '../../../react/features/base/dialog';
  22. import {
  23. JitsiRecordingStatus
  24. } from '../../../react/features/base/lib-jitsi-meet';
  25. import {
  26. createToolbarEvent,
  27. createRecordingDialogEvent,
  28. sendAnalytics
  29. } from '../../../react/features/analytics';
  30. import { setToolboxEnabled } from '../../../react/features/toolbox';
  31. import { setNotificationsEnabled } from '../../../react/features/notifications';
  32. import {
  33. StartLiveStreamDialog,
  34. StopLiveStreamDialog,
  35. hideRecordingLabel,
  36. setRecordingType,
  37. updateRecordingState
  38. } from '../../../react/features/recording';
  39. /**
  40. * Translation keys to use for display in the UI when recording the conference
  41. * but not streaming live.
  42. *
  43. * @private
  44. * @type {Object}
  45. */
  46. export const RECORDING_TRANSLATION_KEYS = {
  47. failedToStartKey: 'recording.failedToStart',
  48. recordingBusy: 'recording.busy',
  49. recordingBusyTitle: 'recording.busyTitle',
  50. recordingButtonTooltip: 'recording.buttonTooltip',
  51. recordingErrorKey: 'recording.error',
  52. recordingOffKey: 'recording.off',
  53. recordingOnKey: 'recording.on',
  54. recordingPendingKey: 'recording.pending',
  55. recordingTitle: 'dialog.recording',
  56. recordingUnavailable: 'recording.unavailable',
  57. recordingUnavailableParams: '$t(recording.serviceName)',
  58. recordingUnavailableTitle: 'recording.unavailableTitle'
  59. };
  60. /**
  61. * Translation keys to use for display in the UI when the recording mode is
  62. * currently streaming live.
  63. *
  64. * @private
  65. * @type {Object}
  66. */
  67. export const STREAMING_TRANSLATION_KEYS = {
  68. failedToStartKey: 'liveStreaming.failedToStart',
  69. recordingBusy: 'liveStreaming.busy',
  70. recordingBusyTitle: 'liveStreaming.busyTitle',
  71. recordingButtonTooltip: 'liveStreaming.buttonTooltip',
  72. recordingErrorKey: 'liveStreaming.error',
  73. recordingOffKey: 'liveStreaming.off',
  74. recordingOnKey: 'liveStreaming.on',
  75. recordingPendingKey: 'liveStreaming.pending',
  76. recordingTitle: 'dialog.liveStreaming',
  77. recordingUnavailable: 'recording.unavailable',
  78. recordingUnavailableParams: '$t(liveStreaming.serviceName)',
  79. recordingUnavailableTitle: 'liveStreaming.unavailableTitle'
  80. };
  81. /**
  82. * The dialog for user input.
  83. */
  84. let dialog = null;
  85. /**
  86. * Indicates if the recording button should be enabled.
  87. *
  88. * @returns {boolean} {true} if the
  89. * @private
  90. */
  91. function _isRecordingButtonEnabled() {
  92. return (
  93. interfaceConfig.TOOLBAR_BUTTONS.indexOf('recording') !== -1
  94. && config.enableRecording
  95. && APP.conference.isRecordingSupported());
  96. }
  97. /**
  98. * Request live stream token from the user.
  99. * @returns {Promise}
  100. */
  101. function _requestLiveStreamId() {
  102. return new Promise((resolve, reject) =>
  103. APP.store.dispatch(openDialog(StartLiveStreamDialog, {
  104. onCancel: reject,
  105. onSubmit: (streamId, broadcastId) => resolve({
  106. broadcastId,
  107. streamId
  108. })
  109. })));
  110. }
  111. /**
  112. * Request recording token from the user.
  113. * @returns {Promise}
  114. */
  115. function _requestRecordingToken() {
  116. const titleKey = 'dialog.recordingToken';
  117. const msgString
  118. = `<input name="recordingToken" type="text"
  119. data-i18n="[placeholder]dialog.token"
  120. class="input-control"
  121. autofocus>`
  122. ;
  123. return new Promise((resolve, reject) => {
  124. dialog = APP.UI.messageHandler.openTwoButtonDialog({
  125. titleKey,
  126. msgString,
  127. leftButtonKey: 'dialog.Save',
  128. submitFunction(e, v, m, f) { // eslint-disable-line max-params
  129. if (v && f.recordingToken) {
  130. resolve(UIUtil.escapeHtml(f.recordingToken));
  131. } else {
  132. reject(APP.UI.messageHandler.CANCEL);
  133. }
  134. },
  135. closeFunction() {
  136. dialog = null;
  137. },
  138. focus: ':input:first'
  139. });
  140. });
  141. }
  142. /**
  143. * Shows a prompt dialog to the user when they have toggled off the recording.
  144. *
  145. * @param recordingType the recording type
  146. * @returns {Promise}
  147. * @private
  148. */
  149. function _showStopRecordingPrompt(recordingType) {
  150. if (recordingType === 'jibri') {
  151. return new Promise((resolve, reject) => {
  152. APP.store.dispatch(openDialog(StopLiveStreamDialog, {
  153. onCancel: reject,
  154. onSubmit: resolve
  155. }));
  156. });
  157. }
  158. return new Promise((resolve, reject) => {
  159. dialog = APP.UI.messageHandler.openTwoButtonDialog({
  160. titleKey: 'dialog.recording',
  161. msgKey: 'dialog.stopRecordingWarning',
  162. leftButtonKey: 'dialog.stopRecording',
  163. submitFunction: (e, v) => (v ? resolve : reject)(),
  164. closeFunction: () => {
  165. dialog = null;
  166. }
  167. });
  168. });
  169. }
  170. /**
  171. * Checks whether if the given status is either PENDING or RETRYING
  172. * @param status {JitsiRecordingStatus} Jibri status to be checked
  173. * @returns {boolean} true if the condition is met or false otherwise.
  174. */
  175. function isStartingStatus(status) {
  176. return (
  177. status === JitsiRecordingStatus.PENDING
  178. || status === JitsiRecordingStatus.RETRYING
  179. );
  180. }
  181. /**
  182. * Manages the recording user interface and user experience.
  183. * @type {{init, updateRecordingState, updateRecordingUI, checkAutoRecord}}
  184. */
  185. const Recording = {
  186. /**
  187. * Initializes the recording UI.
  188. */
  189. init(eventEmitter, recordingType) {
  190. this.eventEmitter = eventEmitter;
  191. this.recordingType = recordingType;
  192. APP.store.dispatch(setRecordingType(recordingType));
  193. this.updateRecordingState(APP.conference.getRecordingState());
  194. if (recordingType === 'jibri') {
  195. this.baseClass = 'fa fa-play-circle';
  196. Object.assign(this, STREAMING_TRANSLATION_KEYS);
  197. } else {
  198. this.baseClass = 'icon-recEnable';
  199. Object.assign(this, RECORDING_TRANSLATION_KEYS);
  200. }
  201. this.eventEmitter.on(UIEvents.TOGGLE_RECORDING,
  202. () => this._onToolbarButtonClick());
  203. // If I am a recorder then I publish my recorder custom role to notify
  204. // everyone.
  205. if (config.iAmRecorder) {
  206. VideoLayout.enableDeviceAvailabilityIcons(
  207. APP.conference.getMyUserId(), false);
  208. // in case of iAmSipGateway keep local video visible
  209. if (!config.iAmSipGateway) {
  210. VideoLayout.setLocalVideoVisible(false);
  211. }
  212. APP.store.dispatch(setToolboxEnabled(false));
  213. APP.store.dispatch(setNotificationsEnabled(false));
  214. APP.UI.messageHandler.enablePopups(false);
  215. }
  216. },
  217. /**
  218. * Updates the recording state UI.
  219. * @param recordingState gives us the current recording state
  220. */
  221. updateRecordingState(recordingState) {
  222. // I'm the recorder, so I don't want to see any UI related to states.
  223. if (config.iAmRecorder) {
  224. return;
  225. }
  226. // If there's no state change, we ignore the update.
  227. if (!recordingState || this.currentState === recordingState) {
  228. return;
  229. }
  230. this.updateRecordingUI(recordingState);
  231. },
  232. /**
  233. * Sets the state of the recording button.
  234. * @param recordingState gives us the current recording state
  235. */
  236. updateRecordingUI(recordingState) {
  237. const oldState = this.currentState;
  238. this.currentState = recordingState;
  239. let labelDisplayConfiguration;
  240. let isRecording = false;
  241. switch (recordingState) {
  242. case JitsiRecordingStatus.ON:
  243. case JitsiRecordingStatus.RETRYING: {
  244. labelDisplayConfiguration = {
  245. centered: false,
  246. key: this.recordingOnKey,
  247. showSpinner: recordingState === JitsiRecordingStatus.RETRYING
  248. };
  249. isRecording = true;
  250. break;
  251. }
  252. case JitsiRecordingStatus.OFF:
  253. case JitsiRecordingStatus.BUSY:
  254. case JitsiRecordingStatus.FAILED:
  255. case JitsiRecordingStatus.UNAVAILABLE: {
  256. const wasInStartingStatus = isStartingStatus(oldState);
  257. // We don't want UI changes if this is an availability change.
  258. if (oldState !== JitsiRecordingStatus.ON && !wasInStartingStatus) {
  259. APP.store.dispatch(updateRecordingState({ recordingState }));
  260. return;
  261. }
  262. labelDisplayConfiguration = {
  263. centered: true,
  264. key: wasInStartingStatus
  265. ? this.failedToStartKey
  266. : this.recordingOffKey
  267. };
  268. setTimeout(() => {
  269. APP.store.dispatch(hideRecordingLabel());
  270. }, 5000);
  271. break;
  272. }
  273. case JitsiRecordingStatus.PENDING: {
  274. labelDisplayConfiguration = {
  275. centered: true,
  276. key: this.recordingPendingKey
  277. };
  278. break;
  279. }
  280. case JitsiRecordingStatus.ERROR: {
  281. labelDisplayConfiguration = {
  282. centered: true,
  283. key: this.recordingErrorKey
  284. };
  285. break;
  286. }
  287. // Return an empty label display configuration to indicate no label
  288. // should be displayed. The JitsiRecordingStatus.AVAIABLE case is
  289. // handled here.
  290. default: {
  291. labelDisplayConfiguration = null;
  292. }
  293. }
  294. APP.store.dispatch(updateRecordingState({
  295. isRecording,
  296. labelDisplayConfiguration,
  297. recordingState
  298. }));
  299. },
  300. // checks whether recording is enabled and whether we have params
  301. // to start automatically recording (XXX: No, it doesn't do that).
  302. checkAutoRecord() {
  303. if (_isRecordingButtonEnabled && config.autoRecord) {
  304. this.predefinedToken = UIUtil.escapeHtml(config.autoRecordToken);
  305. this.eventEmitter.emit(
  306. UIEvents.RECORDING_TOGGLED,
  307. { token: this.predefinedToken });
  308. }
  309. },
  310. /**
  311. * Handles {@code click} on {@code toolbar_button_record}.
  312. *
  313. * @returns {void}
  314. */
  315. _onToolbarButtonClick() {
  316. sendAnalytics(createToolbarEvent(
  317. 'recording.button',
  318. {
  319. 'dialog_present': Boolean(dialog)
  320. }));
  321. if (dialog) {
  322. return;
  323. }
  324. switch (this.currentState) {
  325. case JitsiRecordingStatus.ON:
  326. case JitsiRecordingStatus.RETRYING:
  327. case JitsiRecordingStatus.PENDING: {
  328. _showStopRecordingPrompt(this.recordingType).then(
  329. () => {
  330. this.eventEmitter.emit(UIEvents.RECORDING_TOGGLED);
  331. // The confirm button on the stop recording dialog was
  332. // clicked
  333. sendAnalytics(
  334. createRecordingDialogEvent(
  335. 'stop',
  336. 'confirm.button'));
  337. },
  338. () => {}); // eslint-disable-line no-empty-function
  339. break;
  340. }
  341. case JitsiRecordingStatus.AVAILABLE:
  342. case JitsiRecordingStatus.OFF: {
  343. if (this.recordingType === 'jibri') {
  344. _requestLiveStreamId()
  345. .then(({ broadcastId, streamId }) => {
  346. this.eventEmitter.emit(
  347. UIEvents.RECORDING_TOGGLED,
  348. {
  349. broadcastId,
  350. streamId
  351. });
  352. // The confirm button on the start recording dialog was
  353. // clicked
  354. sendAnalytics(
  355. createRecordingDialogEvent(
  356. 'start',
  357. 'confirm.button'));
  358. })
  359. .catch(reason => {
  360. if (reason === APP.UI.messageHandler.CANCEL) {
  361. // The cancel button on the start recording dialog was
  362. // clicked
  363. sendAnalytics(
  364. createRecordingDialogEvent(
  365. 'start',
  366. 'cancel.button'));
  367. } else {
  368. logger.error(reason);
  369. }
  370. });
  371. } else {
  372. // Note that we only fire analytics events for Jibri.
  373. if (this.predefinedToken) {
  374. this.eventEmitter.emit(
  375. UIEvents.RECORDING_TOGGLED,
  376. { token: this.predefinedToken });
  377. return;
  378. }
  379. _requestRecordingToken().then(token => {
  380. this.eventEmitter.emit(
  381. UIEvents.RECORDING_TOGGLED,
  382. { token });
  383. })
  384. .catch(reason => {
  385. if (reason !== APP.UI.messageHandler.CANCEL) {
  386. logger.error(reason);
  387. }
  388. });
  389. }
  390. break;
  391. }
  392. case JitsiRecordingStatus.BUSY: {
  393. APP.UI.messageHandler.showWarning({
  394. descriptionKey: this.recordingBusy,
  395. titleKey: this.recordingBusyTitle
  396. });
  397. break;
  398. }
  399. default: {
  400. APP.UI.messageHandler.showError({
  401. descriptionKey: this.recordingUnavailable,
  402. descriptionArguments: {
  403. serviceName: this.recordingUnavailableParams },
  404. titleKey: this.recordingUnavailableTitle
  405. });
  406. }
  407. }
  408. }
  409. };
  410. export default Recording;