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

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