You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

API.js 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. // @flow
  2. import Logger from 'jitsi-meet-logger';
  3. import {
  4. createApiEvent,
  5. sendAnalytics
  6. } from '../../react/features/analytics';
  7. import {
  8. getCurrentConference,
  9. sendTones,
  10. setPassword,
  11. setSubject
  12. } from '../../react/features/base/conference';
  13. import { parseJWTFromURLParams } from '../../react/features/base/jwt';
  14. import JitsiMeetJS, { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  15. import { pinParticipant, getParticipantById } from '../../react/features/base/participants';
  16. import { setPrivateMessageRecipient } from '../../react/features/chat/actions';
  17. import {
  18. processExternalDeviceRequest
  19. } from '../../react/features/device-selection/functions';
  20. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox';
  21. import { toggleE2EE } from '../../react/features/e2ee/actions';
  22. import { invite } from '../../react/features/invite';
  23. import {
  24. captureLargeVideoScreenshot,
  25. resizeLargeVideo,
  26. selectParticipantInLargeVideo
  27. } from '../../react/features/large-video/actions';
  28. import { toggleLobbyMode } from '../../react/features/lobby/actions.web';
  29. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  30. import { getActiveSession } from '../../react/features/recording/functions';
  31. import { muteAllParticipants } from '../../react/features/remote-video-menu/actions';
  32. import { toggleTileView } from '../../react/features/video-layout';
  33. import { setVideoQuality } from '../../react/features/video-quality';
  34. import { getJitsiMeetTransport } from '../transport';
  35. import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
  36. const logger = Logger.getLogger(__filename);
  37. declare var APP: Object;
  38. /**
  39. * List of the available commands.
  40. */
  41. let commands = {};
  42. /**
  43. * The transport instance used for communication with external apps.
  44. *
  45. * @type {Transport}
  46. */
  47. const transport = getJitsiMeetTransport();
  48. /**
  49. * The current audio availability.
  50. *
  51. * @type {boolean}
  52. */
  53. let audioAvailable = true;
  54. /**
  55. * The current video availability.
  56. *
  57. * @type {boolean}
  58. */
  59. let videoAvailable = true;
  60. /**
  61. * Initializes supported commands.
  62. *
  63. * @returns {void}
  64. */
  65. function initCommands() {
  66. commands = {
  67. 'display-name': displayName => {
  68. sendAnalytics(createApiEvent('display.name.changed'));
  69. APP.conference.changeLocalDisplayName(displayName);
  70. },
  71. 'mute-everyone': () => {
  72. sendAnalytics(createApiEvent('muted-everyone'));
  73. const participants = APP.store.getState()['features/base/participants'];
  74. const localIds = participants
  75. .filter(participant => participant.local)
  76. .filter(participant => participant.role === 'moderator')
  77. .map(participant => participant.id);
  78. APP.store.dispatch(muteAllParticipants(localIds));
  79. },
  80. 'toggle-lobby': isLobbyEnabled => {
  81. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  82. },
  83. 'password': password => {
  84. const { conference, passwordRequired }
  85. = APP.store.getState()['features/base/conference'];
  86. if (passwordRequired) {
  87. sendAnalytics(createApiEvent('submit.password'));
  88. APP.store.dispatch(setPassword(
  89. passwordRequired,
  90. passwordRequired.join,
  91. password
  92. ));
  93. } else {
  94. sendAnalytics(createApiEvent('password.changed'));
  95. APP.store.dispatch(setPassword(
  96. conference,
  97. conference.lock,
  98. password
  99. ));
  100. }
  101. },
  102. 'pin-participant': id => {
  103. logger.debug('Pin participant command received');
  104. sendAnalytics(createApiEvent('participant.pinned'));
  105. APP.store.dispatch(pinParticipant(id));
  106. },
  107. 'proxy-connection-event': event => {
  108. APP.conference.onProxyConnectionEvent(event);
  109. },
  110. 'resize-large-video': (width, height) => {
  111. logger.debug('Resize large video command received');
  112. sendAnalytics(createApiEvent('largevideo.resized'));
  113. APP.store.dispatch(resizeLargeVideo(width, height));
  114. },
  115. 'send-tones': (options = {}) => {
  116. const { duration, tones, pause } = options;
  117. APP.store.dispatch(sendTones(tones, duration, pause));
  118. },
  119. 'set-large-video-participant': participantId => {
  120. logger.debug('Set large video participant command received');
  121. sendAnalytics(createApiEvent('largevideo.participant.set'));
  122. APP.store.dispatch(selectParticipantInLargeVideo(participantId));
  123. },
  124. 'subject': subject => {
  125. sendAnalytics(createApiEvent('subject.changed'));
  126. APP.store.dispatch(setSubject(subject));
  127. },
  128. 'submit-feedback': feedback => {
  129. sendAnalytics(createApiEvent('submit.feedback'));
  130. APP.conference.submitFeedback(feedback.score, feedback.message);
  131. },
  132. 'toggle-audio': () => {
  133. sendAnalytics(createApiEvent('toggle-audio'));
  134. logger.log('Audio toggle: API command received');
  135. APP.conference.toggleAudioMuted(false /* no UI */);
  136. },
  137. 'toggle-video': () => {
  138. sendAnalytics(createApiEvent('toggle-video'));
  139. logger.log('Video toggle: API command received');
  140. APP.conference.toggleVideoMuted(false /* no UI */);
  141. },
  142. 'toggle-film-strip': () => {
  143. sendAnalytics(createApiEvent('film.strip.toggled'));
  144. APP.UI.toggleFilmstrip();
  145. },
  146. 'toggle-chat': () => {
  147. sendAnalytics(createApiEvent('chat.toggled'));
  148. APP.UI.toggleChat();
  149. },
  150. /**
  151. * Callback to invoke when the "toggle-share-screen" command is received.
  152. *
  153. * @param {Object} options - Additional details of how to perform
  154. * the action. Note this parameter is undocumented and experimental.
  155. * @param {boolean} options.enable - Whether trying to enable screen
  156. * sharing or to turn it off.
  157. * @returns {void}
  158. */
  159. 'toggle-share-screen': (options = {}) => {
  160. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  161. toggleScreenSharing(options.enable);
  162. },
  163. 'toggle-tile-view': () => {
  164. sendAnalytics(createApiEvent('tile-view.toggled'));
  165. APP.store.dispatch(toggleTileView());
  166. },
  167. 'video-hangup': (showFeedbackDialog = true) => {
  168. sendAnalytics(createApiEvent('video.hangup'));
  169. APP.conference.hangup(showFeedbackDialog);
  170. },
  171. 'email': email => {
  172. sendAnalytics(createApiEvent('email.changed'));
  173. APP.conference.changeLocalEmail(email);
  174. },
  175. 'avatar-url': avatarUrl => {
  176. sendAnalytics(createApiEvent('avatar.url.changed'));
  177. APP.conference.changeLocalAvatarUrl(avatarUrl);
  178. },
  179. 'send-endpoint-text-message': (to, text) => {
  180. logger.debug('Send endpoint message command received');
  181. try {
  182. APP.conference.sendEndpointMessage(to, {
  183. name: ENDPOINT_TEXT_MESSAGE_NAME,
  184. text
  185. });
  186. } catch (err) {
  187. logger.error('Failed sending endpoint text message', err);
  188. }
  189. },
  190. 'toggle-e2ee': enabled => {
  191. logger.debug('Toggle E2EE key command received');
  192. APP.store.dispatch(toggleE2EE(enabled));
  193. },
  194. 'set-video-quality': frameHeight => {
  195. logger.debug('Set video quality command received');
  196. sendAnalytics(createApiEvent('set.video.quality'));
  197. APP.store.dispatch(setVideoQuality(frameHeight));
  198. },
  199. /**
  200. * Starts a file recording or streaming session depending on the passed on params.
  201. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  202. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  203. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  204. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  205. * No other params should be passed.
  206. *
  207. * @param { string } arg.mode - Recording mode, either `file` or `stream`.
  208. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  209. * @param { string } arg.rtmpStreamKey - The RTMP stream key.
  210. * @param { string } arg.rtmpBroadcastID - The RTMP braodcast ID.
  211. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  212. * Only applies to certain jitsi meet deploys.
  213. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  214. * @param { string } arg.youtubeBroadcastID - The youtube broacast ID.
  215. * @returns {void}
  216. */
  217. 'start-recording': ({
  218. mode,
  219. dropboxToken,
  220. shouldShare,
  221. rtmpStreamKey,
  222. rtmpBroadcastID,
  223. youtubeStreamKey,
  224. youtubeBroadcastID
  225. }) => {
  226. const state = APP.store.getState();
  227. const conference = getCurrentConference(state);
  228. if (!conference) {
  229. logger.error('Conference is not defined');
  230. return;
  231. }
  232. if (dropboxToken && !isDropboxEnabled(state)) {
  233. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  234. return;
  235. }
  236. if (mode === JitsiRecordingConstants.mode.STREAM && !(youtubeStreamKey || rtmpStreamKey)) {
  237. logger.error('Failed starting recording: missing youtube or RTMP stream key');
  238. return;
  239. }
  240. let recordingConfig;
  241. if (mode === JitsiRecordingConstants.mode.FILE) {
  242. if (dropboxToken) {
  243. recordingConfig = {
  244. mode: JitsiRecordingConstants.mode.FILE,
  245. appData: JSON.stringify({
  246. 'file_recording_metadata': {
  247. 'upload_credentials': {
  248. 'service_name': RECORDING_TYPES.DROPBOX,
  249. 'token': dropboxToken
  250. }
  251. }
  252. })
  253. };
  254. } else {
  255. recordingConfig = {
  256. mode: JitsiRecordingConstants.mode.FILE,
  257. appData: JSON.stringify({
  258. 'file_recording_metadata': {
  259. 'share': shouldShare
  260. }
  261. })
  262. };
  263. }
  264. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  265. recordingConfig = {
  266. broadcastId: youtubeBroadcastID || rtmpBroadcastID,
  267. mode: JitsiRecordingConstants.mode.STREAM,
  268. streamId: youtubeStreamKey || rtmpStreamKey
  269. };
  270. } else {
  271. logger.error('Invalid recording mode provided');
  272. return;
  273. }
  274. conference.startRecording(recordingConfig);
  275. },
  276. /**
  277. * Stops a recording or streaming in progress.
  278. *
  279. * @param {string} mode - `file` or `stream`.
  280. * @returns {void}
  281. */
  282. 'stop-recording': mode => {
  283. const state = APP.store.getState();
  284. const conference = getCurrentConference(state);
  285. if (!conference) {
  286. logger.error('Conference is not defined');
  287. return;
  288. }
  289. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  290. logger.error('Invalid recording mode provided!');
  291. return;
  292. }
  293. const activeSession = getActiveSession(state, mode);
  294. if (activeSession && activeSession.id) {
  295. conference.stopRecording(activeSession.id);
  296. } else {
  297. logger.error('No recording or streaming session found');
  298. }
  299. },
  300. 'initiate-private-chat': participantId => {
  301. const state = APP.store.getState();
  302. const participant = getParticipantById(state, participantId);
  303. if (participant) {
  304. const { isOpen: isChatOpen } = state['features/chat'];
  305. if (!isChatOpen) {
  306. APP.UI.toggleChat();
  307. }
  308. APP.store.dispatch(setPrivateMessageRecipient(participant));
  309. } else {
  310. logger.error('No participant found for the given participantId');
  311. }
  312. },
  313. 'cancel-private-chat': () => {
  314. APP.store.dispatch(setPrivateMessageRecipient());
  315. }
  316. };
  317. transport.on('event', ({ data, name }) => {
  318. if (name && commands[name]) {
  319. commands[name](...data);
  320. return true;
  321. }
  322. return false;
  323. });
  324. transport.on('request', (request, callback) => {
  325. const { dispatch, getState } = APP.store;
  326. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  327. return true;
  328. }
  329. const { name } = request;
  330. switch (name) {
  331. case 'capture-largevideo-screenshot' :
  332. APP.store.dispatch(captureLargeVideoScreenshot())
  333. .then(dataURL => {
  334. let error;
  335. if (!dataURL) {
  336. error = new Error('No large video found!');
  337. }
  338. callback({
  339. error,
  340. dataURL
  341. });
  342. });
  343. break;
  344. case 'invite': {
  345. const { invitees } = request;
  346. if (!Array.isArray(invitees) || invitees.length === 0) {
  347. callback({
  348. error: new Error('Unexpected format of invitees')
  349. });
  350. break;
  351. }
  352. // The store should be already available because API.init is called
  353. // on appWillMount action.
  354. APP.store.dispatch(
  355. invite(invitees, true))
  356. .then(failedInvitees => {
  357. let error;
  358. let result;
  359. if (failedInvitees.length) {
  360. error = new Error('One or more invites failed!');
  361. } else {
  362. result = true;
  363. }
  364. callback({
  365. error,
  366. result
  367. });
  368. });
  369. break;
  370. }
  371. case 'is-audio-muted':
  372. callback(APP.conference.isLocalAudioMuted());
  373. break;
  374. case 'is-video-muted':
  375. callback(APP.conference.isLocalVideoMuted());
  376. break;
  377. case 'is-audio-available':
  378. callback(audioAvailable);
  379. break;
  380. case 'is-video-available':
  381. callback(videoAvailable);
  382. break;
  383. case 'is-sharing-screen':
  384. callback(Boolean(APP.conference.isSharingScreen));
  385. break;
  386. default:
  387. return false;
  388. }
  389. return true;
  390. });
  391. }
  392. /**
  393. * Check whether the API should be enabled or not.
  394. *
  395. * @returns {boolean}
  396. */
  397. function shouldBeEnabled() {
  398. return (
  399. typeof API_ID === 'number'
  400. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  401. // the location/URL because then it is very likely that the Jitsi
  402. // Meet (Web) app is being used by an external/wrapping (Web) app
  403. // and, consequently, the latter will need to communicate with the
  404. // former. (The described logic is merely a heuristic though.)
  405. || parseJWTFromURLParams());
  406. }
  407. /**
  408. * Executes on toggle-share-screen command.
  409. *
  410. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  411. * disable screensharing. If not defined, the application will automatically
  412. * attempt to toggle between enabled and disabled. This boolean is useful for
  413. * explicitly setting desired screensharing state.
  414. * @returns {void}
  415. */
  416. function toggleScreenSharing(enable) {
  417. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  418. APP.conference.toggleScreenSharing(enable).catch(() => {
  419. logger.warn('Failed to toggle screen-sharing');
  420. });
  421. }
  422. }
  423. /**
  424. * Implements API class that communicates with external API class and provides
  425. * interface to access Jitsi Meet features by external applications that embed
  426. * Jitsi Meet.
  427. */
  428. class API {
  429. _enabled: boolean;
  430. /**
  431. * Initializes the API. Setups message event listeners that will receive
  432. * information from external applications that embed Jitsi Meet. It also
  433. * sends a message to the external application that API is initialized.
  434. *
  435. * @param {Object} options - Optional parameters.
  436. * @returns {void}
  437. */
  438. init() {
  439. if (!shouldBeEnabled()) {
  440. return;
  441. }
  442. /**
  443. * Current status (enabled/disabled) of API.
  444. *
  445. * @private
  446. * @type {boolean}
  447. */
  448. this._enabled = true;
  449. initCommands();
  450. }
  451. /**
  452. * Notify external application (if API is enabled) that the large video
  453. * visibility changed.
  454. *
  455. * @param {boolean} isHidden - True if the large video is hidden and false
  456. * otherwise.
  457. * @returns {void}
  458. */
  459. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  460. this._sendEvent({
  461. name: 'large-video-visibility-changed',
  462. isVisible: !isHidden
  463. });
  464. }
  465. /**
  466. * Notifies the external application (spot) that the local jitsi-participant
  467. * has a status update.
  468. *
  469. * @param {Object} event - The message to pass onto spot.
  470. * @returns {void}
  471. */
  472. sendProxyConnectionEvent(event: Object) {
  473. this._sendEvent({
  474. name: 'proxy-connection-event',
  475. ...event
  476. });
  477. }
  478. /**
  479. * Sends event to the external application.
  480. *
  481. * @param {Object} event - The event to be sent.
  482. * @returns {void}
  483. */
  484. _sendEvent(event: Object = {}) {
  485. if (this._enabled) {
  486. transport.sendEvent(event);
  487. }
  488. }
  489. /**
  490. * Notify external application (if API is enabled) that message was sent.
  491. *
  492. * @param {string} message - Message body.
  493. * @param {boolean} privateMessage - True if the message was a private message.
  494. * @returns {void}
  495. */
  496. notifySendingChatMessage(message: string, privateMessage: boolean) {
  497. this._sendEvent({
  498. name: 'outgoing-message',
  499. message,
  500. privateMessage
  501. });
  502. }
  503. /**
  504. * Notify external application that the video quality setting has changed.
  505. *
  506. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  507. * @returns {void}
  508. */
  509. notifyVideoQualityChanged(videoQuality: number) {
  510. this._sendEvent({
  511. name: 'video-quality-changed',
  512. videoQuality
  513. });
  514. }
  515. /**
  516. * Notify external application (if API is enabled) that message was
  517. * received.
  518. *
  519. * @param {Object} options - Object with the message properties.
  520. * @returns {void}
  521. */
  522. notifyReceivedChatMessage(
  523. { body, id, nick, ts }: {
  524. body: *, id: string, nick: string, ts: *
  525. } = {}) {
  526. if (APP.conference.isLocalId(id)) {
  527. return;
  528. }
  529. this._sendEvent({
  530. name: 'incoming-message',
  531. from: id,
  532. message: body,
  533. nick,
  534. stamp: ts
  535. });
  536. }
  537. /**
  538. * Notify external application (if API is enabled) that user joined the
  539. * conference.
  540. *
  541. * @param {string} id - User id.
  542. * @param {Object} props - The display name of the user.
  543. * @returns {void}
  544. */
  545. notifyUserJoined(id: string, props: Object) {
  546. this._sendEvent({
  547. name: 'participant-joined',
  548. id,
  549. ...props
  550. });
  551. }
  552. /**
  553. * Notify external application (if API is enabled) that user left the
  554. * conference.
  555. *
  556. * @param {string} id - User id.
  557. * @returns {void}
  558. */
  559. notifyUserLeft(id: string) {
  560. this._sendEvent({
  561. name: 'participant-left',
  562. id
  563. });
  564. }
  565. /**
  566. * Notify external application (if API is enabled) that the user role
  567. * has changed.
  568. *
  569. * @param {string} id - User id.
  570. * @param {string} role - The new user role.
  571. * @returns {void}
  572. */
  573. notifyUserRoleChanged(id: string, role: string) {
  574. this._sendEvent({
  575. name: 'participant-role-changed',
  576. id,
  577. role
  578. });
  579. }
  580. /**
  581. * Notify external application (if API is enabled) that user changed their
  582. * avatar.
  583. *
  584. * @param {string} id - User id.
  585. * @param {string} avatarURL - The new avatar URL of the participant.
  586. * @returns {void}
  587. */
  588. notifyAvatarChanged(id: string, avatarURL: string) {
  589. this._sendEvent({
  590. name: 'avatar-changed',
  591. avatarURL,
  592. id
  593. });
  594. }
  595. /**
  596. * Notify external application (if API is enabled) that user received
  597. * a text message through datachannels.
  598. *
  599. * @param {Object} data - The event data.
  600. * @returns {void}
  601. */
  602. notifyEndpointTextMessageReceived(data: Object) {
  603. this._sendEvent({
  604. name: 'endpoint-text-message-received',
  605. data
  606. });
  607. }
  608. /**
  609. * Notify external application (if API is enabled) that the device list has
  610. * changed.
  611. *
  612. * @param {Object} devices - The new device list.
  613. * @returns {void}
  614. */
  615. notifyDeviceListChanged(devices: Object) {
  616. this._sendEvent({
  617. name: 'device-list-changed',
  618. devices
  619. });
  620. }
  621. /**
  622. * Notify external application (if API is enabled) that user changed their
  623. * nickname.
  624. *
  625. * @param {string} id - User id.
  626. * @param {string} displayname - User nickname.
  627. * @param {string} formattedDisplayName - The display name shown in Jitsi
  628. * meet's UI for the user.
  629. * @returns {void}
  630. */
  631. notifyDisplayNameChanged(
  632. id: string,
  633. { displayName, formattedDisplayName }: Object) {
  634. this._sendEvent({
  635. name: 'display-name-change',
  636. displayname: displayName,
  637. formattedDisplayName,
  638. id
  639. });
  640. }
  641. /**
  642. * Notify external application (if API is enabled) that user changed their
  643. * email.
  644. *
  645. * @param {string} id - User id.
  646. * @param {string} email - The new email of the participant.
  647. * @returns {void}
  648. */
  649. notifyEmailChanged(
  650. id: string,
  651. { email }: Object) {
  652. this._sendEvent({
  653. name: 'email-change',
  654. email,
  655. id
  656. });
  657. }
  658. /**
  659. * Notify external application (if API is enabled) that the an error has been logged.
  660. *
  661. * @param {string} logLevel - The message log level.
  662. * @param {Array} args - Array of strings composing the log message.
  663. * @returns {void}
  664. */
  665. notifyLog(logLevel: string, args: Array<string>) {
  666. this._sendEvent({
  667. name: 'log',
  668. logLevel,
  669. args
  670. });
  671. }
  672. /**
  673. * Notify external application (if API is enabled) that the conference has
  674. * been joined.
  675. *
  676. * @param {string} roomName - The room name.
  677. * @param {string} id - The id of the local user.
  678. * @param {Object} props - The display name and avatar URL of the local
  679. * user.
  680. * @returns {void}
  681. */
  682. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  683. this._sendEvent({
  684. name: 'video-conference-joined',
  685. roomName,
  686. id,
  687. ...props
  688. });
  689. }
  690. /**
  691. * Notify external application (if API is enabled) that local user has left the conference.
  692. *
  693. * @param {string} roomName - User id.
  694. * @returns {void}
  695. */
  696. notifyConferenceLeft(roomName: string) {
  697. this._sendEvent({
  698. name: 'video-conference-left',
  699. roomName
  700. });
  701. }
  702. /**
  703. * Notify external application (if API is enabled) that we are ready to be
  704. * closed.
  705. *
  706. * @returns {void}
  707. */
  708. notifyReadyToClose() {
  709. this._sendEvent({ name: 'video-ready-to-close' });
  710. }
  711. /**
  712. * Notify external application (if API is enabled) that a suspend event in host computer.
  713. *
  714. * @returns {void}
  715. */
  716. notifySuspendDetected() {
  717. this._sendEvent({ name: 'suspend-detected' });
  718. }
  719. /**
  720. * Notify external application (if API is enabled) for audio muted status
  721. * changed.
  722. *
  723. * @param {boolean} muted - The new muted status.
  724. * @returns {void}
  725. */
  726. notifyAudioMutedStatusChanged(muted: boolean) {
  727. this._sendEvent({
  728. name: 'audio-mute-status-changed',
  729. muted
  730. });
  731. }
  732. /**
  733. * Notify external application (if API is enabled) for video muted status
  734. * changed.
  735. *
  736. * @param {boolean} muted - The new muted status.
  737. * @returns {void}
  738. */
  739. notifyVideoMutedStatusChanged(muted: boolean) {
  740. this._sendEvent({
  741. name: 'video-mute-status-changed',
  742. muted
  743. });
  744. }
  745. /**
  746. * Notify external application (if API is enabled) for audio availability
  747. * changed.
  748. *
  749. * @param {boolean} available - True if available and false otherwise.
  750. * @returns {void}
  751. */
  752. notifyAudioAvailabilityChanged(available: boolean) {
  753. audioAvailable = available;
  754. this._sendEvent({
  755. name: 'audio-availability-changed',
  756. available
  757. });
  758. }
  759. /**
  760. * Notify external application (if API is enabled) for video available
  761. * status changed.
  762. *
  763. * @param {boolean} available - True if available and false otherwise.
  764. * @returns {void}
  765. */
  766. notifyVideoAvailabilityChanged(available: boolean) {
  767. videoAvailable = available;
  768. this._sendEvent({
  769. name: 'video-availability-changed',
  770. available
  771. });
  772. }
  773. /**
  774. * Notify external application (if API is enabled) that the on stage
  775. * participant has changed.
  776. *
  777. * @param {string} id - User id of the new on stage participant.
  778. * @returns {void}
  779. */
  780. notifyOnStageParticipantChanged(id: string) {
  781. this._sendEvent({
  782. name: 'on-stage-participant-changed',
  783. id
  784. });
  785. }
  786. /**
  787. * Notify external application of an unexpected camera-related error having
  788. * occurred.
  789. *
  790. * @param {string} type - The type of the camera error.
  791. * @param {string} message - Additional information about the error.
  792. * @returns {void}
  793. */
  794. notifyOnCameraError(type: string, message: string) {
  795. this._sendEvent({
  796. name: 'camera-error',
  797. type,
  798. message
  799. });
  800. }
  801. /**
  802. * Notify external application of an unexpected mic-related error having
  803. * occurred.
  804. *
  805. * @param {string} type - The type of the mic error.
  806. * @param {string} message - Additional information about the error.
  807. * @returns {void}
  808. */
  809. notifyOnMicError(type: string, message: string) {
  810. this._sendEvent({
  811. name: 'mic-error',
  812. type,
  813. message
  814. });
  815. }
  816. /**
  817. * Notify external application (if API is enabled) that conference feedback
  818. * has been submitted. Intended to be used in conjunction with the
  819. * submit-feedback command to get notified if feedback was submitted.
  820. *
  821. * @param {string} error - A failure message, if any.
  822. * @returns {void}
  823. */
  824. notifyFeedbackSubmitted(error: string) {
  825. this._sendEvent({
  826. name: 'feedback-submitted',
  827. error
  828. });
  829. }
  830. /**
  831. * Notify external application (if API is enabled) that the feedback prompt
  832. * has been displayed.
  833. *
  834. * @returns {void}
  835. */
  836. notifyFeedbackPromptDisplayed() {
  837. this._sendEvent({ name: 'feedback-prompt-displayed' });
  838. }
  839. /**
  840. * Notify external application (if API is enabled) that the display
  841. * configuration of the filmstrip has been changed.
  842. *
  843. * @param {boolean} visible - Whether or not the filmstrip has been set to
  844. * be displayed or hidden.
  845. * @returns {void}
  846. */
  847. notifyFilmstripDisplayChanged(visible: boolean) {
  848. this._sendEvent({
  849. name: 'filmstrip-display-changed',
  850. visible
  851. });
  852. }
  853. /**
  854. * Notify external application of a participant, remote or local, being
  855. * removed from the conference by another participant.
  856. *
  857. * @param {string} kicked - The ID of the participant removed from the
  858. * conference.
  859. * @param {string} kicker - The ID of the participant that removed the
  860. * other participant.
  861. * @returns {void}
  862. */
  863. notifyKickedOut(kicked: Object, kicker: Object) {
  864. this._sendEvent({
  865. name: 'participant-kicked-out',
  866. kicked,
  867. kicker
  868. });
  869. }
  870. /**
  871. * Notify external application of the current meeting requiring a password
  872. * to join.
  873. *
  874. * @returns {void}
  875. */
  876. notifyOnPasswordRequired() {
  877. this._sendEvent({ name: 'password-required' });
  878. }
  879. /**
  880. * Notify external application (if API is enabled) that the screen sharing
  881. * has been turned on/off.
  882. *
  883. * @param {boolean} on - True if screen sharing is enabled.
  884. * @param {Object} details - Additional information about the screen
  885. * sharing.
  886. * @param {string} details.sourceType - Type of device or window the screen
  887. * share is capturing.
  888. * @returns {void}
  889. */
  890. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  891. this._sendEvent({
  892. name: 'screen-sharing-status-changed',
  893. on,
  894. details
  895. });
  896. }
  897. /**
  898. * Notify external application (if API is enabled) that the dominant speaker
  899. * has been turned on/off.
  900. *
  901. * @param {string} id - Id of the dominant participant.
  902. * @returns {void}
  903. */
  904. notifyDominantSpeakerChanged(id: string) {
  905. this._sendEvent({
  906. name: 'dominant-speaker-changed',
  907. id
  908. });
  909. }
  910. /**
  911. * Notify external application (if API is enabled) that the conference
  912. * changed their subject.
  913. *
  914. * @param {string} subject - Conference subject.
  915. * @returns {void}
  916. */
  917. notifySubjectChanged(subject: string) {
  918. this._sendEvent({
  919. name: 'subject-change',
  920. subject
  921. });
  922. }
  923. /**
  924. * Notify external application (if API is enabled) that tile view has been
  925. * entered or exited.
  926. *
  927. * @param {string} enabled - True if tile view is currently displayed, false
  928. * otherwise.
  929. * @returns {void}
  930. */
  931. notifyTileViewChanged(enabled: boolean) {
  932. this._sendEvent({
  933. name: 'tile-view-changed',
  934. enabled
  935. });
  936. }
  937. /**
  938. * Notify external application (if API is enabled) that the localStorage has changed.
  939. *
  940. * @param {string} localStorageContent - The new localStorageContent.
  941. * @returns {void}
  942. */
  943. notifyLocalStorageChanged(localStorageContent: string) {
  944. this._sendEvent({
  945. name: 'local-storage-changed',
  946. localStorageContent
  947. });
  948. }
  949. /**
  950. * Notify external application (if API is enabled) that user updated their hand raised.
  951. *
  952. * @param {string} id - User id.
  953. * @param {boolean} handRaised - Whether user has raised hand.
  954. * @returns {void}
  955. */
  956. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  957. this._sendEvent({
  958. name: 'raise-hand-updated',
  959. handRaised,
  960. id
  961. });
  962. }
  963. /**
  964. * Disposes the allocated resources.
  965. *
  966. * @returns {void}
  967. */
  968. dispose() {
  969. if (this._enabled) {
  970. this._enabled = false;
  971. }
  972. }
  973. }
  974. export default new API();