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.

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