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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
  200. JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
  201. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  202. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  203. chatRoom.addListener(
  204. XMPPEvents.CONFERENCE_SETUP_FAILED,
  205. (jingleSession, error) => {
  206. if (!jingleSession.isP2P) {
  207. conference.eventEmitter.emit(
  208. JitsiConferenceEvents.CONFERENCE_FAILED,
  209. JitsiConferenceErrors.SETUP_FAILED,
  210. error);
  211. }
  212. });
  213. chatRoom.setParticipantPropertyListener((node, from) => {
  214. const participant = conference.getParticipantById(from);
  215. if (!participant) {
  216. return;
  217. }
  218. participant.setProperty(
  219. node.tagName.substring('jitsi_participant_'.length),
  220. node.value);
  221. });
  222. this.chatRoomForwarder.forward(XMPPEvents.KICKED,
  223. JitsiConferenceEvents.KICKED);
  224. chatRoom.addListener(XMPPEvents.KICKED,
  225. () => {
  226. conference.room = null;
  227. conference.leave();
  228. });
  229. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  230. conference.onSuspendDetected.bind(conference));
  231. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  232. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  233. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  234. conference.onMemberJoined.bind(conference));
  235. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  236. conference.onMemberLeft.bind(conference));
  237. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  238. JitsiConferenceEvents.CONFERENCE_LEFT);
  239. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  240. conference.onDisplayNameChanged.bind(conference));
  241. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  242. conference.onLocalRoleChanged(role);
  243. // log all events for the recorder operated by the moderator
  244. if (conference.statistics && conference.isModerator()) {
  245. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  246. (status, error) => {
  247. const logObject = {
  248. id: 'recorder_status',
  249. status
  250. };
  251. if (error) {
  252. logObject.error = error;
  253. }
  254. Statistics.sendLog(JSON.stringify(logObject));
  255. });
  256. }
  257. });
  258. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  259. conference.onUserRoleChanged.bind(conference));
  260. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  261. (authEnabled, authIdentity) => {
  262. conference.authEnabled = authEnabled;
  263. conference.authIdentity = authIdentity;
  264. conference.eventEmitter.emit(
  265. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  266. authIdentity);
  267. });
  268. chatRoom.addListener(
  269. XMPPEvents.MESSAGE_RECEIVED,
  270. // eslint-disable-next-line max-params
  271. (jid, displayName, txt, myJid, ts) => {
  272. const id = Strophe.getResourceFromJid(jid);
  273. conference.eventEmitter.emit(
  274. JitsiConferenceEvents.MESSAGE_RECEIVED,
  275. id, txt, ts);
  276. });
  277. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  278. (jid, status) => {
  279. const id = Strophe.getResourceFromJid(jid);
  280. const participant = conference.getParticipantById(id);
  281. if (!participant || participant._status === status) {
  282. return;
  283. }
  284. participant._status = status;
  285. conference.eventEmitter.emit(
  286. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  287. });
  288. chatRoom.addPresenceListener('startmuted', (data, from) => {
  289. let isModerator = false;
  290. if (conference.myUserId() === from && conference.isModerator()) {
  291. isModerator = true;
  292. } else {
  293. const participant = conference.getParticipantById(from);
  294. if (participant && participant.isModerator()) {
  295. isModerator = true;
  296. }
  297. }
  298. if (!isModerator) {
  299. return;
  300. }
  301. const startAudioMuted = data.attributes.audio === 'true';
  302. const startVideoMuted = data.attributes.video === 'true';
  303. let updated = false;
  304. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  305. conference.startMutedPolicy.audio = startAudioMuted;
  306. updated = true;
  307. }
  308. if (startVideoMuted !== conference.startMutedPolicy.video) {
  309. conference.startMutedPolicy.video = startVideoMuted;
  310. updated = true;
  311. }
  312. if (updated) {
  313. conference.eventEmitter.emit(
  314. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  315. conference.startMutedPolicy
  316. );
  317. }
  318. });
  319. chatRoom.addPresenceListener('devices', (data, from) => {
  320. let isAudioAvailable = false;
  321. let isVideoAvailable = false;
  322. data.children.forEach(config => {
  323. if (config.tagName === 'audio') {
  324. isAudioAvailable = config.value === 'true';
  325. }
  326. if (config.tagName === 'video') {
  327. isVideoAvailable = config.value === 'true';
  328. }
  329. });
  330. let availableDevices;
  331. if (conference.myUserId() === from) {
  332. availableDevices = conference.availableDevices;
  333. } else {
  334. const participant = conference.getParticipantById(from);
  335. if (!participant) {
  336. return;
  337. }
  338. availableDevices = participant._availableDevices;
  339. }
  340. let updated = false;
  341. if (availableDevices.audio !== isAudioAvailable) {
  342. updated = true;
  343. availableDevices.audio = isAudioAvailable;
  344. }
  345. if (availableDevices.video !== isVideoAvailable) {
  346. updated = true;
  347. availableDevices.video = isVideoAvailable;
  348. }
  349. if (updated) {
  350. conference.eventEmitter.emit(
  351. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  352. from, availableDevices);
  353. }
  354. });
  355. if (conference.statistics) {
  356. // FIXME ICE related events should end up in RTCEvents eventually
  357. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  358. (session, pc) => {
  359. conference.statistics.sendIceConnectionFailedEvent(pc);
  360. });
  361. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  362. (e, pc) => {
  363. conference.statistics.sendAddIceCandidateFailed(e, pc);
  364. });
  365. }
  366. };
  367. /**
  368. * Setups event listeners related to conference.rtc
  369. */
  370. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  371. const conference = this.conference;
  372. const rtc = conference.rtc;
  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. rtc.addListener(
  399. RTCEvents.AVAILABLE_DEVICES_CHANGED,
  400. devices => conference.room.updateDeviceAvailability(devices));
  401. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  402. (from, payload) => {
  403. const participant = conference.getParticipantById(from);
  404. if (participant) {
  405. conference.eventEmitter.emit(
  406. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  407. participant, payload);
  408. } else {
  409. logger.warn(
  410. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  411. + `participant: ${from}`,
  412. payload);
  413. }
  414. });
  415. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  416. (tpc, ufrag) => {
  417. if (!tpc.isP2P) {
  418. Statistics.sendLog(
  419. JSON.stringify({
  420. id: 'local_ufrag',
  421. value: ufrag
  422. }));
  423. }
  424. });
  425. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  426. (tpc, ufrag) => {
  427. if (!tpc.isP2P) {
  428. Statistics.sendLog(
  429. JSON.stringify({
  430. id: 'remote_ufrag',
  431. value: ufrag
  432. }));
  433. }
  434. });
  435. if (conference.statistics) {
  436. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  437. (e, pc) => {
  438. conference.statistics.sendCreateAnswerFailed(e, pc);
  439. });
  440. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  441. (e, pc) => {
  442. conference.statistics.sendCreateOfferFailed(e, pc);
  443. });
  444. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  445. (e, pc) => {
  446. conference.statistics.sendSetLocalDescFailed(e, pc);
  447. });
  448. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  449. (e, pc) => {
  450. conference.statistics.sendSetRemoteDescFailed(e, pc);
  451. });
  452. }
  453. };
  454. /**
  455. * Setups event listeners related to conference.xmpp
  456. */
  457. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  458. const conference = this.conference;
  459. conference.xmpp.caps.addListener(XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  460. from => {
  461. const participant
  462. = conference.getParticipantId(
  463. Strophe.getResourceFromJid(from));
  464. if (participant) {
  465. conference.eventEmitter.emit(
  466. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  467. participant);
  468. }
  469. });
  470. conference.xmpp.addListener(
  471. XMPPEvents.CALL_INCOMING,
  472. conference.onIncomingCall.bind(conference));
  473. conference.xmpp.addListener(
  474. XMPPEvents.CALL_ACCEPTED,
  475. conference.onCallAccepted.bind(conference));
  476. conference.xmpp.addListener(
  477. XMPPEvents.TRANSPORT_INFO,
  478. conference.onTransportInfo.bind(conference));
  479. conference.xmpp.addListener(
  480. XMPPEvents.CALL_ENDED,
  481. conference.onCallEnded.bind(conference));
  482. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  483. (audioMuted, videoMuted) => {
  484. if (conference.options.config.ignoreStartMuted) {
  485. return;
  486. }
  487. conference.startAudioMuted = audioMuted;
  488. conference.startVideoMuted = videoMuted;
  489. // mute existing local tracks because this is initial mute from
  490. // Jicofo
  491. conference.getLocalTracks().forEach(track => {
  492. switch (track.getType()) {
  493. case MediaType.AUDIO:
  494. conference.startAudioMuted && track.mute();
  495. break;
  496. case MediaType.VIDEO:
  497. conference.startVideoMuted && track.mute();
  498. break;
  499. }
  500. });
  501. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  502. });
  503. };
  504. /**
  505. * Setups event listeners related to conference.statistics
  506. */
  507. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  508. const conference = this.conference;
  509. if (!conference.statistics) {
  510. return;
  511. }
  512. conference.statistics.addAudioLevelListener((ssrc, level) => {
  513. conference.rtc.setAudioLevel(ssrc, level);
  514. });
  515. // Forward the "before stats disposed" event
  516. conference.statistics.addBeforeDisposedListener(() => {
  517. conference.eventEmitter.emit(
  518. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  519. });
  520. conference.statistics.addConnectionStatsListener(stats => {
  521. stats.resolution = mapResolutionsByUserId(conference, stats.resolution);
  522. stats.framerate = mapFrameratesByUserId(conference, stats.framerate);
  523. conference.eventEmitter.emit(
  524. JitsiConferenceEvents.CONNECTION_STATS, stats);
  525. });
  526. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  527. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  528. const ssrc = tpc.getLocalSSRC(track);
  529. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  530. return;
  531. }
  532. track._setByteSent(tpc, stats[ssrc]);
  533. });
  534. });
  535. };
  536. module.exports = JitsiConferenceEventManager;