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.

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