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

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