Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

JitsiConferenceEventManager.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /* global __filename, Strophe */
  2. import AuthenticationEvents
  3. from './service/authentication/AuthenticationEvents';
  4. import EventEmitterForwarder from './modules/util/EventEmitterForwarder';
  5. import { getLogger } from 'jitsi-meet-logger';
  6. import * as JitsiConferenceErrors from './JitsiConferenceErrors';
  7. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  8. import * as MediaType from './service/RTC/MediaType';
  9. import RTCEvents from './service/RTC/RTCEvents';
  10. import Statistics from './modules/statistics/statistics';
  11. import XMPPEvents from './service/xmpp/XMPPEvents';
  12. const logger = getLogger(__filename);
  13. /**
  14. * Setups all event listeners related to conference
  15. * @param conference {JitsiConference} the conference
  16. */
  17. function JitsiConferenceEventManager(conference) {
  18. this.conference = conference;
  19. // Listeners related to the conference only
  20. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  21. track => {
  22. if (!track.isLocal() || !conference.statistics) {
  23. return;
  24. }
  25. conference.statistics.sendMuteEvent(track.isMuted(),
  26. track.getType());
  27. });
  28. }
  29. /**
  30. * Groups resolutions by user id, skip incorrect resolutions.
  31. * @param conference {JitsiConference} the conference
  32. * @param resolutions map of resolutions by ssrc
  33. */
  34. function mapResolutionsByUserId(conference, resolutions) {
  35. const id2resolution = {};
  36. // preprocess resolutions: group by user id, skip incorrect
  37. // resolutions etc.
  38. Object.keys(resolutions).forEach(ssrc => {
  39. const resolution = resolutions[ssrc];
  40. if (!resolution.width || !resolution.height
  41. || resolution.width === -1 || resolution.height === -1) {
  42. return;
  43. }
  44. const id = conference.rtc.getResourceBySSRC(ssrc);
  45. if (!id) {
  46. return;
  47. }
  48. // ssrc to resolution map for user id
  49. const idResolutions = id2resolution[id] || {};
  50. idResolutions[ssrc] = resolution;
  51. id2resolution[id] = idResolutions;
  52. });
  53. return id2resolution;
  54. }
  55. /**
  56. * Groups framerates by user id, skip framerates with value of 0.
  57. * @param conference {JitsiConference} the conference
  58. * @param framerates map of framerates by ssrc
  59. */
  60. function mapFrameratesByUserId(conference, framerates) {
  61. const id2framerate = {};
  62. // preprocess framerates: group by user id
  63. Object.keys(framerates).forEach(ssrc => {
  64. const framerate = framerates[ssrc];
  65. if (framerate === 0) {
  66. return;
  67. }
  68. const id = conference.rtc.getResourceBySSRC(ssrc);
  69. if (!id) {
  70. return;
  71. }
  72. // ssrc to framerate map for user id
  73. const id2framerates = id2framerate[id] || {};
  74. id2framerates[ssrc] = framerate;
  75. id2framerate[id] = id2framerates;
  76. });
  77. return id2framerate;
  78. }
  79. /**
  80. * Setups event listeners related to conference.chatRoom
  81. */
  82. JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
  83. const conference = this.conference;
  84. const chatRoom = conference.room;
  85. this.chatRoomForwarder = new EventEmitterForwarder(chatRoom,
  86. this.conference.eventEmitter);
  87. chatRoom.addListener(XMPPEvents.ICE_RESTARTING, () => {
  88. // All data channels have to be closed, before ICE restart
  89. // otherwise Chrome will not trigger "opened" event for the channel
  90. // established with the new bridge
  91. conference.rtc.closeAllDataChannels();
  92. });
  93. chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  94. value => {
  95. // set isMutedByFocus when setAudioMute Promise ends
  96. conference.rtc.setAudioMute(value).then(
  97. () => {
  98. conference.isMutedByFocus = true;
  99. },
  100. () =>
  101. logger.warn(
  102. 'Error while audio muting due to focus request'));
  103. }
  104. );
  105. this.chatRoomForwarder.forward(XMPPEvents.SUBJECT_CHANGED,
  106. JitsiConferenceEvents.SUBJECT_CHANGED);
  107. this.chatRoomForwarder.forward(XMPPEvents.MUC_JOINED,
  108. JitsiConferenceEvents.CONFERENCE_JOINED);
  109. // send some analytics events
  110. chatRoom.addListener(XMPPEvents.MUC_JOINED,
  111. () => {
  112. this.conference.connectionIsInterrupted = false;
  113. Object.keys(chatRoom.connectionTimes).forEach(key => {
  114. const value = chatRoom.connectionTimes[key];
  115. Statistics.analytics.sendEvent(`conference.${key}`, { value });
  116. });
  117. Object.keys(chatRoom.xmpp.connectionTimes).forEach(key => {
  118. const value = chatRoom.xmpp.connectionTimes[key];
  119. Statistics.analytics.sendEvent(`xmpp.${key}`, { value });
  120. });
  121. });
  122. this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,
  123. JitsiConferenceEvents.CONFERENCE_FAILED,
  124. JitsiConferenceErrors.CONNECTION_ERROR);
  125. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_ERROR,
  126. JitsiConferenceEvents.CONFERENCE_FAILED,
  127. JitsiConferenceErrors.CONNECTION_ERROR);
  128. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR,
  129. JitsiConferenceEvents.CONFERENCE_FAILED,
  130. JitsiConferenceErrors.NOT_ALLOWED_ERROR);
  131. this.chatRoomForwarder.forward(XMPPEvents.ROOM_MAX_USERS_ERROR,
  132. JitsiConferenceEvents.CONFERENCE_FAILED,
  133. JitsiConferenceErrors.CONFERENCE_MAX_USERS);
  134. this.chatRoomForwarder.forward(XMPPEvents.PASSWORD_REQUIRED,
  135. JitsiConferenceEvents.CONFERENCE_FAILED,
  136. JitsiConferenceErrors.PASSWORD_REQUIRED);
  137. this.chatRoomForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED,
  138. JitsiConferenceEvents.CONFERENCE_FAILED,
  139. JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  140. this.chatRoomForwarder.forward(XMPPEvents.BRIDGE_DOWN,
  141. JitsiConferenceEvents.CONFERENCE_FAILED,
  142. JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  143. chatRoom.addListener(
  144. XMPPEvents.BRIDGE_DOWN,
  145. () => Statistics.analytics.sendEvent('conference.bridgeDown'));
  146. this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
  147. JitsiConferenceEvents.CONFERENCE_FAILED,
  148. JitsiConferenceErrors.RESERVATION_ERROR);
  149. this.chatRoomForwarder.forward(XMPPEvents.GRACEFUL_SHUTDOWN,
  150. JitsiConferenceEvents.CONFERENCE_FAILED,
  151. JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  152. chatRoom.addListener(XMPPEvents.JINGLE_FATAL_ERROR,
  153. (session, error) => {
  154. conference.eventEmitter.emit(
  155. JitsiConferenceEvents.CONFERENCE_FAILED,
  156. JitsiConferenceErrors.JINGLE_FATAL_ERROR, error);
  157. });
  158. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  159. () => {
  160. chatRoom.eventEmitter.emit(
  161. XMPPEvents.CONFERENCE_SETUP_FAILED,
  162. new Error('ICE fail'));
  163. });
  164. this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
  165. JitsiConferenceEvents.CONFERENCE_FAILED,
  166. JitsiConferenceErrors.CONFERENCE_DESTROYED);
  167. this.chatRoomForwarder.forward(XMPPEvents.CHAT_ERROR_RECEIVED,
  168. JitsiConferenceEvents.CONFERENCE_ERROR,
  169. JitsiConferenceErrors.CHAT_ERROR);
  170. this.chatRoomForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED,
  171. JitsiConferenceEvents.CONFERENCE_FAILED,
  172. JitsiConferenceErrors.FOCUS_DISCONNECTED);
  173. chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
  174. () => {
  175. Statistics.analytics.sendEvent('conference.focusLeft');
  176. conference.eventEmitter.emit(
  177. JitsiConferenceEvents.CONFERENCE_FAILED,
  178. JitsiConferenceErrors.FOCUS_LEFT);
  179. });
  180. const eventLogHandler
  181. = reason => Statistics.sendEventToAll(`conference.error.${reason}`);
  182. chatRoom.addListener(XMPPEvents.SESSION_ACCEPT_TIMEOUT,
  183. eventLogHandler.bind(null, 'sessionAcceptTimeout'));
  184. this.chatRoomForwarder.forward(XMPPEvents.CONNECTION_INTERRUPTED,
  185. JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  186. chatRoom.addListener(XMPPEvents.CONNECTION_INTERRUPTED,
  187. () => {
  188. Statistics.sendEventToAll('connection.interrupted');
  189. this.conference.connectionIsInterrupted = true;
  190. });
  191. this.chatRoomForwarder.forward(XMPPEvents.RECORDER_STATE_CHANGED,
  192. JitsiConferenceEvents.RECORDER_STATE_CHANGED);
  193. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  194. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  195. this.chatRoomForwarder.forward(XMPPEvents.CONNECTION_RESTORED,
  196. JitsiConferenceEvents.CONNECTION_RESTORED);
  197. chatRoom.addListener(XMPPEvents.CONNECTION_RESTORED,
  198. () => {
  199. Statistics.sendEventToAll('connection.restored');
  200. this.conference.connectionIsInterrupted = false;
  201. });
  202. this.chatRoomForwarder.forward(XMPPEvents.CONFERENCE_SETUP_FAILED,
  203. JitsiConferenceEvents.CONFERENCE_FAILED,
  204. JitsiConferenceErrors.SETUP_FAILED);
  205. chatRoom.setParticipantPropertyListener((node, from) => {
  206. const participant = conference.getParticipantById(from);
  207. if (!participant) {
  208. return;
  209. }
  210. participant.setProperty(
  211. node.tagName.substring('jitsi_participant_'.length),
  212. node.value);
  213. });
  214. this.chatRoomForwarder.forward(XMPPEvents.KICKED,
  215. JitsiConferenceEvents.KICKED);
  216. chatRoom.addListener(XMPPEvents.KICKED,
  217. () => {
  218. conference.room = null;
  219. conference.leave();
  220. });
  221. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  222. conference.onSuspendDetected.bind(conference));
  223. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  224. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  225. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  226. conference.onMemberJoined.bind(conference));
  227. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  228. conference.onMemberLeft.bind(conference));
  229. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  230. JitsiConferenceEvents.CONFERENCE_LEFT);
  231. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  232. conference.onDisplayNameChanged.bind(conference));
  233. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  234. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED,
  235. conference.myUserId(), role);
  236. // log all events for the recorder operated by the moderator
  237. if (conference.statistics && conference.isModerator()) {
  238. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  239. (status, error) => {
  240. const logObject = {
  241. id: 'recorder_status',
  242. status
  243. };
  244. if (error) {
  245. logObject.error = error;
  246. }
  247. Statistics.sendLog(JSON.stringify(logObject));
  248. });
  249. }
  250. });
  251. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  252. conference.onUserRoleChanged.bind(conference));
  253. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  254. (authEnabled, authIdentity) => {
  255. conference.authEnabled = authEnabled;
  256. conference.authIdentity = authIdentity;
  257. conference.eventEmitter.emit(
  258. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  259. authIdentity);
  260. });
  261. chatRoom.addListener(
  262. XMPPEvents.MESSAGE_RECEIVED,
  263. // eslint-disable-next-line max-params
  264. (jid, displayName, txt, myJid, ts) => {
  265. const id = Strophe.getResourceFromJid(jid);
  266. conference.eventEmitter.emit(
  267. JitsiConferenceEvents.MESSAGE_RECEIVED,
  268. id, txt, ts);
  269. });
  270. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  271. (jid, status) => {
  272. const id = Strophe.getResourceFromJid(jid);
  273. const participant = conference.getParticipantById(id);
  274. if (!participant || participant._status === status) {
  275. return;
  276. }
  277. participant._status = status;
  278. conference.eventEmitter.emit(
  279. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  280. });
  281. conference.room.addListener(XMPPEvents.LOCAL_UFRAG_CHANGED,
  282. ufrag => {
  283. Statistics.sendLog(
  284. JSON.stringify({ id: 'local_ufrag',
  285. value: ufrag }));
  286. });
  287. conference.room.addListener(XMPPEvents.REMOTE_UFRAG_CHANGED,
  288. ufrag => {
  289. Statistics.sendLog(
  290. JSON.stringify({ id: 'remote_ufrag',
  291. value: ufrag }));
  292. });
  293. chatRoom.addPresenceListener('startmuted', (data, from) => {
  294. let isModerator = false;
  295. if (conference.myUserId() === from && conference.isModerator()) {
  296. isModerator = true;
  297. } else {
  298. const participant = conference.getParticipantById(from);
  299. if (participant && participant.isModerator()) {
  300. isModerator = true;
  301. }
  302. }
  303. if (!isModerator) {
  304. return;
  305. }
  306. const startAudioMuted = data.attributes.audio === 'true';
  307. const startVideoMuted = data.attributes.video === 'true';
  308. let updated = false;
  309. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  310. conference.startMutedPolicy.audio = startAudioMuted;
  311. updated = true;
  312. }
  313. if (startVideoMuted !== conference.startMutedPolicy.video) {
  314. conference.startMutedPolicy.video = startVideoMuted;
  315. updated = true;
  316. }
  317. if (updated) {
  318. conference.eventEmitter.emit(
  319. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  320. conference.startMutedPolicy
  321. );
  322. }
  323. });
  324. chatRoom.addPresenceListener('videomuted', (values, from) => {
  325. conference.rtc.handleRemoteTrackMute(MediaType.VIDEO,
  326. values.value === 'true', from);
  327. });
  328. chatRoom.addPresenceListener('audiomuted', (values, from) => {
  329. conference.rtc.handleRemoteTrackMute(MediaType.AUDIO,
  330. values.value === 'true', from);
  331. });
  332. chatRoom.addPresenceListener('videoType', (data, from) => {
  333. conference.rtc.handleRemoteTrackVideoTypeChanged(data.value, from);
  334. });
  335. chatRoom.addPresenceListener('devices', (data, from) => {
  336. let isAudioAvailable = false;
  337. let isVideoAvailable = false;
  338. data.children.forEach(config => {
  339. if (config.tagName === 'audio') {
  340. isAudioAvailable = config.value === 'true';
  341. }
  342. if (config.tagName === 'video') {
  343. isVideoAvailable = config.value === 'true';
  344. }
  345. });
  346. let availableDevices;
  347. if (conference.myUserId() === from) {
  348. availableDevices = conference.availableDevices;
  349. } else {
  350. const participant = conference.getParticipantById(from);
  351. if (!participant) {
  352. return;
  353. }
  354. availableDevices = participant._availableDevices;
  355. }
  356. let updated = false;
  357. if (availableDevices.audio !== isAudioAvailable) {
  358. updated = true;
  359. availableDevices.audio = isAudioAvailable;
  360. }
  361. if (availableDevices.video !== isVideoAvailable) {
  362. updated = true;
  363. availableDevices.video = isVideoAvailable;
  364. }
  365. if (updated) {
  366. conference.eventEmitter.emit(
  367. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  368. from, availableDevices);
  369. }
  370. });
  371. if (conference.statistics) {
  372. // FIXME ICE related events should end up in RTCEvents eventually
  373. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  374. pc => {
  375. conference.statistics.sendIceConnectionFailedEvent(pc);
  376. });
  377. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  378. (e, pc) => {
  379. conference.statistics.sendAddIceCandidateFailed(e, pc);
  380. });
  381. }
  382. };
  383. /**
  384. * Setups event listeners related to conference.rtc
  385. */
  386. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  387. const conference = this.conference;
  388. const rtc = conference.rtc;
  389. this.rtcForwarder
  390. = new EventEmitterForwarder(rtc, this.conference.eventEmitter);
  391. rtc.addListener(
  392. RTCEvents.REMOTE_TRACK_ADDED,
  393. conference.onRemoteTrackAdded.bind(conference));
  394. rtc.addListener(
  395. RTCEvents.REMOTE_TRACK_REMOVED,
  396. conference.onRemoteTrackRemoved.bind(conference));
  397. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  398. id => {
  399. if (conference.lastDominantSpeaker !== id && conference.room) {
  400. conference.lastDominantSpeaker = id;
  401. conference.eventEmitter.emit(
  402. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  403. }
  404. if (conference.statistics && conference.myUserId() === id) {
  405. // We are the new dominant speaker.
  406. conference.statistics.sendDominantSpeakerEvent();
  407. }
  408. });
  409. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  410. const now = window.performance.now();
  411. logger.log('(TIME) data channel opened ', now);
  412. conference.room.connectionTimes['data.channel.opened'] = now;
  413. Statistics.analytics.sendEvent('conference.dataChannel.open',
  414. { value: now });
  415. });
  416. this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,
  417. JitsiConferenceEvents.IN_LAST_N_CHANGED);
  418. this.rtcForwarder.forward(RTCEvents.LASTN_ENDPOINT_CHANGED,
  419. JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED);
  420. rtc.addListener(
  421. RTCEvents.AVAILABLE_DEVICES_CHANGED,
  422. devices => conference.room.updateDeviceAvailability(devices));
  423. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  424. (from, payload) => {
  425. const participant = conference.getParticipantById(from);
  426. if (participant) {
  427. conference.eventEmitter.emit(
  428. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  429. participant, payload);
  430. } else {
  431. logger.warn(
  432. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  433. + `participant: ${from}`,
  434. payload);
  435. }
  436. });
  437. if (conference.statistics) {
  438. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  439. (e, pc) => {
  440. conference.statistics.sendCreateAnswerFailed(e, pc);
  441. });
  442. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  443. (e, pc) => {
  444. conference.statistics.sendCreateOfferFailed(e, pc);
  445. });
  446. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  447. (e, pc) => {
  448. conference.statistics.sendSetLocalDescFailed(e, pc);
  449. });
  450. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  451. (e, pc) => {
  452. conference.statistics.sendSetRemoteDescFailed(e, pc);
  453. });
  454. }
  455. };
  456. /**
  457. * Setups event listeners related to conference.xmpp
  458. */
  459. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  460. const conference = this.conference;
  461. conference.xmpp.caps.addListener(XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  462. from => {
  463. const participant
  464. = conference.getParticipantId(
  465. Strophe.getResourceFromJid(from));
  466. if (participant) {
  467. conference.eventEmitter.emit(
  468. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  469. participant);
  470. }
  471. });
  472. conference.xmpp.addListener(
  473. XMPPEvents.CALL_INCOMING,
  474. conference.onIncomingCall.bind(conference));
  475. conference.xmpp.addListener(
  476. XMPPEvents.CALL_ENDED,
  477. conference.onCallEnded.bind(conference));
  478. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  479. (audioMuted, videoMuted) => {
  480. conference.startAudioMuted = audioMuted;
  481. conference.startVideoMuted = videoMuted;
  482. // mute existing local tracks because this is initial mute from
  483. // Jicofo
  484. conference.getLocalTracks().forEach(track => {
  485. switch (track.getType()) {
  486. case MediaType.AUDIO:
  487. conference.startAudioMuted && track.mute();
  488. break;
  489. case MediaType.VIDEO:
  490. conference.startVideoMuted && track.mute();
  491. break;
  492. }
  493. });
  494. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  495. });
  496. };
  497. /**
  498. * Setups event listeners related to conference.statistics
  499. */
  500. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  501. const conference = this.conference;
  502. if (!conference.statistics) {
  503. return;
  504. }
  505. conference.statistics.addAudioLevelListener((ssrc, level) => {
  506. const resource = conference.rtc.getResourceBySSRC(ssrc);
  507. if (!resource) {
  508. return;
  509. }
  510. conference.rtc.setAudioLevel(resource, level);
  511. });
  512. // Forward the "before stats disposed" event
  513. conference.statistics.addBeforeDisposedListener(() => {
  514. conference.eventEmitter.emit(
  515. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  516. });
  517. conference.statistics.addConnectionStatsListener(stats => {
  518. stats.resolution = mapResolutionsByUserId(conference, stats.resolution);
  519. stats.framerate = mapFrameratesByUserId(conference, stats.framerate);
  520. conference.eventEmitter.emit(
  521. JitsiConferenceEvents.CONNECTION_STATS, stats);
  522. });
  523. conference.statistics.addByteSentStatsListener(stats => {
  524. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  525. const ssrc = track.getSSRC();
  526. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  527. return;
  528. }
  529. track._setByteSent(stats[ssrc]);
  530. });
  531. });
  532. };
  533. module.exports = JitsiConferenceEventManager;