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

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