您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Recording.js 14KB

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