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.

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