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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  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. case 'get-content-sharing-participants': {
  387. const tracks = getState()['features/base/tracks'];
  388. const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId);
  389. callback({
  390. sharingParticipantIds
  391. });
  392. break;
  393. }
  394. case 'get-livestream-url': {
  395. const state = APP.store.getState();
  396. const conference = getCurrentConference(state);
  397. let livestreamUrl;
  398. if (conference) {
  399. const activeSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  400. livestreamUrl = activeSession?.liveStreamViewURL;
  401. } else {
  402. logger.error('Conference is not defined');
  403. }
  404. callback({
  405. livestreamUrl
  406. });
  407. break;
  408. }
  409. default:
  410. return false;
  411. }
  412. return true;
  413. });
  414. }
  415. /**
  416. * Check whether the API should be enabled or not.
  417. *
  418. * @returns {boolean}
  419. */
  420. function shouldBeEnabled() {
  421. return (
  422. typeof API_ID === 'number'
  423. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  424. // the location/URL because then it is very likely that the Jitsi
  425. // Meet (Web) app is being used by an external/wrapping (Web) app
  426. // and, consequently, the latter will need to communicate with the
  427. // former. (The described logic is merely a heuristic though.)
  428. || parseJWTFromURLParams());
  429. }
  430. /**
  431. * Executes on toggle-share-screen command.
  432. *
  433. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  434. * disable screensharing. If not defined, the application will automatically
  435. * attempt to toggle between enabled and disabled. This boolean is useful for
  436. * explicitly setting desired screensharing state.
  437. * @returns {void}
  438. */
  439. function toggleScreenSharing(enable) {
  440. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  441. APP.conference.toggleScreenSharing(enable).catch(() => {
  442. logger.warn('Failed to toggle screen-sharing');
  443. });
  444. }
  445. }
  446. /**
  447. * Implements API class that communicates with external API class and provides
  448. * interface to access Jitsi Meet features by external applications that embed
  449. * Jitsi Meet.
  450. */
  451. class API {
  452. _enabled: boolean;
  453. /**
  454. * Initializes the API. Setups message event listeners that will receive
  455. * information from external applications that embed Jitsi Meet. It also
  456. * sends a message to the external application that API is initialized.
  457. *
  458. * @param {Object} options - Optional parameters.
  459. * @returns {void}
  460. */
  461. init() {
  462. if (!shouldBeEnabled()) {
  463. return;
  464. }
  465. /**
  466. * Current status (enabled/disabled) of API.
  467. *
  468. * @private
  469. * @type {boolean}
  470. */
  471. this._enabled = true;
  472. initCommands();
  473. }
  474. /**
  475. * Notify external application (if API is enabled) that the large video
  476. * visibility changed.
  477. *
  478. * @param {boolean} isHidden - True if the large video is hidden and false
  479. * otherwise.
  480. * @returns {void}
  481. */
  482. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  483. this._sendEvent({
  484. name: 'large-video-visibility-changed',
  485. isVisible: !isHidden
  486. });
  487. }
  488. /**
  489. * Notifies the external application (spot) that the local jitsi-participant
  490. * has a status update.
  491. *
  492. * @param {Object} event - The message to pass onto spot.
  493. * @returns {void}
  494. */
  495. sendProxyConnectionEvent(event: Object) {
  496. this._sendEvent({
  497. name: 'proxy-connection-event',
  498. ...event
  499. });
  500. }
  501. /**
  502. * Sends event to the external application.
  503. *
  504. * @param {Object} event - The event to be sent.
  505. * @returns {void}
  506. */
  507. _sendEvent(event: Object = {}) {
  508. if (this._enabled) {
  509. transport.sendEvent(event);
  510. }
  511. }
  512. /**
  513. * Notify external application (if API is enabled) that the chat state has been updated.
  514. *
  515. * @param {number} unreadCount - The unread messages counter.
  516. * @param {boolean} isOpen - True if the chat panel is open.
  517. * @returns {void}
  518. */
  519. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  520. this._sendEvent({
  521. name: 'chat-updated',
  522. unreadCount,
  523. isOpen
  524. });
  525. }
  526. /**
  527. * Notify external application (if API is enabled) that message was sent.
  528. *
  529. * @param {string} message - Message body.
  530. * @param {boolean} privateMessage - True if the message was a private message.
  531. * @returns {void}
  532. */
  533. notifySendingChatMessage(message: string, privateMessage: boolean) {
  534. this._sendEvent({
  535. name: 'outgoing-message',
  536. message,
  537. privateMessage
  538. });
  539. }
  540. /**
  541. * Notify external application that the video quality setting has changed.
  542. *
  543. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  544. * @returns {void}
  545. */
  546. notifyVideoQualityChanged(videoQuality: number) {
  547. this._sendEvent({
  548. name: 'video-quality-changed',
  549. videoQuality
  550. });
  551. }
  552. /**
  553. * Notify external application (if API is enabled) that message was
  554. * received.
  555. *
  556. * @param {Object} options - Object with the message properties.
  557. * @returns {void}
  558. */
  559. notifyReceivedChatMessage(
  560. { body, id, nick, privateMessage, ts }: {
  561. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  562. } = {}) {
  563. if (APP.conference.isLocalId(id)) {
  564. return;
  565. }
  566. this._sendEvent({
  567. name: 'incoming-message',
  568. from: id,
  569. message: body,
  570. nick,
  571. privateMessage,
  572. stamp: ts
  573. });
  574. }
  575. /**
  576. * Notify external application (if API is enabled) that user joined the
  577. * conference.
  578. *
  579. * @param {string} id - User id.
  580. * @param {Object} props - The display name of the user.
  581. * @returns {void}
  582. */
  583. notifyUserJoined(id: string, props: Object) {
  584. this._sendEvent({
  585. name: 'participant-joined',
  586. id,
  587. ...props
  588. });
  589. }
  590. /**
  591. * Notify external application (if API is enabled) that user left the
  592. * conference.
  593. *
  594. * @param {string} id - User id.
  595. * @returns {void}
  596. */
  597. notifyUserLeft(id: string) {
  598. this._sendEvent({
  599. name: 'participant-left',
  600. id
  601. });
  602. }
  603. /**
  604. * Notify external application (if API is enabled) that the user role
  605. * has changed.
  606. *
  607. * @param {string} id - User id.
  608. * @param {string} role - The new user role.
  609. * @returns {void}
  610. */
  611. notifyUserRoleChanged(id: string, role: string) {
  612. this._sendEvent({
  613. name: 'participant-role-changed',
  614. id,
  615. role
  616. });
  617. }
  618. /**
  619. * Notify external application (if API is enabled) that user changed their
  620. * avatar.
  621. *
  622. * @param {string} id - User id.
  623. * @param {string} avatarURL - The new avatar URL of the participant.
  624. * @returns {void}
  625. */
  626. notifyAvatarChanged(id: string, avatarURL: string) {
  627. this._sendEvent({
  628. name: 'avatar-changed',
  629. avatarURL,
  630. id
  631. });
  632. }
  633. /**
  634. * Notify external application (if API is enabled) that user received
  635. * a text message through datachannels.
  636. *
  637. * @param {Object} data - The event data.
  638. * @returns {void}
  639. */
  640. notifyEndpointTextMessageReceived(data: Object) {
  641. this._sendEvent({
  642. name: 'endpoint-text-message-received',
  643. data
  644. });
  645. }
  646. /**
  647. * Notify external application (if API is enabled) that the list of sharing participants changed.
  648. *
  649. * @param {Object} data - The event data.
  650. * @returns {void}
  651. */
  652. notifySharingParticipantsChanged(data: Object) {
  653. this._sendEvent({
  654. name: 'content-sharing-participants-changed',
  655. data
  656. });
  657. }
  658. /**
  659. * Notify external application (if API is enabled) that the device list has
  660. * changed.
  661. *
  662. * @param {Object} devices - The new device list.
  663. * @returns {void}
  664. */
  665. notifyDeviceListChanged(devices: Object) {
  666. this._sendEvent({
  667. name: 'device-list-changed',
  668. devices
  669. });
  670. }
  671. /**
  672. * Notify external application (if API is enabled) that user changed their
  673. * nickname.
  674. *
  675. * @param {string} id - User id.
  676. * @param {string} displayname - User nickname.
  677. * @param {string} formattedDisplayName - The display name shown in Jitsi
  678. * meet's UI for the user.
  679. * @returns {void}
  680. */
  681. notifyDisplayNameChanged(
  682. id: string,
  683. { displayName, formattedDisplayName }: Object) {
  684. this._sendEvent({
  685. name: 'display-name-change',
  686. displayname: displayName,
  687. formattedDisplayName,
  688. id
  689. });
  690. }
  691. /**
  692. * Notify external application (if API is enabled) that user changed their
  693. * email.
  694. *
  695. * @param {string} id - User id.
  696. * @param {string} email - The new email of the participant.
  697. * @returns {void}
  698. */
  699. notifyEmailChanged(
  700. id: string,
  701. { email }: Object) {
  702. this._sendEvent({
  703. name: 'email-change',
  704. email,
  705. id
  706. });
  707. }
  708. /**
  709. * Notify external application (if API is enabled) that the an error has been logged.
  710. *
  711. * @param {string} logLevel - The message log level.
  712. * @param {Array} args - Array of strings composing the log message.
  713. * @returns {void}
  714. */
  715. notifyLog(logLevel: string, args: Array<string>) {
  716. this._sendEvent({
  717. name: 'log',
  718. logLevel,
  719. args
  720. });
  721. }
  722. /**
  723. * Notify external application (if API is enabled) that the conference has
  724. * been joined.
  725. *
  726. * @param {string} roomName - The room name.
  727. * @param {string} id - The id of the local user.
  728. * @param {Object} props - The display name and avatar URL of the local
  729. * user.
  730. * @returns {void}
  731. */
  732. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  733. this._sendEvent({
  734. name: 'video-conference-joined',
  735. roomName,
  736. id,
  737. ...props
  738. });
  739. }
  740. /**
  741. * Notify external application (if API is enabled) that local user has left the conference.
  742. *
  743. * @param {string} roomName - User id.
  744. * @returns {void}
  745. */
  746. notifyConferenceLeft(roomName: string) {
  747. this._sendEvent({
  748. name: 'video-conference-left',
  749. roomName
  750. });
  751. }
  752. /**
  753. * Notify external application (if API is enabled) that we are ready to be
  754. * closed.
  755. *
  756. * @returns {void}
  757. */
  758. notifyReadyToClose() {
  759. this._sendEvent({ name: 'video-ready-to-close' });
  760. }
  761. /**
  762. * Notify external application (if API is enabled) that a suspend event in host computer.
  763. *
  764. * @returns {void}
  765. */
  766. notifySuspendDetected() {
  767. this._sendEvent({ name: 'suspend-detected' });
  768. }
  769. /**
  770. * Notify external application (if API is enabled) for audio muted status
  771. * changed.
  772. *
  773. * @param {boolean} muted - The new muted status.
  774. * @returns {void}
  775. */
  776. notifyAudioMutedStatusChanged(muted: boolean) {
  777. this._sendEvent({
  778. name: 'audio-mute-status-changed',
  779. muted
  780. });
  781. }
  782. /**
  783. * Notify external application (if API is enabled) for video muted status
  784. * changed.
  785. *
  786. * @param {boolean} muted - The new muted status.
  787. * @returns {void}
  788. */
  789. notifyVideoMutedStatusChanged(muted: boolean) {
  790. this._sendEvent({
  791. name: 'video-mute-status-changed',
  792. muted
  793. });
  794. }
  795. /**
  796. * Notify external application (if API is enabled) for audio availability
  797. * changed.
  798. *
  799. * @param {boolean} available - True if available and false otherwise.
  800. * @returns {void}
  801. */
  802. notifyAudioAvailabilityChanged(available: boolean) {
  803. audioAvailable = available;
  804. this._sendEvent({
  805. name: 'audio-availability-changed',
  806. available
  807. });
  808. }
  809. /**
  810. * Notify external application (if API is enabled) for video available
  811. * status changed.
  812. *
  813. * @param {boolean} available - True if available and false otherwise.
  814. * @returns {void}
  815. */
  816. notifyVideoAvailabilityChanged(available: boolean) {
  817. videoAvailable = available;
  818. this._sendEvent({
  819. name: 'video-availability-changed',
  820. available
  821. });
  822. }
  823. /**
  824. * Notify external application (if API is enabled) that the on stage
  825. * participant has changed.
  826. *
  827. * @param {string} id - User id of the new on stage participant.
  828. * @returns {void}
  829. */
  830. notifyOnStageParticipantChanged(id: string) {
  831. this._sendEvent({
  832. name: 'on-stage-participant-changed',
  833. id
  834. });
  835. }
  836. /**
  837. * Notify external application of an unexpected camera-related error having
  838. * occurred.
  839. *
  840. * @param {string} type - The type of the camera error.
  841. * @param {string} message - Additional information about the error.
  842. * @returns {void}
  843. */
  844. notifyOnCameraError(type: string, message: string) {
  845. this._sendEvent({
  846. name: 'camera-error',
  847. type,
  848. message
  849. });
  850. }
  851. /**
  852. * Notify external application of an unexpected mic-related error having
  853. * occurred.
  854. *
  855. * @param {string} type - The type of the mic error.
  856. * @param {string} message - Additional information about the error.
  857. * @returns {void}
  858. */
  859. notifyOnMicError(type: string, message: string) {
  860. this._sendEvent({
  861. name: 'mic-error',
  862. type,
  863. message
  864. });
  865. }
  866. /**
  867. * Notify external application (if API is enabled) that conference feedback
  868. * has been submitted. Intended to be used in conjunction with the
  869. * submit-feedback command to get notified if feedback was submitted.
  870. *
  871. * @param {string} error - A failure message, if any.
  872. * @returns {void}
  873. */
  874. notifyFeedbackSubmitted(error: string) {
  875. this._sendEvent({
  876. name: 'feedback-submitted',
  877. error
  878. });
  879. }
  880. /**
  881. * Notify external application (if API is enabled) that the feedback prompt
  882. * has been displayed.
  883. *
  884. * @returns {void}
  885. */
  886. notifyFeedbackPromptDisplayed() {
  887. this._sendEvent({ name: 'feedback-prompt-displayed' });
  888. }
  889. /**
  890. * Notify external application (if API is enabled) that the display
  891. * configuration of the filmstrip has been changed.
  892. *
  893. * @param {boolean} visible - Whether or not the filmstrip has been set to
  894. * be displayed or hidden.
  895. * @returns {void}
  896. */
  897. notifyFilmstripDisplayChanged(visible: boolean) {
  898. this._sendEvent({
  899. name: 'filmstrip-display-changed',
  900. visible
  901. });
  902. }
  903. /**
  904. * Notify external application of a participant, remote or local, being
  905. * removed from the conference by another participant.
  906. *
  907. * @param {string} kicked - The ID of the participant removed from the
  908. * conference.
  909. * @param {string} kicker - The ID of the participant that removed the
  910. * other participant.
  911. * @returns {void}
  912. */
  913. notifyKickedOut(kicked: Object, kicker: Object) {
  914. this._sendEvent({
  915. name: 'participant-kicked-out',
  916. kicked,
  917. kicker
  918. });
  919. }
  920. /**
  921. * Notify external application of the current meeting requiring a password
  922. * to join.
  923. *
  924. * @returns {void}
  925. */
  926. notifyOnPasswordRequired() {
  927. this._sendEvent({ name: 'password-required' });
  928. }
  929. /**
  930. * Notify external application (if API is enabled) that the screen sharing
  931. * has been turned on/off.
  932. *
  933. * @param {boolean} on - True if screen sharing is enabled.
  934. * @param {Object} details - Additional information about the screen
  935. * sharing.
  936. * @param {string} details.sourceType - Type of device or window the screen
  937. * share is capturing.
  938. * @returns {void}
  939. */
  940. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  941. this._sendEvent({
  942. name: 'screen-sharing-status-changed',
  943. on,
  944. details
  945. });
  946. }
  947. /**
  948. * Notify external application (if API is enabled) that the dominant speaker
  949. * has been turned on/off.
  950. *
  951. * @param {string} id - Id of the dominant participant.
  952. * @returns {void}
  953. */
  954. notifyDominantSpeakerChanged(id: string) {
  955. this._sendEvent({
  956. name: 'dominant-speaker-changed',
  957. id
  958. });
  959. }
  960. /**
  961. * Notify external application (if API is enabled) that the conference
  962. * changed their subject.
  963. *
  964. * @param {string} subject - Conference subject.
  965. * @returns {void}
  966. */
  967. notifySubjectChanged(subject: string) {
  968. this._sendEvent({
  969. name: 'subject-change',
  970. subject
  971. });
  972. }
  973. /**
  974. * Notify external application (if API is enabled) that tile view has been
  975. * entered or exited.
  976. *
  977. * @param {string} enabled - True if tile view is currently displayed, false
  978. * otherwise.
  979. * @returns {void}
  980. */
  981. notifyTileViewChanged(enabled: boolean) {
  982. this._sendEvent({
  983. name: 'tile-view-changed',
  984. enabled
  985. });
  986. }
  987. /**
  988. * Notify external application (if API is enabled) that the localStorage has changed.
  989. *
  990. * @param {string} localStorageContent - The new localStorageContent.
  991. * @returns {void}
  992. */
  993. notifyLocalStorageChanged(localStorageContent: string) {
  994. this._sendEvent({
  995. name: 'local-storage-changed',
  996. localStorageContent
  997. });
  998. }
  999. /**
  1000. * Notify external application (if API is enabled) that user updated their hand raised.
  1001. *
  1002. * @param {string} id - User id.
  1003. * @param {boolean} handRaised - Whether user has raised hand.
  1004. * @returns {void}
  1005. */
  1006. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  1007. this._sendEvent({
  1008. name: 'raise-hand-updated',
  1009. handRaised,
  1010. id
  1011. });
  1012. }
  1013. /**
  1014. * Disposes the allocated resources.
  1015. *
  1016. * @returns {void}
  1017. */
  1018. dispose() {
  1019. if (this._enabled) {
  1020. this._enabled = false;
  1021. }
  1022. }
  1023. }
  1024. export default new API();