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

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