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

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