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 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. sendTones,
  10. setPassword,
  11. setSubject
  12. } from '../../react/features/base/conference';
  13. import { parseJWTFromURLParams } from '../../react/features/base/jwt';
  14. import {
  15. processExternalDeviceRequest
  16. } from '../../react/features/device-selection/functions';
  17. import { setE2EEKey } from '../../react/features/e2ee';
  18. import { invite } from '../../react/features/invite';
  19. import { muteAllParticipants } from '../../react/features/remote-video-menu/actions';
  20. import { toggleTileView } from '../../react/features/video-layout';
  21. import { setVideoQuality } from '../../react/features/video-quality';
  22. import { getJitsiMeetTransport } from '../transport';
  23. import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
  24. const logger = Logger.getLogger(__filename);
  25. declare var APP: Object;
  26. /**
  27. * List of the available commands.
  28. */
  29. let commands = {};
  30. /**
  31. * The state of screen sharing(started/stopped) before the screen sharing is
  32. * enabled and initialized.
  33. * NOTE: This flag help us to cache the state and use it if toggle-share-screen
  34. * was received before the initialization.
  35. */
  36. let initialScreenSharingState = false;
  37. /**
  38. * The transport instance used for communication with external apps.
  39. *
  40. * @type {Transport}
  41. */
  42. const transport = getJitsiMeetTransport();
  43. /**
  44. * The current audio availability.
  45. *
  46. * @type {boolean}
  47. */
  48. let audioAvailable = true;
  49. /**
  50. * The current video availability.
  51. *
  52. * @type {boolean}
  53. */
  54. let videoAvailable = true;
  55. /**
  56. * Initializes supported commands.
  57. *
  58. * @returns {void}
  59. */
  60. function initCommands() {
  61. commands = {
  62. 'display-name': displayName => {
  63. sendAnalytics(createApiEvent('display.name.changed'));
  64. APP.conference.changeLocalDisplayName(displayName);
  65. },
  66. 'mute-everyone': () => {
  67. sendAnalytics(createApiEvent('muted-everyone'));
  68. const participants = APP.store.getState()['features/base/participants'];
  69. const localIds = participants
  70. .filter(participant => participant.local)
  71. .filter(participant => participant.role === 'moderator')
  72. .map(participant => participant.id);
  73. APP.store.dispatch(muteAllParticipants(localIds));
  74. },
  75. 'password': password => {
  76. const { conference, passwordRequired }
  77. = APP.store.getState()['features/base/conference'];
  78. if (passwordRequired) {
  79. sendAnalytics(createApiEvent('submit.password'));
  80. APP.store.dispatch(setPassword(
  81. passwordRequired,
  82. passwordRequired.join,
  83. password
  84. ));
  85. } else {
  86. sendAnalytics(createApiEvent('password.changed'));
  87. APP.store.dispatch(setPassword(
  88. conference,
  89. conference.lock,
  90. password
  91. ));
  92. }
  93. },
  94. 'proxy-connection-event': event => {
  95. APP.conference.onProxyConnectionEvent(event);
  96. },
  97. 'send-tones': (options = {}) => {
  98. const { duration, tones, pause } = options;
  99. APP.store.dispatch(sendTones(tones, duration, pause));
  100. },
  101. 'subject': subject => {
  102. sendAnalytics(createApiEvent('subject.changed'));
  103. APP.store.dispatch(setSubject(subject));
  104. },
  105. 'submit-feedback': feedback => {
  106. sendAnalytics(createApiEvent('submit.feedback'));
  107. APP.conference.submitFeedback(feedback.score, feedback.message);
  108. },
  109. 'toggle-audio': () => {
  110. sendAnalytics(createApiEvent('toggle-audio'));
  111. logger.log('Audio toggle: API command received');
  112. APP.conference.toggleAudioMuted(false /* no UI */);
  113. },
  114. 'toggle-video': () => {
  115. sendAnalytics(createApiEvent('toggle-video'));
  116. logger.log('Video toggle: API command received');
  117. APP.conference.toggleVideoMuted(false /* no UI */);
  118. },
  119. 'toggle-film-strip': () => {
  120. sendAnalytics(createApiEvent('film.strip.toggled'));
  121. APP.UI.toggleFilmstrip();
  122. },
  123. 'toggle-chat': () => {
  124. sendAnalytics(createApiEvent('chat.toggled'));
  125. APP.UI.toggleChat();
  126. },
  127. /**
  128. * Callback to invoke when the "toggle-share-screen" command is received.
  129. *
  130. * @param {Object} options - Additional details of how to perform
  131. * the action. Note this parameter is undocumented and experimental.
  132. * @param {boolean} options.enable - Whether trying to enable screen
  133. * sharing or to turn it off.
  134. * @returns {void}
  135. */
  136. 'toggle-share-screen': (options = {}) => {
  137. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  138. toggleScreenSharing(options.enable);
  139. },
  140. 'toggle-tile-view': () => {
  141. sendAnalytics(createApiEvent('tile-view.toggled'));
  142. APP.store.dispatch(toggleTileView());
  143. },
  144. 'video-hangup': (showFeedbackDialog = true) => {
  145. sendAnalytics(createApiEvent('video.hangup'));
  146. APP.conference.hangup(showFeedbackDialog);
  147. },
  148. 'email': email => {
  149. sendAnalytics(createApiEvent('email.changed'));
  150. APP.conference.changeLocalEmail(email);
  151. },
  152. 'avatar-url': avatarUrl => {
  153. sendAnalytics(createApiEvent('avatar.url.changed'));
  154. APP.conference.changeLocalAvatarUrl(avatarUrl);
  155. },
  156. 'send-endpoint-text-message': (to, text) => {
  157. logger.debug('Send endpoint message command received');
  158. try {
  159. APP.conference.sendEndpointMessage(to, {
  160. name: ENDPOINT_TEXT_MESSAGE_NAME,
  161. text
  162. });
  163. } catch (err) {
  164. logger.error('Failed sending endpoint text message', err);
  165. }
  166. },
  167. 'e2ee-key': key => {
  168. logger.debug('Set E2EE key command received');
  169. APP.store.dispatch(setE2EEKey(key));
  170. },
  171. 'set-video-quality': frameHeight => {
  172. logger.debug('Set video quality command received');
  173. sendAnalytics(createApiEvent('set.video.quality'));
  174. APP.store.dispatch(setVideoQuality(frameHeight));
  175. }
  176. };
  177. transport.on('event', ({ data, name }) => {
  178. if (name && commands[name]) {
  179. commands[name](...data);
  180. return true;
  181. }
  182. return false;
  183. });
  184. transport.on('request', (request, callback) => {
  185. const { dispatch, getState } = APP.store;
  186. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  187. return true;
  188. }
  189. const { name } = request;
  190. switch (name) {
  191. case 'invite': {
  192. const { invitees } = request;
  193. if (!Array.isArray(invitees) || invitees.length === 0) {
  194. callback({
  195. error: new Error('Unexpected format of invitees')
  196. });
  197. break;
  198. }
  199. // The store should be already available because API.init is called
  200. // on appWillMount action.
  201. APP.store.dispatch(
  202. invite(invitees, true))
  203. .then(failedInvitees => {
  204. let error;
  205. let result;
  206. if (failedInvitees.length) {
  207. error = new Error('One or more invites failed!');
  208. } else {
  209. result = true;
  210. }
  211. callback({
  212. error,
  213. result
  214. });
  215. });
  216. break;
  217. }
  218. case 'is-audio-muted':
  219. callback(APP.conference.isLocalAudioMuted());
  220. break;
  221. case 'is-video-muted':
  222. callback(APP.conference.isLocalVideoMuted());
  223. break;
  224. case 'is-audio-available':
  225. callback(audioAvailable);
  226. break;
  227. case 'is-video-available':
  228. callback(videoAvailable);
  229. break;
  230. default:
  231. return false;
  232. }
  233. return true;
  234. });
  235. }
  236. /**
  237. * Listens for desktop/screen sharing enabled events and toggles the screen
  238. * sharing if needed.
  239. *
  240. * @param {boolean} enabled - Current screen sharing enabled status.
  241. * @returns {void}
  242. */
  243. function onDesktopSharingEnabledChanged(enabled = false) {
  244. if (enabled && initialScreenSharingState) {
  245. toggleScreenSharing();
  246. }
  247. }
  248. /**
  249. * Check whether the API should be enabled or not.
  250. *
  251. * @returns {boolean}
  252. */
  253. function shouldBeEnabled() {
  254. return (
  255. typeof API_ID === 'number'
  256. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  257. // the location/URL because then it is very likely that the Jitsi
  258. // Meet (Web) app is being used by an external/wrapping (Web) app
  259. // and, consequently, the latter will need to communicate with the
  260. // former. (The described logic is merely a heuristic though.)
  261. || parseJWTFromURLParams());
  262. }
  263. /**
  264. * Executes on toggle-share-screen command.
  265. *
  266. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  267. * disable screensharing. If not defined, the application will automatically
  268. * attempt to toggle between enabled and disabled. This boolean is useful for
  269. * explicitly setting desired screensharing state.
  270. * @returns {void}
  271. */
  272. function toggleScreenSharing(enable) {
  273. if (APP.conference.isDesktopSharingEnabled) {
  274. // eslint-disable-next-line no-empty-function
  275. APP.conference.toggleScreenSharing(enable).catch(() => {});
  276. } else {
  277. initialScreenSharingState = !initialScreenSharingState;
  278. }
  279. }
  280. /**
  281. * Implements API class that communicates with external API class and provides
  282. * interface to access Jitsi Meet features by external applications that embed
  283. * Jitsi Meet.
  284. */
  285. class API {
  286. _enabled: boolean;
  287. /**
  288. * Initializes the API. Setups message event listeners that will receive
  289. * information from external applications that embed Jitsi Meet. It also
  290. * sends a message to the external application that API is initialized.
  291. *
  292. * @param {Object} options - Optional parameters.
  293. * @returns {void}
  294. */
  295. init() {
  296. if (!shouldBeEnabled()) {
  297. return;
  298. }
  299. /**
  300. * Current status (enabled/disabled) of API.
  301. *
  302. * @private
  303. * @type {boolean}
  304. */
  305. this._enabled = true;
  306. APP.conference.addListener(
  307. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  308. onDesktopSharingEnabledChanged);
  309. initCommands();
  310. }
  311. /**
  312. * Notify external application (if API is enabled) that the large video
  313. * visibility changed.
  314. *
  315. * @param {boolean} isHidden - True if the large video is hidden and false
  316. * otherwise.
  317. * @returns {void}
  318. */
  319. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  320. this._sendEvent({
  321. name: 'large-video-visibility-changed',
  322. isVisible: !isHidden
  323. });
  324. }
  325. /**
  326. * Notifies the external application (spot) that the local jitsi-participant
  327. * has a status update.
  328. *
  329. * @param {Object} event - The message to pass onto spot.
  330. * @returns {void}
  331. */
  332. sendProxyConnectionEvent(event: Object) {
  333. this._sendEvent({
  334. name: 'proxy-connection-event',
  335. ...event
  336. });
  337. }
  338. /**
  339. * Sends event to the external application.
  340. *
  341. * @param {Object} event - The event to be sent.
  342. * @returns {void}
  343. */
  344. _sendEvent(event: Object = {}) {
  345. if (this._enabled) {
  346. transport.sendEvent(event);
  347. }
  348. }
  349. /**
  350. * Notify external application (if API is enabled) that message was sent.
  351. *
  352. * @param {string} message - Message body.
  353. * @param {boolean} privateMessage - True if the message was a private message.
  354. * @returns {void}
  355. */
  356. notifySendingChatMessage(message: string, privateMessage: boolean) {
  357. this._sendEvent({
  358. name: 'outgoing-message',
  359. message,
  360. privateMessage
  361. });
  362. }
  363. /**
  364. * Notify external application (if API is enabled) that message was
  365. * received.
  366. *
  367. * @param {Object} options - Object with the message properties.
  368. * @returns {void}
  369. */
  370. notifyReceivedChatMessage(
  371. { body, id, nick, ts }: {
  372. body: *, id: string, nick: string, ts: *
  373. } = {}) {
  374. if (APP.conference.isLocalId(id)) {
  375. return;
  376. }
  377. this._sendEvent({
  378. name: 'incoming-message',
  379. from: id,
  380. message: body,
  381. nick,
  382. stamp: ts
  383. });
  384. }
  385. /**
  386. * Notify external application (if API is enabled) that user joined the
  387. * conference.
  388. *
  389. * @param {string} id - User id.
  390. * @param {Object} props - The display name of the user.
  391. * @returns {void}
  392. */
  393. notifyUserJoined(id: string, props: Object) {
  394. this._sendEvent({
  395. name: 'participant-joined',
  396. id,
  397. ...props
  398. });
  399. }
  400. /**
  401. * Notify external application (if API is enabled) that user left the
  402. * conference.
  403. *
  404. * @param {string} id - User id.
  405. * @returns {void}
  406. */
  407. notifyUserLeft(id: string) {
  408. this._sendEvent({
  409. name: 'participant-left',
  410. id
  411. });
  412. }
  413. /**
  414. * Notify external application (if API is enabled) that the user role
  415. * has changed.
  416. *
  417. * @param {string} id - User id.
  418. * @param {string} role - The new user role.
  419. * @returns {void}
  420. */
  421. notifyUserRoleChanged(id: string, role: string) {
  422. this._sendEvent({
  423. name: 'participant-role-changed',
  424. id,
  425. role
  426. });
  427. }
  428. /**
  429. * Notify external application (if API is enabled) that user changed their
  430. * avatar.
  431. *
  432. * @param {string} id - User id.
  433. * @param {string} avatarURL - The new avatar URL of the participant.
  434. * @returns {void}
  435. */
  436. notifyAvatarChanged(id: string, avatarURL: string) {
  437. this._sendEvent({
  438. name: 'avatar-changed',
  439. avatarURL,
  440. id
  441. });
  442. }
  443. /**
  444. * Notify external application (if API is enabled) that user received
  445. * a text message through datachannels.
  446. *
  447. * @param {Object} data - The event data.
  448. * @returns {void}
  449. */
  450. notifyEndpointTextMessageReceived(data: Object) {
  451. this._sendEvent({
  452. name: 'endpoint-text-message-received',
  453. data
  454. });
  455. }
  456. /**
  457. * Notify external application (if API is enabled) that the device list has
  458. * changed.
  459. *
  460. * @param {Object} devices - The new device list.
  461. * @returns {void}
  462. */
  463. notifyDeviceListChanged(devices: Object) {
  464. this._sendEvent({
  465. name: 'device-list-changed',
  466. devices });
  467. }
  468. /**
  469. * Notify external application (if API is enabled) that user changed their
  470. * nickname.
  471. *
  472. * @param {string} id - User id.
  473. * @param {string} displayname - User nickname.
  474. * @param {string} formattedDisplayName - The display name shown in Jitsi
  475. * meet's UI for the user.
  476. * @returns {void}
  477. */
  478. notifyDisplayNameChanged(
  479. id: string,
  480. { displayName, formattedDisplayName }: Object) {
  481. this._sendEvent({
  482. name: 'display-name-change',
  483. displayname: displayName,
  484. formattedDisplayName,
  485. id
  486. });
  487. }
  488. /**
  489. * Notify external application (if API is enabled) that user changed their
  490. * email.
  491. *
  492. * @param {string} id - User id.
  493. * @param {string} email - The new email of the participant.
  494. * @returns {void}
  495. */
  496. notifyEmailChanged(
  497. id: string,
  498. { email }: Object) {
  499. this._sendEvent({
  500. name: 'email-change',
  501. email,
  502. id
  503. });
  504. }
  505. /**
  506. * Notify external application (if API is enabled) that the conference has
  507. * been joined.
  508. *
  509. * @param {string} roomName - The room name.
  510. * @param {string} id - The id of the local user.
  511. * @param {Object} props - The display name and avatar URL of the local
  512. * user.
  513. * @returns {void}
  514. */
  515. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  516. this._sendEvent({
  517. name: 'video-conference-joined',
  518. roomName,
  519. id,
  520. ...props
  521. });
  522. }
  523. /**
  524. * Notify external application (if API is enabled) that user changed their
  525. * nickname.
  526. *
  527. * @param {string} roomName - User id.
  528. * @returns {void}
  529. */
  530. notifyConferenceLeft(roomName: string) {
  531. this._sendEvent({
  532. name: 'video-conference-left',
  533. roomName
  534. });
  535. }
  536. /**
  537. * Notify external application (if API is enabled) that we are ready to be
  538. * closed.
  539. *
  540. * @returns {void}
  541. */
  542. notifyReadyToClose() {
  543. this._sendEvent({ name: 'video-ready-to-close' });
  544. }
  545. /**
  546. * Notify external application (if API is enabled) that a suspend event in host computer.
  547. *
  548. * @returns {void}
  549. */
  550. notifySuspendDetected() {
  551. this._sendEvent({ name: 'suspend-detected' });
  552. }
  553. /**
  554. * Notify external application (if API is enabled) for audio muted status
  555. * changed.
  556. *
  557. * @param {boolean} muted - The new muted status.
  558. * @returns {void}
  559. */
  560. notifyAudioMutedStatusChanged(muted: boolean) {
  561. this._sendEvent({
  562. name: 'audio-mute-status-changed',
  563. muted
  564. });
  565. }
  566. /**
  567. * Notify external application (if API is enabled) for video muted status
  568. * changed.
  569. *
  570. * @param {boolean} muted - The new muted status.
  571. * @returns {void}
  572. */
  573. notifyVideoMutedStatusChanged(muted: boolean) {
  574. this._sendEvent({
  575. name: 'video-mute-status-changed',
  576. muted
  577. });
  578. }
  579. /**
  580. * Notify external application (if API is enabled) for audio availability
  581. * changed.
  582. *
  583. * @param {boolean} available - True if available and false otherwise.
  584. * @returns {void}
  585. */
  586. notifyAudioAvailabilityChanged(available: boolean) {
  587. audioAvailable = available;
  588. this._sendEvent({
  589. name: 'audio-availability-changed',
  590. available
  591. });
  592. }
  593. /**
  594. * Notify external application (if API is enabled) for video available
  595. * status changed.
  596. *
  597. * @param {boolean} available - True if available and false otherwise.
  598. * @returns {void}
  599. */
  600. notifyVideoAvailabilityChanged(available: boolean) {
  601. videoAvailable = available;
  602. this._sendEvent({
  603. name: 'video-availability-changed',
  604. available
  605. });
  606. }
  607. /**
  608. * Notify external application (if API is enabled) that the on stage
  609. * participant has changed.
  610. *
  611. * @param {string} id - User id of the new on stage participant.
  612. * @returns {void}
  613. */
  614. notifyOnStageParticipantChanged(id: string) {
  615. this._sendEvent({
  616. name: 'on-stage-participant-changed',
  617. id
  618. });
  619. }
  620. /**
  621. * Notify external application of an unexpected camera-related error having
  622. * occurred.
  623. *
  624. * @param {string} type - The type of the camera error.
  625. * @param {string} message - Additional information about the error.
  626. * @returns {void}
  627. */
  628. notifyOnCameraError(type: string, message: string) {
  629. this._sendEvent({
  630. name: 'camera-error',
  631. type,
  632. message
  633. });
  634. }
  635. /**
  636. * Notify external application of an unexpected mic-related error having
  637. * occurred.
  638. *
  639. * @param {string} type - The type of the mic error.
  640. * @param {string} message - Additional information about the error.
  641. * @returns {void}
  642. */
  643. notifyOnMicError(type: string, message: string) {
  644. this._sendEvent({
  645. name: 'mic-error',
  646. type,
  647. message
  648. });
  649. }
  650. /**
  651. * Notify external application (if API is enabled) that conference feedback
  652. * has been submitted. Intended to be used in conjunction with the
  653. * submit-feedback command to get notified if feedback was submitted.
  654. *
  655. * @param {string} error - A failure message, if any.
  656. * @returns {void}
  657. */
  658. notifyFeedbackSubmitted(error: string) {
  659. this._sendEvent({
  660. name: 'feedback-submitted',
  661. error
  662. });
  663. }
  664. /**
  665. * Notify external application (if API is enabled) that the feedback prompt
  666. * has been displayed.
  667. *
  668. * @returns {void}
  669. */
  670. notifyFeedbackPromptDisplayed() {
  671. this._sendEvent({ name: 'feedback-prompt-displayed' });
  672. }
  673. /**
  674. * Notify external application (if API is enabled) that the display
  675. * configuration of the filmstrip has been changed.
  676. *
  677. * @param {boolean} visible - Whether or not the filmstrip has been set to
  678. * be displayed or hidden.
  679. * @returns {void}
  680. */
  681. notifyFilmstripDisplayChanged(visible: boolean) {
  682. this._sendEvent({
  683. name: 'filmstrip-display-changed',
  684. visible
  685. });
  686. }
  687. /**
  688. * Notify external application of a participant, remote or local, being
  689. * removed from the conference by another participant.
  690. *
  691. * @param {string} kicked - The ID of the participant removed from the
  692. * conference.
  693. * @param {string} kicker - The ID of the participant that removed the
  694. * other participant.
  695. * @returns {void}
  696. */
  697. notifyKickedOut(kicked: Object, kicker: Object) {
  698. this._sendEvent({
  699. name: 'participant-kicked-out',
  700. kicked,
  701. kicker
  702. });
  703. }
  704. /**
  705. * Notify external application of the current meeting requiring a password
  706. * to join.
  707. *
  708. * @returns {void}
  709. */
  710. notifyOnPasswordRequired() {
  711. this._sendEvent({ name: 'password-required' });
  712. }
  713. /**
  714. * Notify external application (if API is enabled) that the screen sharing
  715. * has been turned on/off.
  716. *
  717. * @param {boolean} on - True if screen sharing is enabled.
  718. * @param {Object} details - Additional information about the screen
  719. * sharing.
  720. * @param {string} details.sourceType - Type of device or window the screen
  721. * share is capturing.
  722. * @returns {void}
  723. */
  724. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  725. this._sendEvent({
  726. name: 'screen-sharing-status-changed',
  727. on,
  728. details
  729. });
  730. }
  731. /**
  732. * Notify external application (if API is enabled) that the dominant speaker
  733. * has been turned on/off.
  734. *
  735. * @param {string} id - Id of the dominant participant.
  736. * @returns {void}
  737. */
  738. notifyDominantSpeakerChanged(id: string) {
  739. this._sendEvent({
  740. name: 'dominant-speaker-changed',
  741. id
  742. });
  743. }
  744. /**
  745. * Notify external application (if API is enabled) that the conference
  746. * changed their subject.
  747. *
  748. * @param {string} subject - Conference subject.
  749. * @returns {void}
  750. */
  751. notifySubjectChanged(subject: string) {
  752. this._sendEvent({
  753. name: 'subject-change',
  754. subject
  755. });
  756. }
  757. /**
  758. * Notify external application (if API is enabled) that tile view has been
  759. * entered or exited.
  760. *
  761. * @param {string} enabled - True if tile view is currently displayed, false
  762. * otherwise.
  763. * @returns {void}
  764. */
  765. notifyTileViewChanged(enabled: boolean) {
  766. this._sendEvent({
  767. name: 'tile-view-changed',
  768. enabled
  769. });
  770. }
  771. /**
  772. * Disposes the allocated resources.
  773. *
  774. * @returns {void}
  775. */
  776. dispose() {
  777. if (this._enabled) {
  778. this._enabled = false;
  779. APP.conference.removeListener(
  780. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  781. onDesktopSharingEnabledChanged);
  782. }
  783. }
  784. }
  785. export default new API();