您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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