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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  1. /* global APP */
  2. import Logger from '@jitsi/logger';
  3. import { createApiEvent } from '../../react/features/analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../react/features/analytics/functions';
  5. import {
  6. approveParticipantAudio,
  7. approveParticipantVideo,
  8. rejectParticipantAudio,
  9. rejectParticipantVideo,
  10. requestDisableAudioModeration,
  11. requestDisableVideoModeration,
  12. requestEnableAudioModeration,
  13. requestEnableVideoModeration
  14. } from '../../react/features/av-moderation/actions';
  15. import { isEnabledFromState } from '../../react/features/av-moderation/functions';
  16. import {
  17. endConference,
  18. sendTones,
  19. setAssumedBandwidthBps,
  20. setFollowMe,
  21. setLocalSubject,
  22. setPassword,
  23. setSubject
  24. } from '../../react/features/base/conference/actions';
  25. import { getCurrentConference, isP2pActive } from '../../react/features/base/conference/functions';
  26. import { overwriteConfig } from '../../react/features/base/config/actions';
  27. import { getWhitelistedJSON } from '../../react/features/base/config/functions.any';
  28. import { toggleDialog } from '../../react/features/base/dialog/actions';
  29. import { isSupportedBrowser } from '../../react/features/base/environment/environment';
  30. import { parseJWTFromURLParams } from '../../react/features/base/jwt/functions';
  31. import JitsiMeetJS, { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  32. import { MEDIA_TYPE, VIDEO_TYPE } from '../../react/features/base/media/constants';
  33. import {
  34. grantModerator,
  35. kickParticipant,
  36. overwriteParticipantsNames,
  37. pinParticipant,
  38. raiseHand
  39. } from '../../react/features/base/participants/actions';
  40. import { LOCAL_PARTICIPANT_DEFAULT_ID } from '../../react/features/base/participants/constants';
  41. import {
  42. getLocalParticipant,
  43. getParticipantById,
  44. getScreenshareParticipantIds,
  45. getVirtualScreenshareParticipantByOwnerId,
  46. hasRaisedHand,
  47. isLocalParticipantModerator,
  48. isParticipantModerator
  49. } from '../../react/features/base/participants/functions';
  50. import { updateSettings } from '../../react/features/base/settings/actions';
  51. import { getDisplayName } from '../../react/features/base/settings/functions.web';
  52. import { setCameraFacingMode } from '../../react/features/base/tracks/actions.web';
  53. import { CAMERA_FACING_MODE_MESSAGE } from '../../react/features/base/tracks/constants';
  54. import {
  55. autoAssignToBreakoutRooms,
  56. closeBreakoutRoom,
  57. createBreakoutRoom,
  58. moveToRoom,
  59. removeBreakoutRoom,
  60. sendParticipantToRoom
  61. } from '../../react/features/breakout-rooms/actions';
  62. import { getBreakoutRooms, getRoomsInfo } from '../../react/features/breakout-rooms/functions';
  63. import {
  64. sendMessage,
  65. setPrivateMessageRecipient,
  66. toggleChat
  67. } from '../../react/features/chat/actions';
  68. import { openChat } from '../../react/features/chat/actions.web';
  69. import {
  70. processExternalDeviceRequest
  71. } from '../../react/features/device-selection/functions';
  72. import { appendSuffix } from '../../react/features/display-name/functions';
  73. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox/functions';
  74. import { setMediaEncryptionKey, toggleE2EE } from '../../react/features/e2ee/actions';
  75. import {
  76. addStageParticipant,
  77. resizeFilmStrip,
  78. setVolume,
  79. togglePinStageParticipant
  80. } from '../../react/features/filmstrip/actions.web';
  81. import { getPinnedActiveParticipants, isStageFilmstripAvailable } from '../../react/features/filmstrip/functions.web';
  82. import { invite } from '../../react/features/invite/actions.any';
  83. import {
  84. selectParticipantInLargeVideo
  85. } from '../../react/features/large-video/actions.any';
  86. import {
  87. captureLargeVideoScreenshot,
  88. resizeLargeVideo
  89. } from '../../react/features/large-video/actions.web';
  90. import { answerKnockingParticipant, toggleLobbyMode } from '../../react/features/lobby/actions';
  91. import { setNoiseSuppressionEnabled } from '../../react/features/noise-suppression/actions';
  92. import { hideNotification, showNotification } from '../../react/features/notifications/actions';
  93. import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../../react/features/notifications/constants';
  94. import {
  95. close as closeParticipantsPane,
  96. open as openParticipantsPane
  97. } from '../../react/features/participants-pane/actions';
  98. import { getParticipantsPaneOpen, isForceMuted } from '../../react/features/participants-pane/functions';
  99. import { startLocalVideoRecording, stopLocalVideoRecording } from '../../react/features/recording/actions.any';
  100. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  101. import { getActiveSession, supportsLocalRecording } from '../../react/features/recording/functions';
  102. import { startAudioScreenShareFlow, startScreenShareFlow } from '../../react/features/screen-share/actions';
  103. import { isScreenAudioSupported } from '../../react/features/screen-share/functions';
  104. import { toggleScreenshotCaptureSummary } from '../../react/features/screenshot-capture/actions';
  105. import { isScreenshotCaptureEnabled } from '../../react/features/screenshot-capture/functions';
  106. import SettingsDialog from '../../react/features/settings/components/web/SettingsDialog';
  107. import { SETTINGS_TABS } from '../../react/features/settings/constants';
  108. import { playSharedVideo, stopSharedVideo } from '../../react/features/shared-video/actions.any';
  109. import { extractYoutubeIdOrURL } from '../../react/features/shared-video/functions';
  110. import { setRequestingSubtitles, toggleRequestingSubtitles } from '../../react/features/subtitles/actions';
  111. import { isAudioMuteButtonDisabled } from '../../react/features/toolbox/functions';
  112. import { setTileView, toggleTileView } from '../../react/features/video-layout/actions.any';
  113. import { muteAllParticipants } from '../../react/features/video-menu/actions';
  114. import { setVideoQuality } from '../../react/features/video-quality/actions';
  115. import { toggleWhiteboard } from '../../react/features/whiteboard/actions.any';
  116. import { getJitsiMeetTransport } from '../transport';
  117. import {
  118. API_ID,
  119. ENDPOINT_TEXT_MESSAGE_NAME
  120. } from './constants';
  121. const logger = Logger.getLogger(__filename);
  122. /**
  123. * List of the available commands.
  124. */
  125. let commands = {};
  126. /**
  127. * The transport instance used for communication with external apps.
  128. *
  129. * @type {Transport}
  130. */
  131. const transport = getJitsiMeetTransport();
  132. /**
  133. * The current audio availability.
  134. *
  135. * @type {boolean}
  136. */
  137. let audioAvailable = true;
  138. /**
  139. * The current video availability.
  140. *
  141. * @type {boolean}
  142. */
  143. let videoAvailable = true;
  144. /**
  145. * Initializes supported commands.
  146. *
  147. * @returns {void}
  148. */
  149. function initCommands() {
  150. commands = {
  151. 'add-breakout-room': name => {
  152. if (!isLocalParticipantModerator(APP.store.getState())) {
  153. logger.error('Missing moderator rights to add breakout rooms');
  154. return;
  155. }
  156. APP.store.dispatch(createBreakoutRoom(name));
  157. },
  158. 'answer-knocking-participant': (id, approved) => {
  159. APP.store.dispatch(answerKnockingParticipant(id, approved));
  160. },
  161. 'approve-video': participantId => {
  162. if (!isLocalParticipantModerator(APP.store.getState())) {
  163. return;
  164. }
  165. APP.store.dispatch(approveParticipantVideo(participantId));
  166. },
  167. 'ask-to-unmute': participantId => {
  168. if (!isLocalParticipantModerator(APP.store.getState())) {
  169. return;
  170. }
  171. APP.store.dispatch(approveParticipantAudio(participantId));
  172. },
  173. 'auto-assign-to-breakout-rooms': () => {
  174. if (!isLocalParticipantModerator(APP.store.getState())) {
  175. logger.error('Missing moderator rights to auto-assign participants to breakout rooms');
  176. return;
  177. }
  178. APP.store.dispatch(autoAssignToBreakoutRooms());
  179. },
  180. 'grant-moderator': participantId => {
  181. if (!isLocalParticipantModerator(APP.store.getState())) {
  182. logger.error('Missing moderator rights to grant moderator right to another participant');
  183. return;
  184. }
  185. APP.store.dispatch(grantModerator(participantId));
  186. },
  187. 'display-name': displayName => {
  188. sendAnalytics(createApiEvent('display.name.changed'));
  189. APP.conference.changeLocalDisplayName(displayName);
  190. },
  191. 'local-subject': localSubject => {
  192. sendAnalytics(createApiEvent('local.subject.changed'));
  193. APP.store.dispatch(setLocalSubject(localSubject));
  194. },
  195. 'mute-everyone': mediaType => {
  196. const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
  197. sendAnalytics(createApiEvent('muted-everyone'));
  198. const localParticipant = getLocalParticipant(APP.store.getState());
  199. const exclude = [];
  200. if (localParticipant && isParticipantModerator(localParticipant)) {
  201. exclude.push(localParticipant.id);
  202. }
  203. APP.store.dispatch(muteAllParticipants(exclude, muteMediaType));
  204. },
  205. 'toggle-lobby': isLobbyEnabled => {
  206. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  207. },
  208. 'password': password => {
  209. const { conference, passwordRequired }
  210. = APP.store.getState()['features/base/conference'];
  211. if (passwordRequired) {
  212. sendAnalytics(createApiEvent('submit.password'));
  213. APP.store.dispatch(setPassword(
  214. passwordRequired,
  215. passwordRequired.join,
  216. password
  217. ));
  218. } else {
  219. sendAnalytics(createApiEvent('password.changed'));
  220. APP.store.dispatch(setPassword(
  221. conference,
  222. conference.lock,
  223. password
  224. ));
  225. }
  226. },
  227. 'pin-participant': (id, videoType) => {
  228. logger.debug('Pin participant command received');
  229. const state = APP.store.getState();
  230. // if id not provided, unpin everybody.
  231. if (!id) {
  232. if (isStageFilmstripAvailable(state)) {
  233. const pinnedParticipants = getPinnedActiveParticipants(state);
  234. pinnedParticipants?.forEach(p => {
  235. APP.store.dispatch(togglePinStageParticipant(p.participantId));
  236. });
  237. } else {
  238. APP.store.dispatch(pinParticipant());
  239. }
  240. return;
  241. }
  242. const participant = videoType === VIDEO_TYPE.DESKTOP
  243. ? getVirtualScreenshareParticipantByOwnerId(state, id) : getParticipantById(state, id);
  244. if (!participant) {
  245. logger.warn('Trying to pin a non-existing participant with pin-participant command.');
  246. return;
  247. }
  248. sendAnalytics(createApiEvent('participant.pinned'));
  249. const participantId = participant.id;
  250. if (isStageFilmstripAvailable(state)) {
  251. APP.store.dispatch(addStageParticipant(participantId, true));
  252. } else {
  253. APP.store.dispatch(pinParticipant(participantId));
  254. }
  255. },
  256. 'proxy-connection-event': event => {
  257. APP.conference.onProxyConnectionEvent(event);
  258. },
  259. 'reject-participant': (participantId, mediaType) => {
  260. if (!isLocalParticipantModerator(APP.store.getState())) {
  261. return;
  262. }
  263. const reject = mediaType === MEDIA_TYPE.VIDEO ? rejectParticipantVideo : rejectParticipantAudio;
  264. APP.store.dispatch(reject(participantId));
  265. },
  266. 'remove-breakout-room': breakoutRoomJid => {
  267. if (!isLocalParticipantModerator(APP.store.getState())) {
  268. logger.error('Missing moderator rights to remove breakout rooms');
  269. return;
  270. }
  271. APP.store.dispatch(removeBreakoutRoom(breakoutRoomJid));
  272. },
  273. 'resize-large-video': (width, height) => {
  274. logger.debug('Resize large video command received');
  275. sendAnalytics(createApiEvent('largevideo.resized'));
  276. APP.store.dispatch(resizeLargeVideo(width, height));
  277. },
  278. 'send-tones': (options = {}) => {
  279. const { duration, tones, pause } = options;
  280. APP.store.dispatch(sendTones(tones, duration, pause));
  281. },
  282. 'set-assumed-bandwidth-bps': value => {
  283. logger.debug('Set assumed bandwidth bps command received', value);
  284. if (typeof value !== 'number' || isNaN(value)) {
  285. logger.error('Assumed bandwidth bps must be a number.');
  286. return;
  287. }
  288. APP.store.dispatch(setAssumedBandwidthBps(value));
  289. },
  290. 'set-follow-me': value => {
  291. logger.debug('Set follow me command received');
  292. if (value) {
  293. sendAnalytics(createApiEvent('follow.me.set'));
  294. } else {
  295. sendAnalytics(createApiEvent('follow.me.unset'));
  296. }
  297. APP.store.dispatch(setFollowMe(value));
  298. },
  299. 'set-large-video-participant': (participantId, videoType) => {
  300. logger.debug('Set large video participant command received');
  301. const { getState, dispatch } = APP.store;
  302. if (!participantId) {
  303. sendAnalytics(createApiEvent('largevideo.participant.set'));
  304. dispatch(selectParticipantInLargeVideo());
  305. return;
  306. }
  307. const state = getState();
  308. const participant = videoType === VIDEO_TYPE.DESKTOP
  309. ? getVirtualScreenshareParticipantByOwnerId(state, participantId)
  310. : getParticipantById(state, participantId);
  311. if (!participant) {
  312. logger.warn('Trying to select a non-existing participant with set-large-video-participant command.');
  313. return;
  314. }
  315. dispatch(setTileView(false));
  316. sendAnalytics(createApiEvent('largevideo.participant.set'));
  317. dispatch(selectParticipantInLargeVideo(participant.id));
  318. },
  319. 'set-participant-volume': (participantId, volume) => {
  320. APP.store.dispatch(setVolume(participantId, volume));
  321. },
  322. 'subject': subject => {
  323. sendAnalytics(createApiEvent('subject.changed'));
  324. APP.store.dispatch(setSubject(subject));
  325. },
  326. 'submit-feedback': feedback => {
  327. sendAnalytics(createApiEvent('submit.feedback'));
  328. APP.conference.submitFeedback(feedback.score, feedback.message);
  329. },
  330. 'toggle-audio': () => {
  331. sendAnalytics(createApiEvent('toggle-audio'));
  332. logger.log('Audio toggle: API command received');
  333. APP.conference.toggleAudioMuted(false /* no UI */);
  334. },
  335. 'toggle-video': () => {
  336. sendAnalytics(createApiEvent('toggle-video'));
  337. logger.log('Video toggle: API command received');
  338. APP.conference.toggleVideoMuted(false /* no UI */, true /* ensure track */);
  339. },
  340. 'toggle-film-strip': () => {
  341. sendAnalytics(createApiEvent('film.strip.toggled'));
  342. APP.UI.toggleFilmstrip();
  343. },
  344. /*
  345. * @param {Object} options - Additional details of how to perform
  346. * the action.
  347. * @param {number} options.width - width value for film strip.
  348. */
  349. 'resize-film-strip': (options = {}) => {
  350. sendAnalytics(createApiEvent('film.strip.resize'));
  351. APP.store.dispatch(resizeFilmStrip(options.width));
  352. },
  353. 'toggle-camera': facingMode => {
  354. APP.store.dispatch(setCameraFacingMode(facingMode));
  355. },
  356. 'toggle-camera-mirror': () => {
  357. const state = APP.store.getState();
  358. const { localFlipX: currentFlipX } = state['features/base/settings'];
  359. APP.store.dispatch(updateSettings({ localFlipX: !currentFlipX }));
  360. },
  361. 'toggle-chat': () => {
  362. sendAnalytics(createApiEvent('chat.toggled'));
  363. APP.store.dispatch(toggleChat());
  364. },
  365. 'toggle-moderation': (enabled, mediaType) => {
  366. const state = APP.store.getState();
  367. if (!isLocalParticipantModerator(state)) {
  368. return;
  369. }
  370. const enable = mediaType === MEDIA_TYPE.VIDEO
  371. ? requestEnableVideoModeration : requestEnableAudioModeration;
  372. const disable = mediaType === MEDIA_TYPE.VIDEO
  373. ? requestDisableVideoModeration : requestDisableAudioModeration;
  374. if (enabled) {
  375. APP.store.dispatch(enable());
  376. } else {
  377. APP.store.dispatch(disable());
  378. }
  379. },
  380. 'toggle-participants-pane': enabled => {
  381. const toggleParticipantsPane = enabled
  382. ? openParticipantsPane : closeParticipantsPane;
  383. APP.store.dispatch(toggleParticipantsPane());
  384. },
  385. 'toggle-raise-hand': () => {
  386. const localParticipant = getLocalParticipant(APP.store.getState());
  387. if (!localParticipant) {
  388. return;
  389. }
  390. const raisedHand = hasRaisedHand(localParticipant);
  391. sendAnalytics(createApiEvent('raise-hand.toggled'));
  392. APP.store.dispatch(raiseHand(!raisedHand));
  393. },
  394. 'toggle-share-audio': () => {
  395. sendAnalytics(createApiEvent('audio.screen.sharing.toggled'));
  396. if (isScreenAudioSupported()) {
  397. APP.store.dispatch(startAudioScreenShareFlow());
  398. return;
  399. }
  400. logger.error('Audio screen sharing is not supported by the current platform!');
  401. },
  402. /**
  403. * Callback to invoke when the "toggle-share-screen" command is received.
  404. *
  405. * @param {Object} options - Additional details of how to perform
  406. * the action. Note this parameter is undocumented and experimental.
  407. * @param {boolean} options.enable - Whether trying to enable screen
  408. * sharing or to turn it off.
  409. * @returns {void}
  410. */
  411. 'toggle-share-screen': (options = {}) => {
  412. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  413. toggleScreenSharing(options.enable);
  414. },
  415. 'set-noise-suppression-enabled': (options = {}) => {
  416. APP.store.dispatch(setNoiseSuppressionEnabled(options.enabled));
  417. },
  418. 'toggle-subtitles': () => {
  419. APP.store.dispatch(toggleRequestingSubtitles());
  420. },
  421. 'set-subtitles': enabled => {
  422. APP.store.dispatch(setRequestingSubtitles(enabled));
  423. },
  424. 'toggle-tile-view': () => {
  425. sendAnalytics(createApiEvent('tile-view.toggled'));
  426. APP.store.dispatch(toggleTileView());
  427. },
  428. 'set-tile-view': enabled => {
  429. APP.store.dispatch(setTileView(enabled));
  430. },
  431. 'video-hangup': (showFeedbackDialog = true) => {
  432. sendAnalytics(createApiEvent('video.hangup'));
  433. APP.conference.hangup(showFeedbackDialog);
  434. },
  435. 'email': email => {
  436. sendAnalytics(createApiEvent('email.changed'));
  437. APP.conference.changeLocalEmail(email);
  438. },
  439. 'avatar-url': avatarUrl => {
  440. sendAnalytics(createApiEvent('avatar.url.changed'));
  441. APP.conference.changeLocalAvatarUrl(avatarUrl);
  442. },
  443. 'send-chat-message': (message, to, ignorePrivacy = false) => {
  444. logger.debug('Send chat message command received');
  445. if (to) {
  446. const participant = getParticipantById(APP.store.getState(), to);
  447. if (participant) {
  448. APP.store.dispatch(setPrivateMessageRecipient(participant));
  449. } else {
  450. logger.error(`Participant with id ${to} not found!`);
  451. return;
  452. }
  453. } else {
  454. APP.store.dispatch(setPrivateMessageRecipient());
  455. }
  456. APP.store.dispatch(sendMessage(message, ignorePrivacy));
  457. },
  458. 'send-endpoint-text-message': (to, text) => {
  459. logger.debug('Send endpoint message command received');
  460. try {
  461. APP.conference.sendEndpointMessage(to, {
  462. name: ENDPOINT_TEXT_MESSAGE_NAME,
  463. text
  464. });
  465. } catch (err) {
  466. logger.error('Failed sending endpoint text message', err);
  467. }
  468. },
  469. 'send-camera-facing-mode-message': (to, facingMode) => {
  470. if (!to) {
  471. logger.warn('Participant id not set');
  472. return;
  473. }
  474. APP.conference.sendEndpointMessage(to, {
  475. name: CAMERA_FACING_MODE_MESSAGE,
  476. facingMode
  477. });
  478. },
  479. 'overwrite-names': participantList => {
  480. logger.debug('Overwrite names command received');
  481. APP.store.dispatch(overwriteParticipantsNames(participantList));
  482. },
  483. 'toggle-e2ee': enabled => {
  484. logger.debug('Toggle E2EE key command received');
  485. APP.store.dispatch(toggleE2EE(enabled));
  486. },
  487. 'set-media-encryption-key': keyInfo => {
  488. APP.store.dispatch(setMediaEncryptionKey(JSON.parse(keyInfo)));
  489. },
  490. 'set-video-quality': frameHeight => {
  491. logger.debug('Set video quality command received');
  492. sendAnalytics(createApiEvent('set.video.quality'));
  493. APP.store.dispatch(setVideoQuality(frameHeight));
  494. },
  495. 'start-share-video': url => {
  496. logger.debug('Share video command received');
  497. sendAnalytics(createApiEvent('share.video.start'));
  498. const id = extractYoutubeIdOrURL(url);
  499. if (id) {
  500. APP.store.dispatch(playSharedVideo(id));
  501. }
  502. },
  503. 'stop-share-video': () => {
  504. logger.debug('Share video command received');
  505. sendAnalytics(createApiEvent('share.video.stop'));
  506. APP.store.dispatch(stopSharedVideo());
  507. },
  508. /**
  509. * Shows a custom in-meeting notification.
  510. *
  511. * @param { string } arg.title - Notification title.
  512. * @param { string } arg.description - Notification description.
  513. * @param { string } arg.uid - Optional unique identifier for the notification.
  514. * @param { string } arg.type - Notification type, either `error`, `info`, `normal`, `success` or `warning`.
  515. * Defaults to "normal" if not provided.
  516. * @param { string } arg.timeout - Timeout type, either `short`, `medium`, `long` or `sticky`.
  517. * Defaults to "short" if not provided.
  518. * @returns {void}
  519. */
  520. 'show-notification': ({
  521. title,
  522. description,
  523. uid,
  524. type = NOTIFICATION_TYPE.NORMAL,
  525. timeout = NOTIFICATION_TIMEOUT_TYPE.SHORT
  526. }) => {
  527. const validTypes = Object.values(NOTIFICATION_TYPE);
  528. const validTimeouts = Object.values(NOTIFICATION_TIMEOUT_TYPE);
  529. if (!validTypes.includes(type)) {
  530. logger.error(`Invalid notification type "${type}". Expecting one of ${validTypes}`);
  531. return;
  532. }
  533. if (!validTimeouts.includes(timeout)) {
  534. logger.error(`Invalid notification timeout "${timeout}". Expecting one of ${validTimeouts}`);
  535. return;
  536. }
  537. APP.store.dispatch(showNotification({
  538. uid,
  539. title,
  540. description,
  541. appearance: type
  542. }, timeout));
  543. },
  544. /**
  545. * Removes a notification given a unique identifier.
  546. *
  547. * @param { string } uid - Unique identifier for the notification to be removed.
  548. * @returns {void}
  549. */
  550. 'hide-notification': uid => {
  551. APP.store.dispatch(hideNotification(uid));
  552. },
  553. /**
  554. * Starts a file recording or streaming session depending on the passed on params.
  555. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  556. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  557. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  558. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  559. * For local recording, recording `mode` should be `local` and optionally `onlySelf` could be passed on.
  560. * No other params should be passed.
  561. *
  562. * @param { string } arg.mode - Recording mode, either `local`, `file` or `stream`.
  563. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  564. * @param { boolean } arg.onlySelf - Whether to only record the local streams.
  565. * @param { string } arg.rtmpStreamKey - The RTMP stream key.
  566. * @param { string } arg.rtmpBroadcastID - The RTMP broadcast ID.
  567. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  568. * Only applies to certain jitsi meet deploys.
  569. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  570. * @param { string } arg.youtubeBroadcastID - The youtube broadcast ID.
  571. * @returns {void}
  572. */
  573. 'start-recording': ({
  574. mode,
  575. dropboxToken,
  576. onlySelf,
  577. shouldShare,
  578. rtmpStreamKey,
  579. rtmpBroadcastID,
  580. youtubeStreamKey,
  581. youtubeBroadcastID
  582. }) => {
  583. const state = APP.store.getState();
  584. const conference = getCurrentConference(state);
  585. if (!conference) {
  586. logger.error('Conference is not defined');
  587. return;
  588. }
  589. if (dropboxToken && !isDropboxEnabled(state)) {
  590. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  591. return;
  592. }
  593. if (mode === JitsiRecordingConstants.mode.STREAM && !(youtubeStreamKey || rtmpStreamKey)) {
  594. logger.error('Failed starting recording: missing youtube or RTMP stream key');
  595. return;
  596. }
  597. if (mode === 'local') {
  598. const { localRecording } = state['features/base/config'];
  599. if (!localRecording?.disable && supportsLocalRecording()) {
  600. APP.store.dispatch(startLocalVideoRecording(onlySelf));
  601. } else {
  602. logger.error('Failed starting recording: local recording is either disabled or not supported');
  603. }
  604. return;
  605. }
  606. let recordingConfig;
  607. if (mode === JitsiRecordingConstants.mode.FILE) {
  608. const { recordingService } = state['features/base/config'];
  609. if (!recordingService.enabled && !dropboxToken) {
  610. logger.error('Failed starting recording: the recording service is not enabled');
  611. return;
  612. }
  613. if (dropboxToken) {
  614. recordingConfig = {
  615. mode: JitsiRecordingConstants.mode.FILE,
  616. appData: JSON.stringify({
  617. 'file_recording_metadata': {
  618. 'upload_credentials': {
  619. 'service_name': RECORDING_TYPES.DROPBOX,
  620. 'token': dropboxToken
  621. }
  622. }
  623. })
  624. };
  625. } else {
  626. recordingConfig = {
  627. mode: JitsiRecordingConstants.mode.FILE,
  628. appData: JSON.stringify({
  629. 'file_recording_metadata': {
  630. 'share': shouldShare
  631. }
  632. })
  633. };
  634. }
  635. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  636. recordingConfig = {
  637. broadcastId: youtubeBroadcastID || rtmpBroadcastID,
  638. mode: JitsiRecordingConstants.mode.STREAM,
  639. streamId: youtubeStreamKey || rtmpStreamKey
  640. };
  641. } else {
  642. logger.error('Invalid recording mode provided');
  643. return;
  644. }
  645. if (isScreenshotCaptureEnabled(state, true, false)) {
  646. APP.store.dispatch(toggleScreenshotCaptureSummary(true));
  647. }
  648. conference.startRecording(recordingConfig);
  649. },
  650. /**
  651. * Stops a recording or streaming in progress.
  652. *
  653. * @param {string} mode - `local`, `file` or `stream`.
  654. * @returns {void}
  655. */
  656. 'stop-recording': mode => {
  657. const state = APP.store.getState();
  658. const conference = getCurrentConference(state);
  659. if (!conference) {
  660. logger.error('Conference is not defined');
  661. return;
  662. }
  663. if (mode === 'local') {
  664. APP.store.dispatch(stopLocalVideoRecording());
  665. return;
  666. }
  667. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  668. logger.error('Invalid recording mode provided!');
  669. return;
  670. }
  671. const activeSession = getActiveSession(state, mode);
  672. if (activeSession && activeSession.id) {
  673. APP.store.dispatch(toggleScreenshotCaptureSummary(false));
  674. conference.stopRecording(activeSession.id);
  675. } else {
  676. logger.error('No recording or streaming session found');
  677. }
  678. },
  679. 'initiate-private-chat': participantId => {
  680. const state = APP.store.getState();
  681. const participant = getParticipantById(state, participantId);
  682. if (participant) {
  683. const { isOpen: isChatOpen } = state['features/chat'];
  684. if (!isChatOpen) {
  685. APP.store.dispatch(toggleChat());
  686. }
  687. APP.store.dispatch(openChat(participant));
  688. } else {
  689. logger.error('No participant found for the given participantId');
  690. }
  691. },
  692. 'cancel-private-chat': () => {
  693. APP.store.dispatch(setPrivateMessageRecipient());
  694. },
  695. 'close-breakout-room': roomId => {
  696. if (!isLocalParticipantModerator(APP.store.getState())) {
  697. logger.error('Missing moderator rights to close breakout rooms');
  698. return;
  699. }
  700. APP.store.dispatch(closeBreakoutRoom(roomId));
  701. },
  702. 'join-breakout-room': roomId => {
  703. APP.store.dispatch(moveToRoom(roomId));
  704. },
  705. 'send-participant-to-room': (participantId, roomId) => {
  706. if (!isLocalParticipantModerator(APP.store.getState())) {
  707. logger.error('Missing moderator rights to send participants to rooms');
  708. return;
  709. }
  710. APP.store.dispatch(sendParticipantToRoom(participantId, roomId));
  711. },
  712. 'kick-participant': participantId => {
  713. APP.store.dispatch(kickParticipant(participantId));
  714. },
  715. 'overwrite-config': config => {
  716. const whitelistedConfig = getWhitelistedJSON('config', config);
  717. APP.store.dispatch(overwriteConfig(whitelistedConfig));
  718. },
  719. 'toggle-virtual-background': () => {
  720. APP.store.dispatch(toggleDialog(SettingsDialog, {
  721. defaultTab: SETTINGS_TABS.VIRTUAL_BACKGROUND }));
  722. },
  723. 'end-conference': () => {
  724. APP.store.dispatch(endConference());
  725. const state = APP.store.getState();
  726. const conference = getCurrentConference(state);
  727. if (!conference) {
  728. logger.error('Conference not yet available');
  729. } else if (conference.isEndConferenceSupported()) {
  730. APP.store.dispatch(endConference());
  731. } else {
  732. logger.error(' End Conference not supported');
  733. }
  734. },
  735. 'toggle-whiteboard': () => {
  736. APP.store.dispatch(toggleWhiteboard());
  737. }
  738. };
  739. transport.on('event', ({ data, name }) => {
  740. if (name && commands[name]) {
  741. commands[name](...data);
  742. return true;
  743. }
  744. return false;
  745. });
  746. transport.on('request', (request, callback) => {
  747. const { dispatch, getState } = APP.store;
  748. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  749. return true;
  750. }
  751. const { name } = request;
  752. switch (name) {
  753. case 'capture-largevideo-screenshot' :
  754. APP.store.dispatch(captureLargeVideoScreenshot())
  755. .then(dataURL => {
  756. let error;
  757. if (!dataURL) {
  758. error = new Error('No large video found!');
  759. }
  760. callback({
  761. error,
  762. dataURL
  763. });
  764. });
  765. break;
  766. case 'deployment-info':
  767. callback(APP.store.getState()['features/base/config'].deploymentInfo);
  768. break;
  769. case 'invite': {
  770. const { invitees } = request;
  771. if (!Array.isArray(invitees) || invitees.length === 0) {
  772. callback({
  773. error: new Error('Unexpected format of invitees')
  774. });
  775. break;
  776. }
  777. // The store should be already available because API.init is called
  778. // on appWillMount action.
  779. APP.store.dispatch(
  780. invite(invitees, true))
  781. .then(failedInvitees => {
  782. let error;
  783. let result;
  784. if (failedInvitees.length) {
  785. error = new Error('One or more invites failed!');
  786. } else {
  787. result = true;
  788. }
  789. callback({
  790. error,
  791. result
  792. });
  793. });
  794. break;
  795. }
  796. case 'is-audio-muted':
  797. callback(APP.conference.isLocalAudioMuted());
  798. break;
  799. case 'is-audio-disabled':
  800. callback(isAudioMuteButtonDisabled(APP.store.getState()));
  801. break;
  802. case 'is-moderation-on': {
  803. const { mediaType } = request;
  804. const type = mediaType || MEDIA_TYPE.AUDIO;
  805. callback(isEnabledFromState(type, APP.store.getState()));
  806. break;
  807. }
  808. case 'is-participant-force-muted': {
  809. const state = APP.store.getState();
  810. const { participantId, mediaType } = request;
  811. const type = mediaType || MEDIA_TYPE.AUDIO;
  812. const participant = getParticipantById(state, participantId);
  813. callback(isForceMuted(participant, type, state));
  814. break;
  815. }
  816. case 'is-participants-pane-open': {
  817. callback(getParticipantsPaneOpen(APP.store.getState()));
  818. break;
  819. }
  820. case 'is-video-muted':
  821. callback(APP.conference.isLocalVideoMuted());
  822. break;
  823. case 'is-audio-available':
  824. callback(audioAvailable);
  825. break;
  826. case 'is-video-available':
  827. callback(videoAvailable);
  828. break;
  829. case 'is-sharing-screen':
  830. callback(Boolean(APP.conference.isSharingScreen));
  831. break;
  832. case 'is-start-silent':
  833. callback(Boolean(APP.store.getState()['features/base/config'].startSilent));
  834. break;
  835. case 'get-content-sharing-participants': {
  836. const sharingParticipantIds = getScreenshareParticipantIds(APP.store.getState());
  837. callback({
  838. sharingParticipantIds
  839. });
  840. break;
  841. }
  842. case 'get-livestream-url': {
  843. const state = APP.store.getState();
  844. const conference = getCurrentConference(state);
  845. let livestreamUrl;
  846. if (conference) {
  847. const activeSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  848. livestreamUrl = activeSession?.liveStreamViewURL;
  849. } else {
  850. logger.error('Conference is not defined');
  851. }
  852. callback({
  853. livestreamUrl
  854. });
  855. break;
  856. }
  857. case 'get-custom-avatar-backgrounds' : {
  858. callback({
  859. avatarBackgrounds: APP.store.getState()['features/dynamic-branding'].avatarBackgrounds
  860. });
  861. break;
  862. }
  863. case 'list-breakout-rooms': {
  864. callback(getBreakoutRooms(APP.store.getState()));
  865. break;
  866. }
  867. case 'rooms-info': {
  868. callback(getRoomsInfo(APP.store.getState()));
  869. break;
  870. }
  871. case 'get-p2p-status': {
  872. callback(isP2pActive(APP.store.getState()));
  873. break;
  874. }
  875. case '_new_electron_screensharing_supported': {
  876. callback(true);
  877. break;
  878. }
  879. default:
  880. callback({ error: new Error('UnknownRequestError') });
  881. return false;
  882. }
  883. return true;
  884. });
  885. }
  886. /**
  887. * Check whether the API should be enabled or not.
  888. *
  889. * @returns {boolean}
  890. */
  891. function shouldBeEnabled() {
  892. return (
  893. typeof API_ID === 'number'
  894. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  895. // the location/URL because then it is very likely that the Jitsi
  896. // Meet (Web) app is being used by an external/wrapping (Web) app
  897. // and, consequently, the latter will need to communicate with the
  898. // former. (The described logic is merely a heuristic though.)
  899. || parseJWTFromURLParams());
  900. }
  901. /**
  902. * Executes on toggle-share-screen command.
  903. *
  904. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  905. * disable screensharing. If not defined, the application will automatically
  906. * attempt to toggle between enabled and disabled. This boolean is useful for
  907. * explicitly setting desired screensharing state.
  908. * @returns {void}
  909. */
  910. function toggleScreenSharing(enable) {
  911. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  912. APP.store.dispatch(startScreenShareFlow(enable));
  913. }
  914. }
  915. /**
  916. * Removes sensitive data from a mouse event.
  917. *
  918. * @param {MouseEvent} event - The mouse event to sanitize.
  919. * @returns {Object}
  920. */
  921. function sanitizeMouseEvent(event) {
  922. const {
  923. clientX,
  924. clientY,
  925. movementX,
  926. movementY,
  927. offsetX,
  928. offsetY,
  929. pageX,
  930. pageY,
  931. x,
  932. y,
  933. screenX,
  934. screenY
  935. } = event;
  936. return {
  937. clientX,
  938. clientY,
  939. movementX,
  940. movementY,
  941. offsetX,
  942. offsetY,
  943. pageX,
  944. pageY,
  945. x,
  946. y,
  947. screenX,
  948. screenY
  949. };
  950. }
  951. /**
  952. * Implements API class that communicates with external API class and provides
  953. * interface to access Jitsi Meet features by external applications that embed
  954. * Jitsi Meet.
  955. */
  956. class API {
  957. _enabled;
  958. /**
  959. * Initializes the API. Setups message event listeners that will receive
  960. * information from external applications that embed Jitsi Meet. It also
  961. * sends a message to the external application that API is initialized.
  962. *
  963. * @param {Object} options - Optional parameters.
  964. * @returns {void}
  965. */
  966. init() {
  967. if (!shouldBeEnabled()) {
  968. return;
  969. }
  970. /**
  971. * Current status (enabled/disabled) of API.
  972. *
  973. * @private
  974. * @type {boolean}
  975. */
  976. this._enabled = true;
  977. initCommands();
  978. this.notifyBrowserSupport(isSupportedBrowser());
  979. // Let the embedder know we are ready.
  980. this._sendEvent({ name: 'ready' });
  981. }
  982. /**
  983. * Notify external application (if API is enabled) that the large video
  984. * visibility changed.
  985. *
  986. * @param {boolean} isHidden - True if the large video is hidden and false
  987. * otherwise.
  988. * @returns {void}
  989. */
  990. notifyLargeVideoVisibilityChanged(isHidden) {
  991. this._sendEvent({
  992. name: 'large-video-visibility-changed',
  993. isVisible: !isHidden
  994. });
  995. }
  996. /**
  997. * Notifies the external application (spot) that the local jitsi-participant
  998. * has a status update.
  999. *
  1000. * @param {Object} event - The message to pass onto spot.
  1001. * @returns {void}
  1002. */
  1003. sendProxyConnectionEvent(event) {
  1004. this._sendEvent({
  1005. name: 'proxy-connection-event',
  1006. ...event
  1007. });
  1008. }
  1009. /**
  1010. * Sends event to the external application.
  1011. *
  1012. * @param {Object} event - The event to be sent.
  1013. * @returns {void}
  1014. */
  1015. _sendEvent(event = {}) {
  1016. if (this._enabled) {
  1017. try {
  1018. transport.sendEvent(event);
  1019. } catch (error) {
  1020. logger.error('Failed to send and IFrame API event', error);
  1021. }
  1022. }
  1023. }
  1024. /**
  1025. * Notify external application (if API is enabled) that the chat state has been updated.
  1026. *
  1027. * @param {number} unreadCount - The unread messages counter.
  1028. * @param {boolean} isOpen - True if the chat panel is open.
  1029. * @returns {void}
  1030. */
  1031. notifyChatUpdated(unreadCount, isOpen) {
  1032. this._sendEvent({
  1033. name: 'chat-updated',
  1034. unreadCount,
  1035. isOpen
  1036. });
  1037. }
  1038. /**
  1039. * Notify external application (if API is enabled) that message was sent.
  1040. *
  1041. * @param {string} message - Message body.
  1042. * @param {boolean} privateMessage - True if the message was a private message.
  1043. * @returns {void}
  1044. */
  1045. notifySendingChatMessage(message, privateMessage) {
  1046. this._sendEvent({
  1047. name: 'outgoing-message',
  1048. message,
  1049. privateMessage
  1050. });
  1051. }
  1052. /**
  1053. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1054. *
  1055. * @param {MouseEvent} event - The mousemove event.
  1056. * @returns {void}
  1057. */
  1058. notifyMouseEnter(event) {
  1059. this._sendEvent({
  1060. name: 'mouse-enter',
  1061. event: sanitizeMouseEvent(event)
  1062. });
  1063. }
  1064. /**
  1065. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1066. *
  1067. * @param {MouseEvent} event - The mousemove event.
  1068. * @returns {void}
  1069. */
  1070. notifyMouseLeave(event) {
  1071. this._sendEvent({
  1072. name: 'mouse-leave',
  1073. event: sanitizeMouseEvent(event)
  1074. });
  1075. }
  1076. /**
  1077. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  1078. *
  1079. * @param {MouseEvent} event - The mousemove event.
  1080. * @returns {void}
  1081. */
  1082. notifyMouseMove(event) {
  1083. this._sendEvent({
  1084. name: 'mouse-move',
  1085. event: sanitizeMouseEvent(event)
  1086. });
  1087. }
  1088. /**
  1089. * Notify the external application that the moderation status has changed.
  1090. *
  1091. * @param {string} mediaType - Media type for which the moderation changed.
  1092. * @param {boolean} enabled - Whether or not the new moderation status is enabled.
  1093. * @returns {void}
  1094. */
  1095. notifyModerationChanged(mediaType, enabled) {
  1096. this._sendEvent({
  1097. name: 'moderation-status-changed',
  1098. mediaType,
  1099. enabled
  1100. });
  1101. }
  1102. /**
  1103. * Notify the external application that a participant was approved on moderation.
  1104. *
  1105. * @param {string} participantId - The ID of the participant that got approved.
  1106. * @param {string} mediaType - Media type for which the participant was approved.
  1107. * @returns {void}
  1108. */
  1109. notifyParticipantApproved(participantId, mediaType) {
  1110. this._sendEvent({
  1111. name: 'moderation-participant-approved',
  1112. id: participantId,
  1113. mediaType
  1114. });
  1115. }
  1116. /**
  1117. * Notify the external application that a participant was rejected on moderation.
  1118. *
  1119. * @param {string} participantId - The ID of the participant that got rejected.
  1120. * @param {string} mediaType - Media type for which the participant was rejected.
  1121. * @returns {void}
  1122. */
  1123. notifyParticipantRejected(participantId, mediaType) {
  1124. this._sendEvent({
  1125. name: 'moderation-participant-rejected',
  1126. id: participantId,
  1127. mediaType
  1128. });
  1129. }
  1130. /**
  1131. * Notify the external app that a notification has been triggered.
  1132. *
  1133. * @param {string} title - The notification title.
  1134. * @param {string} description - The notification description.
  1135. *
  1136. * @returns {void}
  1137. */
  1138. notifyNotificationTriggered(title, description) {
  1139. this._sendEvent({
  1140. description,
  1141. name: 'notification-triggered',
  1142. title
  1143. });
  1144. }
  1145. /**
  1146. * Notify request desktop sources.
  1147. *
  1148. * @param {Object} options - Object with the options for desktop sources.
  1149. * @returns {void}
  1150. */
  1151. requestDesktopSources(options) {
  1152. return transport.sendRequest({
  1153. name: '_request-desktop-sources',
  1154. options
  1155. });
  1156. }
  1157. /**
  1158. * Notify external application that the video quality setting has changed.
  1159. *
  1160. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  1161. * @returns {void}
  1162. */
  1163. notifyVideoQualityChanged(videoQuality) {
  1164. this._sendEvent({
  1165. name: 'video-quality-changed',
  1166. videoQuality
  1167. });
  1168. }
  1169. /**
  1170. * Notify external application (if API is enabled) that message was
  1171. * received.
  1172. *
  1173. * @param {Object} options - Object with the message properties.
  1174. * @returns {void}
  1175. */
  1176. notifyReceivedChatMessage(
  1177. { body, id, nick, privateMessage, ts } = {}) {
  1178. if (APP.conference.isLocalId(id)) {
  1179. return;
  1180. }
  1181. this._sendEvent({
  1182. name: 'incoming-message',
  1183. from: id,
  1184. message: body,
  1185. nick,
  1186. privateMessage,
  1187. stamp: ts
  1188. });
  1189. }
  1190. /**
  1191. * Notify external application (if API is enabled) that user joined the
  1192. * conference.
  1193. *
  1194. * @param {string} id - User id.
  1195. * @param {Object} props - The display name of the user.
  1196. * @returns {void}
  1197. */
  1198. notifyUserJoined(id, props) {
  1199. this._sendEvent({
  1200. name: 'participant-joined',
  1201. id,
  1202. ...props
  1203. });
  1204. }
  1205. /**
  1206. * Notify external application (if API is enabled) that user left the
  1207. * conference.
  1208. *
  1209. * @param {string} id - User id.
  1210. * @returns {void}
  1211. */
  1212. notifyUserLeft(id) {
  1213. this._sendEvent({
  1214. name: 'participant-left',
  1215. id
  1216. });
  1217. }
  1218. /**
  1219. * Notify external application (if API is enabled) that the user role
  1220. * has changed.
  1221. *
  1222. * @param {string} id - User id.
  1223. * @param {string} role - The new user role.
  1224. * @returns {void}
  1225. */
  1226. notifyUserRoleChanged(id, role) {
  1227. this._sendEvent({
  1228. name: 'participant-role-changed',
  1229. id,
  1230. role
  1231. });
  1232. }
  1233. /**
  1234. * Notify external application (if API is enabled) that user changed their
  1235. * avatar.
  1236. *
  1237. * @param {string} id - User id.
  1238. * @param {string} avatarURL - The new avatar URL of the participant.
  1239. * @returns {void}
  1240. */
  1241. notifyAvatarChanged(id, avatarURL) {
  1242. this._sendEvent({
  1243. name: 'avatar-changed',
  1244. avatarURL,
  1245. id
  1246. });
  1247. }
  1248. /**
  1249. * Notify external application (if API is enabled) that user received
  1250. * a text message through datachannels.
  1251. *
  1252. * @param {Object} data - The event data.
  1253. * @returns {void}
  1254. */
  1255. notifyEndpointTextMessageReceived(data) {
  1256. this._sendEvent({
  1257. name: 'endpoint-text-message-received',
  1258. data
  1259. });
  1260. }
  1261. /**
  1262. * Notify external application (if API is enabled) that some face landmark data is available.
  1263. *
  1264. * @param {Object | undefined} faceBox - Detected face(s) bounding box (left, right, width).
  1265. * @param {string} faceExpression - Detected face expression.
  1266. * @returns {void}
  1267. */
  1268. notifyFaceLandmarkDetected(faceBox, faceExpression) {
  1269. this._sendEvent({
  1270. name: 'face-landmark-detected',
  1271. faceBox,
  1272. faceExpression
  1273. });
  1274. }
  1275. /**
  1276. * Notify external application (if API is enabled) that the list of sharing participants changed.
  1277. *
  1278. * @param {Object} data - The event data.
  1279. * @returns {void}
  1280. */
  1281. notifySharingParticipantsChanged(data) {
  1282. this._sendEvent({
  1283. name: 'content-sharing-participants-changed',
  1284. data
  1285. });
  1286. }
  1287. /**
  1288. * Notify external application (if API is enabled) that the device list has
  1289. * changed.
  1290. *
  1291. * @param {Object} devices - The new device list.
  1292. * @returns {void}
  1293. */
  1294. notifyDeviceListChanged(devices) {
  1295. this._sendEvent({
  1296. name: 'device-list-changed',
  1297. devices
  1298. });
  1299. }
  1300. /**
  1301. * Notify external application (if API is enabled) that user changed their
  1302. * nickname.
  1303. *
  1304. * @param {string} id - User id.
  1305. * @param {string} displayname - User nickname.
  1306. * @param {string} formattedDisplayName - The display name shown in Jitsi
  1307. * meet's UI for the user.
  1308. * @returns {void}
  1309. */
  1310. notifyDisplayNameChanged(
  1311. id,
  1312. { displayName, formattedDisplayName }) {
  1313. this._sendEvent({
  1314. name: 'display-name-change',
  1315. displayname: displayName,
  1316. formattedDisplayName,
  1317. id
  1318. });
  1319. }
  1320. /**
  1321. * Notify external application (if API is enabled) that user changed their
  1322. * email.
  1323. *
  1324. * @param {string} id - User id.
  1325. * @param {string} email - The new email of the participant.
  1326. * @returns {void}
  1327. */
  1328. notifyEmailChanged(
  1329. id,
  1330. { email }) {
  1331. this._sendEvent({
  1332. name: 'email-change',
  1333. email,
  1334. id
  1335. });
  1336. }
  1337. /**
  1338. * Notify external application (if API is enabled) that the an error has been logged.
  1339. *
  1340. * @param {string} logLevel - The message log level.
  1341. * @param {Array<string>} args - Array of strings composing the log message.
  1342. * @returns {void}
  1343. */
  1344. notifyLog(logLevel, args = []) {
  1345. if (!Array.isArray(args)) {
  1346. logger.error('notifyLog received wrong argument types!');
  1347. return;
  1348. }
  1349. // Trying to convert arguments to strings. Otherwise in order to send the event the arguments will be formatted
  1350. // with JSON.stringify which can throw an error because of circular objects and we will lose the whole log.
  1351. const formattedArguments = [];
  1352. args.forEach(arg => {
  1353. let formattedArgument = '';
  1354. if (arg instanceof Error) {
  1355. formattedArgument += `${arg.toString()}: ${arg.stack}`;
  1356. } else if (typeof arg === 'object') {
  1357. // NOTE: The non-enumerable properties of the objects wouldn't be included in the string after
  1358. // JSON.strigify. For example Map instance will be translated to '{}'. So I think we have to eventually
  1359. // do something better for parsing the arguments. But since this option for strigify is part of the
  1360. // public interface and I think it could be useful in some cases I will it for now.
  1361. try {
  1362. formattedArgument += JSON.stringify(arg);
  1363. } catch (error) {
  1364. formattedArgument += arg;
  1365. }
  1366. } else {
  1367. formattedArgument += arg;
  1368. }
  1369. formattedArguments.push(formattedArgument);
  1370. });
  1371. this._sendEvent({
  1372. name: 'log',
  1373. logLevel,
  1374. args: formattedArguments
  1375. });
  1376. }
  1377. /**
  1378. * Notify external application (if API is enabled) that the conference has
  1379. * been joined.
  1380. *
  1381. * @param {string} roomName - The room name.
  1382. * @param {string} id - The id of the local user.
  1383. * @param {Object} props - The display name, the avatar URL of the local
  1384. * user and the type of the room.
  1385. * @returns {void}
  1386. */
  1387. notifyConferenceJoined(roomName, id, props) {
  1388. this._sendEvent({
  1389. name: 'video-conference-joined',
  1390. roomName,
  1391. id,
  1392. ...props
  1393. });
  1394. }
  1395. /**
  1396. * Notify external application (if API is enabled) that local user has left the conference.
  1397. *
  1398. * @param {string} roomName - User id.
  1399. * @returns {void}
  1400. */
  1401. notifyConferenceLeft(roomName) {
  1402. this._sendEvent({
  1403. name: 'video-conference-left',
  1404. roomName
  1405. });
  1406. }
  1407. /**
  1408. * Notify external application that the data channel has been closed.
  1409. *
  1410. * @param {number} code - The close code.
  1411. * @param {string} reason - The close reason.
  1412. *
  1413. * @returns {void}
  1414. */
  1415. notifyDataChannelClosed(code, reason) {
  1416. this._sendEvent({
  1417. name: 'data-channel-closed',
  1418. code,
  1419. reason
  1420. });
  1421. }
  1422. /**
  1423. * Notify external application that the data channel has been opened.
  1424. *
  1425. * @returns {void}
  1426. */
  1427. notifyDataChannelOpened() {
  1428. this._sendEvent({ name: 'data-channel-opened' });
  1429. }
  1430. /**
  1431. * Notify external application (if API is enabled) that we are ready to be
  1432. * closed.
  1433. *
  1434. * @returns {void}
  1435. */
  1436. notifyReadyToClose() {
  1437. this._sendEvent({ name: 'video-ready-to-close' });
  1438. }
  1439. /**
  1440. * Notify external application (if API is enabled) that a suspend event in host computer.
  1441. *
  1442. * @returns {void}
  1443. */
  1444. notifySuspendDetected() {
  1445. this._sendEvent({ name: 'suspend-detected' });
  1446. }
  1447. /**
  1448. * Notify external application (if API is enabled) for audio muted status
  1449. * changed.
  1450. *
  1451. * @param {boolean} muted - The new muted status.
  1452. * @returns {void}
  1453. */
  1454. notifyAudioMutedStatusChanged(muted) {
  1455. this._sendEvent({
  1456. name: 'audio-mute-status-changed',
  1457. muted
  1458. });
  1459. }
  1460. /**
  1461. * Notify external application (if API is enabled) for video muted status
  1462. * changed.
  1463. *
  1464. * @param {boolean} muted - The new muted status.
  1465. * @returns {void}
  1466. */
  1467. notifyVideoMutedStatusChanged(muted) {
  1468. this._sendEvent({
  1469. name: 'video-mute-status-changed',
  1470. muted
  1471. });
  1472. }
  1473. /**
  1474. * Notify external application (if API is enabled) for audio availability
  1475. * changed.
  1476. *
  1477. * @param {boolean} available - True if available and false otherwise.
  1478. * @returns {void}
  1479. */
  1480. notifyAudioAvailabilityChanged(available) {
  1481. audioAvailable = available;
  1482. this._sendEvent({
  1483. name: 'audio-availability-changed',
  1484. available
  1485. });
  1486. }
  1487. /**
  1488. * Notify external application (if API is enabled) for video available
  1489. * status changed.
  1490. *
  1491. * @param {boolean} available - True if available and false otherwise.
  1492. * @returns {void}
  1493. */
  1494. notifyVideoAvailabilityChanged(available) {
  1495. videoAvailable = available;
  1496. this._sendEvent({
  1497. name: 'video-availability-changed',
  1498. available
  1499. });
  1500. }
  1501. /**
  1502. * Notify external application (if API is enabled) that the on stage
  1503. * participant has changed.
  1504. *
  1505. * @param {string} id - User id of the new on stage participant.
  1506. * @returns {void}
  1507. */
  1508. notifyOnStageParticipantChanged(id) {
  1509. this._sendEvent({
  1510. name: 'on-stage-participant-changed',
  1511. id
  1512. });
  1513. }
  1514. /**
  1515. * Notify external application (if API is enabled) that the prejoin video
  1516. * visibility had changed.
  1517. *
  1518. * @param {boolean} isVisible - Whether the prejoin video is visible.
  1519. * @returns {void}
  1520. */
  1521. notifyPrejoinVideoVisibilityChanged(isVisible) {
  1522. this._sendEvent({
  1523. name: 'on-prejoin-video-changed',
  1524. isVisible
  1525. });
  1526. }
  1527. /**
  1528. * Notify external application (if API is enabled) that the prejoin
  1529. * screen was loaded.
  1530. *
  1531. * @returns {void}
  1532. */
  1533. notifyPrejoinLoaded() {
  1534. const state = APP.store.getState();
  1535. const { defaultLocalDisplayName } = state['features/base/config'];
  1536. const displayName = getDisplayName(state);
  1537. this._sendEvent({
  1538. name: 'prejoin-screen-loaded',
  1539. id: LOCAL_PARTICIPANT_DEFAULT_ID,
  1540. displayName,
  1541. formattedDisplayName: appendSuffix(displayName, defaultLocalDisplayName)
  1542. });
  1543. }
  1544. /**
  1545. * Notify external application of an unexpected camera-related error having
  1546. * occurred.
  1547. *
  1548. * @param {string} type - The type of the camera error.
  1549. * @param {string} message - Additional information about the error.
  1550. * @returns {void}
  1551. */
  1552. notifyOnCameraError(type, message) {
  1553. this._sendEvent({
  1554. name: 'camera-error',
  1555. type,
  1556. message
  1557. });
  1558. }
  1559. /**
  1560. * Notify external application of an unexpected mic-related error having
  1561. * occurred.
  1562. *
  1563. * @param {string} type - The type of the mic error.
  1564. * @param {string} message - Additional information about the error.
  1565. * @returns {void}
  1566. */
  1567. notifyOnMicError(type, message) {
  1568. this._sendEvent({
  1569. name: 'mic-error',
  1570. type,
  1571. message
  1572. });
  1573. }
  1574. /**
  1575. * Notify external application (if API is enabled) that conference feedback
  1576. * has been submitted. Intended to be used in conjunction with the
  1577. * submit-feedback command to get notified if feedback was submitted.
  1578. *
  1579. * @param {string} error - A failure message, if any.
  1580. * @returns {void}
  1581. */
  1582. notifyFeedbackSubmitted(error) {
  1583. this._sendEvent({
  1584. name: 'feedback-submitted',
  1585. error
  1586. });
  1587. }
  1588. /**
  1589. * Notify external application (if API is enabled) that the feedback prompt
  1590. * has been displayed.
  1591. *
  1592. * @returns {void}
  1593. */
  1594. notifyFeedbackPromptDisplayed() {
  1595. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1596. }
  1597. /**
  1598. * Notify external application (if API is enabled) that the display
  1599. * configuration of the filmstrip has been changed.
  1600. *
  1601. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1602. * be displayed or hidden.
  1603. * @returns {void}
  1604. */
  1605. notifyFilmstripDisplayChanged(visible) {
  1606. this._sendEvent({
  1607. name: 'filmstrip-display-changed',
  1608. visible
  1609. });
  1610. }
  1611. /**
  1612. * Notify external application of a participant, remote or local, being
  1613. * removed from the conference by another participant.
  1614. *
  1615. * @param {string} kicked - The ID of the participant removed from the
  1616. * conference.
  1617. * @param {string} kicker - The ID of the participant that removed the
  1618. * other participant.
  1619. * @returns {void}
  1620. */
  1621. notifyKickedOut(kicked, kicker) {
  1622. this._sendEvent({
  1623. name: 'participant-kicked-out',
  1624. kicked,
  1625. kicker
  1626. });
  1627. }
  1628. /**
  1629. * Notify external application of the current meeting requiring a password
  1630. * to join.
  1631. *
  1632. * @returns {void}
  1633. */
  1634. notifyOnPasswordRequired() {
  1635. this._sendEvent({ name: 'password-required' });
  1636. }
  1637. /**
  1638. * Notify external application (if API is enabled) that the screen sharing
  1639. * has been turned on/off.
  1640. *
  1641. * @param {boolean} on - True if screen sharing is enabled.
  1642. * @param {Object} details - Additional information about the screen
  1643. * sharing.
  1644. * @param {string} details.sourceType - Type of device or window the screen
  1645. * share is capturing.
  1646. * @returns {void}
  1647. */
  1648. notifyScreenSharingStatusChanged(on, details) {
  1649. this._sendEvent({
  1650. name: 'screen-sharing-status-changed',
  1651. on,
  1652. details
  1653. });
  1654. }
  1655. /**
  1656. * Notify external application (if API is enabled) that the dominant speaker
  1657. * has been turned on/off.
  1658. *
  1659. * @param {string} id - Id of the dominant participant.
  1660. * @returns {void}
  1661. */
  1662. notifyDominantSpeakerChanged(id) {
  1663. this._sendEvent({
  1664. name: 'dominant-speaker-changed',
  1665. id
  1666. });
  1667. }
  1668. /**
  1669. * Notify external application (if API is enabled) that the conference
  1670. * changed their subject.
  1671. *
  1672. * @param {string} subject - Conference subject.
  1673. * @returns {void}
  1674. */
  1675. notifySubjectChanged(subject) {
  1676. this._sendEvent({
  1677. name: 'subject-change',
  1678. subject
  1679. });
  1680. }
  1681. /**
  1682. * Notify external application (if API is enabled) that tile view has been
  1683. * entered or exited.
  1684. *
  1685. * @param {string} enabled - True if tile view is currently displayed, false
  1686. * otherwise.
  1687. * @returns {void}
  1688. */
  1689. notifyTileViewChanged(enabled) {
  1690. this._sendEvent({
  1691. name: 'tile-view-changed',
  1692. enabled
  1693. });
  1694. }
  1695. /**
  1696. * Notify external application (if API is enabled) that the localStorage has changed.
  1697. *
  1698. * @param {string} localStorageContent - The new localStorageContent.
  1699. * @returns {void}
  1700. */
  1701. notifyLocalStorageChanged(localStorageContent) {
  1702. this._sendEvent({
  1703. name: 'local-storage-changed',
  1704. localStorageContent
  1705. });
  1706. }
  1707. /**
  1708. * Notify external application (if API is enabled) that user updated their hand raised.
  1709. *
  1710. * @param {string} id - User id.
  1711. * @param {boolean} handRaised - Whether user has raised hand.
  1712. * @returns {void}
  1713. */
  1714. notifyRaiseHandUpdated(id, handRaised) {
  1715. this._sendEvent({
  1716. name: 'raise-hand-updated',
  1717. handRaised,
  1718. id
  1719. });
  1720. }
  1721. /**
  1722. * Notify external application (if API is enabled) that recording has started or stopped.
  1723. *
  1724. * @param {boolean} on - True if recording is on, false otherwise.
  1725. * @param {string} mode - Stream or file or local.
  1726. * @param {string} error - Error type or null if success.
  1727. * @returns {void}
  1728. */
  1729. notifyRecordingStatusChanged(on, mode, error) {
  1730. this._sendEvent({
  1731. name: 'recording-status-changed',
  1732. on,
  1733. mode,
  1734. error
  1735. });
  1736. }
  1737. /**
  1738. * Notify external application (if API is enabled) that the current recording link is
  1739. * available.
  1740. *
  1741. * @param {string} link - The recording download link.
  1742. * @param {number} ttl - The recording download link time to live.
  1743. * @returns {void}
  1744. */
  1745. notifyRecordingLinkAvailable(link, ttl) {
  1746. this._sendEvent({
  1747. name: 'recording-link-available',
  1748. link,
  1749. ttl
  1750. });
  1751. }
  1752. /**
  1753. * Notify external application (if API is enabled) that a participant is knocking in the lobby.
  1754. *
  1755. * @param {Object} participant - Participant data such as id and name.
  1756. * @returns {void}
  1757. */
  1758. notifyKnockingParticipant(participant) {
  1759. this._sendEvent({
  1760. name: 'knocking-participant',
  1761. participant
  1762. });
  1763. }
  1764. /**
  1765. * Notify external application (if API is enabled) that an error occurred.
  1766. *
  1767. * @param {Object} error - The error.
  1768. * @returns {void}
  1769. */
  1770. notifyError(error) {
  1771. this._sendEvent({
  1772. name: 'error-occurred',
  1773. error
  1774. });
  1775. }
  1776. /**
  1777. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1778. *
  1779. * @param {string} key - The key of the toolbar button.
  1780. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1781. * @returns {void}
  1782. */
  1783. notifyToolbarButtonClicked(key, preventExecution) {
  1784. this._sendEvent({
  1785. name: 'toolbar-button-clicked',
  1786. key,
  1787. preventExecution
  1788. });
  1789. }
  1790. /**
  1791. * Notify external application (if API is enabled) that the user received
  1792. * a transcription chunk.
  1793. *
  1794. * @param {Object} data - The event data.
  1795. * @returns {void}
  1796. */
  1797. notifyTranscriptionChunkReceived(data) {
  1798. this._sendEvent({
  1799. name: 'transcription-chunk-received',
  1800. data
  1801. });
  1802. }
  1803. /**
  1804. * Notify external application (if API is enabled) whether the used browser is supported or not.
  1805. *
  1806. * @param {boolean} supported - If browser is supported or not.
  1807. * @returns {void}
  1808. */
  1809. notifyBrowserSupport(supported) {
  1810. this._sendEvent({
  1811. name: 'browser-support',
  1812. supported
  1813. });
  1814. }
  1815. /**
  1816. * Notify external application that the breakout rooms changed.
  1817. *
  1818. * @param {Array} rooms - Array containing the breakout rooms and main room.
  1819. * @returns {void}
  1820. */
  1821. notifyBreakoutRoomsUpdated(rooms) {
  1822. this._sendEvent({
  1823. name: 'breakout-rooms-updated',
  1824. rooms
  1825. });
  1826. }
  1827. /**
  1828. * Notify the external application that the state of the participants pane changed.
  1829. *
  1830. * @param {boolean} open - Whether the panel is open or not.
  1831. * @returns {void}
  1832. */
  1833. notifyParticipantsPaneToggled(open) {
  1834. this._sendEvent({
  1835. name: 'participants-pane-toggled',
  1836. open
  1837. });
  1838. }
  1839. /**
  1840. * Notify the external application that the audio or video is being shared by a participant.
  1841. *
  1842. * @param {string} mediaType - Whether the content which is being shared is audio or video.
  1843. * @param {string} value - Whether the sharing is playing, pause or stop (on audio there is only playing and stop).
  1844. * @param {string} participantId - Participant id of the participant which started or ended
  1845. * the video or audio sharing.
  1846. * @returns {void}
  1847. */
  1848. notifyAudioOrVideoSharingToggled(mediaType, value, participantId) {
  1849. this._sendEvent({
  1850. name: 'audio-or-video-sharing-toggled',
  1851. mediaType,
  1852. value,
  1853. participantId
  1854. });
  1855. }
  1856. /**
  1857. * Notify the external application that a PeerConnection lost connectivity. This event is fired only if
  1858. * a PC `failed` but connectivity to the rtcstats server is still maintained signaling that there is a
  1859. * problem establishing a link between the app and the JVB server or the remote peer in case of P2P.
  1860. * Will only fire if rtcstats is enabled.
  1861. *
  1862. * @param {boolean} isP2P - Type of PC.
  1863. * @param {boolean} wasConnected - Was this connection previously connected. If it was it could mean
  1864. * that connectivity was disrupted, if not it most likely means that the app could not reach
  1865. * the JVB server, or the other peer in case of P2P.
  1866. *
  1867. * @returns {void}
  1868. */
  1869. notifyPeerConnectionFailure(isP2P, wasConnected) {
  1870. this._sendEvent({
  1871. name: 'peer-connection-failure',
  1872. isP2P,
  1873. wasConnected
  1874. });
  1875. }
  1876. /**
  1877. * Notify external application ( if API is enabled) that a participant menu button was clicked.
  1878. *
  1879. * @param {string} key - The key of the participant menu button.
  1880. * @param {string} participantId - The ID of the participant for whom the participant menu button was clicked.
  1881. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1882. * @returns {void}
  1883. */
  1884. notifyParticipantMenuButtonClicked(key, participantId, preventExecution) {
  1885. this._sendEvent({
  1886. name: 'participant-menu-button-clicked',
  1887. key,
  1888. participantId,
  1889. preventExecution
  1890. });
  1891. }
  1892. /**
  1893. * Notify external application (if API is enabled) if whiteboard state is
  1894. * changed.
  1895. *
  1896. * @param {WhiteboardStatus} status - The new whiteboard status.
  1897. * @returns {void}
  1898. */
  1899. notifyWhiteboardStatusChanged(status) {
  1900. this._sendEvent({
  1901. name: 'whiteboard-status-changed',
  1902. status
  1903. });
  1904. }
  1905. /**
  1906. * Notify external application (if API is enabled) if non participant message
  1907. * is received.
  1908. *
  1909. * @param {string} id - The resource id of the sender.
  1910. * @param {Object} json - The json carried by the message.
  1911. * @returns {void}
  1912. */
  1913. notifyNonParticipantMessageReceived(id, json) {
  1914. this._sendEvent({
  1915. name: 'non-participant-message-received',
  1916. id,
  1917. message: json
  1918. });
  1919. }
  1920. /**
  1921. * Notify the external application (if API is enabled) if the connection type changed.
  1922. *
  1923. * @param {boolean} isP2p - Whether the new connection is P2P.
  1924. * @returns {void}
  1925. */
  1926. notifyP2pStatusChanged(isP2p) {
  1927. this._sendEvent({
  1928. name: 'p2p-status-changed',
  1929. isP2p
  1930. });
  1931. }
  1932. /**
  1933. * Notify the external application (if API is enabled) when the compute pressure changed.
  1934. *
  1935. * @param {Array} records - The new pressure records.
  1936. * @returns {void}
  1937. */
  1938. notifyComputePressureChanged(records) {
  1939. this._sendEvent({
  1940. name: 'compute-pressure-changed',
  1941. records
  1942. });
  1943. }
  1944. /**
  1945. * Disposes the allocated resources.
  1946. *
  1947. * @returns {void}
  1948. */
  1949. dispose() {
  1950. if (this._enabled) {
  1951. this._enabled = false;
  1952. }
  1953. }
  1954. }
  1955. export default new API();