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.

JitsiConferenceEventManager.js 22KB

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