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

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