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

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