modified lib-jitsi-meet dev repo
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

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