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

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