modified lib-jitsi-meet dev repo
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JitsiConferenceEventManager.js 22KB

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