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

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