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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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. * Removes sensitive data from a mouse event.
  512. *
  513. * @param {MouseEvent} event - The mouse event to sanitize.
  514. * @returns {Object}
  515. */
  516. function sanitizeMouseEvent(event: MouseEvent) {
  517. const {
  518. clientX,
  519. clientY,
  520. movementX,
  521. movementY,
  522. offsetX,
  523. offsetY,
  524. pageX,
  525. pageY,
  526. x,
  527. y,
  528. screenX,
  529. screenY
  530. } = event;
  531. return {
  532. clientX,
  533. clientY,
  534. movementX,
  535. movementY,
  536. offsetX,
  537. offsetY,
  538. pageX,
  539. pageY,
  540. x,
  541. y,
  542. screenX,
  543. screenY
  544. };
  545. }
  546. /**
  547. * Implements API class that communicates with external API class and provides
  548. * interface to access Jitsi Meet features by external applications that embed
  549. * Jitsi Meet.
  550. */
  551. class API {
  552. _enabled: boolean;
  553. /**
  554. * Initializes the API. Setups message event listeners that will receive
  555. * information from external applications that embed Jitsi Meet. It also
  556. * sends a message to the external application that API is initialized.
  557. *
  558. * @param {Object} options - Optional parameters.
  559. * @returns {void}
  560. */
  561. init() {
  562. if (!shouldBeEnabled()) {
  563. return;
  564. }
  565. /**
  566. * Current status (enabled/disabled) of API.
  567. *
  568. * @private
  569. * @type {boolean}
  570. */
  571. this._enabled = true;
  572. initCommands();
  573. }
  574. /**
  575. * Notify external application (if API is enabled) that the large video
  576. * visibility changed.
  577. *
  578. * @param {boolean} isHidden - True if the large video is hidden and false
  579. * otherwise.
  580. * @returns {void}
  581. */
  582. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  583. this._sendEvent({
  584. name: 'large-video-visibility-changed',
  585. isVisible: !isHidden
  586. });
  587. }
  588. /**
  589. * Notifies the external application (spot) that the local jitsi-participant
  590. * has a status update.
  591. *
  592. * @param {Object} event - The message to pass onto spot.
  593. * @returns {void}
  594. */
  595. sendProxyConnectionEvent(event: Object) {
  596. this._sendEvent({
  597. name: 'proxy-connection-event',
  598. ...event
  599. });
  600. }
  601. /**
  602. * Sends event to the external application.
  603. *
  604. * @param {Object} event - The event to be sent.
  605. * @returns {void}
  606. */
  607. _sendEvent(event: Object = {}) {
  608. if (this._enabled) {
  609. transport.sendEvent(event);
  610. }
  611. }
  612. /**
  613. * Notify external application (if API is enabled) that the chat state has been updated.
  614. *
  615. * @param {number} unreadCount - The unread messages counter.
  616. * @param {boolean} isOpen - True if the chat panel is open.
  617. * @returns {void}
  618. */
  619. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  620. this._sendEvent({
  621. name: 'chat-updated',
  622. unreadCount,
  623. isOpen
  624. });
  625. }
  626. /**
  627. * Notify external application (if API is enabled) that message was sent.
  628. *
  629. * @param {string} message - Message body.
  630. * @param {boolean} privateMessage - True if the message was a private message.
  631. * @returns {void}
  632. */
  633. notifySendingChatMessage(message: string, privateMessage: boolean) {
  634. this._sendEvent({
  635. name: 'outgoing-message',
  636. message,
  637. privateMessage
  638. });
  639. }
  640. /**
  641. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  642. *
  643. * @param {MouseEvent} event - The mousemove event.
  644. * @returns {void}
  645. */
  646. notifyMouseEnter(event: MouseEvent) {
  647. this._sendEvent({
  648. name: 'mouse-enter',
  649. event: sanitizeMouseEvent(event)
  650. });
  651. }
  652. /**
  653. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  654. *
  655. * @param {MouseEvent} event - The mousemove event.
  656. * @returns {void}
  657. */
  658. notifyMouseLeave(event: MouseEvent) {
  659. this._sendEvent({
  660. name: 'mouse-leave',
  661. event: sanitizeMouseEvent(event)
  662. });
  663. }
  664. /**
  665. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  666. *
  667. * @param {MouseEvent} event - The mousemove event.
  668. * @returns {void}
  669. */
  670. notifyMouseMove(event: MouseEvent) {
  671. this._sendEvent({
  672. name: 'mouse-move',
  673. event: sanitizeMouseEvent(event)
  674. });
  675. }
  676. /**
  677. * Notify external application that the video quality setting has changed.
  678. *
  679. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  680. * @returns {void}
  681. */
  682. notifyVideoQualityChanged(videoQuality: number) {
  683. this._sendEvent({
  684. name: 'video-quality-changed',
  685. videoQuality
  686. });
  687. }
  688. /**
  689. * Notify external application (if API is enabled) that message was
  690. * received.
  691. *
  692. * @param {Object} options - Object with the message properties.
  693. * @returns {void}
  694. */
  695. notifyReceivedChatMessage(
  696. { body, id, nick, privateMessage, ts }: {
  697. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  698. } = {}) {
  699. if (APP.conference.isLocalId(id)) {
  700. return;
  701. }
  702. this._sendEvent({
  703. name: 'incoming-message',
  704. from: id,
  705. message: body,
  706. nick,
  707. privateMessage,
  708. stamp: ts
  709. });
  710. }
  711. /**
  712. * Notify external application (if API is enabled) that user joined the
  713. * conference.
  714. *
  715. * @param {string} id - User id.
  716. * @param {Object} props - The display name of the user.
  717. * @returns {void}
  718. */
  719. notifyUserJoined(id: string, props: Object) {
  720. this._sendEvent({
  721. name: 'participant-joined',
  722. id,
  723. ...props
  724. });
  725. }
  726. /**
  727. * Notify external application (if API is enabled) that user left the
  728. * conference.
  729. *
  730. * @param {string} id - User id.
  731. * @returns {void}
  732. */
  733. notifyUserLeft(id: string) {
  734. this._sendEvent({
  735. name: 'participant-left',
  736. id
  737. });
  738. }
  739. /**
  740. * Notify external application (if API is enabled) that the user role
  741. * has changed.
  742. *
  743. * @param {string} id - User id.
  744. * @param {string} role - The new user role.
  745. * @returns {void}
  746. */
  747. notifyUserRoleChanged(id: string, role: string) {
  748. this._sendEvent({
  749. name: 'participant-role-changed',
  750. id,
  751. role
  752. });
  753. }
  754. /**
  755. * Notify external application (if API is enabled) that user changed their
  756. * avatar.
  757. *
  758. * @param {string} id - User id.
  759. * @param {string} avatarURL - The new avatar URL of the participant.
  760. * @returns {void}
  761. */
  762. notifyAvatarChanged(id: string, avatarURL: string) {
  763. this._sendEvent({
  764. name: 'avatar-changed',
  765. avatarURL,
  766. id
  767. });
  768. }
  769. /**
  770. * Notify external application (if API is enabled) that user received
  771. * a text message through datachannels.
  772. *
  773. * @param {Object} data - The event data.
  774. * @returns {void}
  775. */
  776. notifyEndpointTextMessageReceived(data: Object) {
  777. this._sendEvent({
  778. name: 'endpoint-text-message-received',
  779. data
  780. });
  781. }
  782. /**
  783. * Notify external application (if API is enabled) that the list of sharing participants changed.
  784. *
  785. * @param {Object} data - The event data.
  786. * @returns {void}
  787. */
  788. notifySharingParticipantsChanged(data: Object) {
  789. this._sendEvent({
  790. name: 'content-sharing-participants-changed',
  791. data
  792. });
  793. }
  794. /**
  795. * Notify external application (if API is enabled) that the device list has
  796. * changed.
  797. *
  798. * @param {Object} devices - The new device list.
  799. * @returns {void}
  800. */
  801. notifyDeviceListChanged(devices: Object) {
  802. this._sendEvent({
  803. name: 'device-list-changed',
  804. devices
  805. });
  806. }
  807. /**
  808. * Notify external application (if API is enabled) that user changed their
  809. * nickname.
  810. *
  811. * @param {string} id - User id.
  812. * @param {string} displayname - User nickname.
  813. * @param {string} formattedDisplayName - The display name shown in Jitsi
  814. * meet's UI for the user.
  815. * @returns {void}
  816. */
  817. notifyDisplayNameChanged(
  818. id: string,
  819. { displayName, formattedDisplayName }: Object) {
  820. this._sendEvent({
  821. name: 'display-name-change',
  822. displayname: displayName,
  823. formattedDisplayName,
  824. id
  825. });
  826. }
  827. /**
  828. * Notify external application (if API is enabled) that user changed their
  829. * email.
  830. *
  831. * @param {string} id - User id.
  832. * @param {string} email - The new email of the participant.
  833. * @returns {void}
  834. */
  835. notifyEmailChanged(
  836. id: string,
  837. { email }: Object) {
  838. this._sendEvent({
  839. name: 'email-change',
  840. email,
  841. id
  842. });
  843. }
  844. /**
  845. * Notify external application (if API is enabled) that the an error has been logged.
  846. *
  847. * @param {string} logLevel - The message log level.
  848. * @param {Array} args - Array of strings composing the log message.
  849. * @returns {void}
  850. */
  851. notifyLog(logLevel: string, args: Array<string>) {
  852. this._sendEvent({
  853. name: 'log',
  854. logLevel,
  855. args
  856. });
  857. }
  858. /**
  859. * Notify external application (if API is enabled) that the conference has
  860. * been joined.
  861. *
  862. * @param {string} roomName - The room name.
  863. * @param {string} id - The id of the local user.
  864. * @param {Object} props - The display name and avatar URL of the local
  865. * user.
  866. * @returns {void}
  867. */
  868. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  869. this._sendEvent({
  870. name: 'video-conference-joined',
  871. roomName,
  872. id,
  873. ...props
  874. });
  875. }
  876. /**
  877. * Notify external application (if API is enabled) that local user has left the conference.
  878. *
  879. * @param {string} roomName - User id.
  880. * @returns {void}
  881. */
  882. notifyConferenceLeft(roomName: string) {
  883. this._sendEvent({
  884. name: 'video-conference-left',
  885. roomName
  886. });
  887. }
  888. /**
  889. * Notify external application (if API is enabled) that we are ready to be
  890. * closed.
  891. *
  892. * @returns {void}
  893. */
  894. notifyReadyToClose() {
  895. this._sendEvent({ name: 'video-ready-to-close' });
  896. }
  897. /**
  898. * Notify external application (if API is enabled) that a suspend event in host computer.
  899. *
  900. * @returns {void}
  901. */
  902. notifySuspendDetected() {
  903. this._sendEvent({ name: 'suspend-detected' });
  904. }
  905. /**
  906. * Notify external application (if API is enabled) for audio muted status
  907. * changed.
  908. *
  909. * @param {boolean} muted - The new muted status.
  910. * @returns {void}
  911. */
  912. notifyAudioMutedStatusChanged(muted: boolean) {
  913. this._sendEvent({
  914. name: 'audio-mute-status-changed',
  915. muted
  916. });
  917. }
  918. /**
  919. * Notify external application (if API is enabled) for video muted status
  920. * changed.
  921. *
  922. * @param {boolean} muted - The new muted status.
  923. * @returns {void}
  924. */
  925. notifyVideoMutedStatusChanged(muted: boolean) {
  926. this._sendEvent({
  927. name: 'video-mute-status-changed',
  928. muted
  929. });
  930. }
  931. /**
  932. * Notify external application (if API is enabled) for audio availability
  933. * changed.
  934. *
  935. * @param {boolean} available - True if available and false otherwise.
  936. * @returns {void}
  937. */
  938. notifyAudioAvailabilityChanged(available: boolean) {
  939. audioAvailable = available;
  940. this._sendEvent({
  941. name: 'audio-availability-changed',
  942. available
  943. });
  944. }
  945. /**
  946. * Notify external application (if API is enabled) for video available
  947. * status changed.
  948. *
  949. * @param {boolean} available - True if available and false otherwise.
  950. * @returns {void}
  951. */
  952. notifyVideoAvailabilityChanged(available: boolean) {
  953. videoAvailable = available;
  954. this._sendEvent({
  955. name: 'video-availability-changed',
  956. available
  957. });
  958. }
  959. /**
  960. * Notify external application (if API is enabled) that the on stage
  961. * participant has changed.
  962. *
  963. * @param {string} id - User id of the new on stage participant.
  964. * @returns {void}
  965. */
  966. notifyOnStageParticipantChanged(id: string) {
  967. this._sendEvent({
  968. name: 'on-stage-participant-changed',
  969. id
  970. });
  971. }
  972. /**
  973. * Notify external application of an unexpected camera-related error having
  974. * occurred.
  975. *
  976. * @param {string} type - The type of the camera error.
  977. * @param {string} message - Additional information about the error.
  978. * @returns {void}
  979. */
  980. notifyOnCameraError(type: string, message: string) {
  981. this._sendEvent({
  982. name: 'camera-error',
  983. type,
  984. message
  985. });
  986. }
  987. /**
  988. * Notify external application of an unexpected mic-related error having
  989. * occurred.
  990. *
  991. * @param {string} type - The type of the mic error.
  992. * @param {string} message - Additional information about the error.
  993. * @returns {void}
  994. */
  995. notifyOnMicError(type: string, message: string) {
  996. this._sendEvent({
  997. name: 'mic-error',
  998. type,
  999. message
  1000. });
  1001. }
  1002. /**
  1003. * Notify external application (if API is enabled) that conference feedback
  1004. * has been submitted. Intended to be used in conjunction with the
  1005. * submit-feedback command to get notified if feedback was submitted.
  1006. *
  1007. * @param {string} error - A failure message, if any.
  1008. * @returns {void}
  1009. */
  1010. notifyFeedbackSubmitted(error: string) {
  1011. this._sendEvent({
  1012. name: 'feedback-submitted',
  1013. error
  1014. });
  1015. }
  1016. /**
  1017. * Notify external application (if API is enabled) that the feedback prompt
  1018. * has been displayed.
  1019. *
  1020. * @returns {void}
  1021. */
  1022. notifyFeedbackPromptDisplayed() {
  1023. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1024. }
  1025. /**
  1026. * Notify external application (if API is enabled) that the display
  1027. * configuration of the filmstrip has been changed.
  1028. *
  1029. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1030. * be displayed or hidden.
  1031. * @returns {void}
  1032. */
  1033. notifyFilmstripDisplayChanged(visible: boolean) {
  1034. this._sendEvent({
  1035. name: 'filmstrip-display-changed',
  1036. visible
  1037. });
  1038. }
  1039. /**
  1040. * Notify external application of a participant, remote or local, being
  1041. * removed from the conference by another participant.
  1042. *
  1043. * @param {string} kicked - The ID of the participant removed from the
  1044. * conference.
  1045. * @param {string} kicker - The ID of the participant that removed the
  1046. * other participant.
  1047. * @returns {void}
  1048. */
  1049. notifyKickedOut(kicked: Object, kicker: Object) {
  1050. this._sendEvent({
  1051. name: 'participant-kicked-out',
  1052. kicked,
  1053. kicker
  1054. });
  1055. }
  1056. /**
  1057. * Notify external application of the current meeting requiring a password
  1058. * to join.
  1059. *
  1060. * @returns {void}
  1061. */
  1062. notifyOnPasswordRequired() {
  1063. this._sendEvent({ name: 'password-required' });
  1064. }
  1065. /**
  1066. * Notify external application (if API is enabled) that the screen sharing
  1067. * has been turned on/off.
  1068. *
  1069. * @param {boolean} on - True if screen sharing is enabled.
  1070. * @param {Object} details - Additional information about the screen
  1071. * sharing.
  1072. * @param {string} details.sourceType - Type of device or window the screen
  1073. * share is capturing.
  1074. * @returns {void}
  1075. */
  1076. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  1077. this._sendEvent({
  1078. name: 'screen-sharing-status-changed',
  1079. on,
  1080. details
  1081. });
  1082. }
  1083. /**
  1084. * Notify external application (if API is enabled) that the dominant speaker
  1085. * has been turned on/off.
  1086. *
  1087. * @param {string} id - Id of the dominant participant.
  1088. * @returns {void}
  1089. */
  1090. notifyDominantSpeakerChanged(id: string) {
  1091. this._sendEvent({
  1092. name: 'dominant-speaker-changed',
  1093. id
  1094. });
  1095. }
  1096. /**
  1097. * Notify external application (if API is enabled) that the conference
  1098. * changed their subject.
  1099. *
  1100. * @param {string} subject - Conference subject.
  1101. * @returns {void}
  1102. */
  1103. notifySubjectChanged(subject: string) {
  1104. this._sendEvent({
  1105. name: 'subject-change',
  1106. subject
  1107. });
  1108. }
  1109. /**
  1110. * Notify external application (if API is enabled) that tile view has been
  1111. * entered or exited.
  1112. *
  1113. * @param {string} enabled - True if tile view is currently displayed, false
  1114. * otherwise.
  1115. * @returns {void}
  1116. */
  1117. notifyTileViewChanged(enabled: boolean) {
  1118. this._sendEvent({
  1119. name: 'tile-view-changed',
  1120. enabled
  1121. });
  1122. }
  1123. /**
  1124. * Notify external application (if API is enabled) that the localStorage has changed.
  1125. *
  1126. * @param {string} localStorageContent - The new localStorageContent.
  1127. * @returns {void}
  1128. */
  1129. notifyLocalStorageChanged(localStorageContent: string) {
  1130. this._sendEvent({
  1131. name: 'local-storage-changed',
  1132. localStorageContent
  1133. });
  1134. }
  1135. /**
  1136. * Notify external application (if API is enabled) that user updated their hand raised.
  1137. *
  1138. * @param {string} id - User id.
  1139. * @param {boolean} handRaised - Whether user has raised hand.
  1140. * @returns {void}
  1141. */
  1142. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  1143. this._sendEvent({
  1144. name: 'raise-hand-updated',
  1145. handRaised,
  1146. id
  1147. });
  1148. }
  1149. /**
  1150. * Notify external application (if API is enabled) that recording has started or stopped.
  1151. *
  1152. * @param {boolean} on - True if recording is on, false otherwise.
  1153. * @param {string} mode - Stream or file.
  1154. * @param {string} error - Error type or null if success.
  1155. * @returns {void}
  1156. */
  1157. notifyRecordingStatusChanged(on: boolean, mode: string, error?: string) {
  1158. this._sendEvent({
  1159. name: 'recording-status-changed',
  1160. on,
  1161. mode,
  1162. error
  1163. });
  1164. }
  1165. /**
  1166. * Disposes the allocated resources.
  1167. *
  1168. * @returns {void}
  1169. */
  1170. dispose() {
  1171. if (this._enabled) {
  1172. this._enabled = false;
  1173. }
  1174. }
  1175. }
  1176. export default new API();