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 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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(
  258. XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
  259. // eslint-disable-next-line max-params
  260. (jid, displayName, txt, myJid, ts) => {
  261. const id = Strophe.getResourceFromJid(jid);
  262. conference.eventEmitter.emit(
  263. JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
  264. id, txt, ts);
  265. });
  266. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  267. (jid, status) => {
  268. const id = Strophe.getResourceFromJid(jid);
  269. const participant = conference.getParticipantById(id);
  270. if (!participant || participant._status === status) {
  271. return;
  272. }
  273. participant._status = status;
  274. conference.eventEmitter.emit(
  275. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  276. });
  277. chatRoom.addListener(XMPPEvents.JSON_MESSAGE_RECEIVED,
  278. (from, payload) => {
  279. const id = Strophe.getResourceFromJid(from);
  280. const participant = conference.getParticipantById(id);
  281. if (participant) {
  282. conference.eventEmitter.emit(
  283. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  284. participant, payload);
  285. } else {
  286. logger.warn(
  287. 'Ignored XMPPEvents.JSON_MESSAGE_RECEIVED for not existing '
  288. + `participant: ${from}`,
  289. payload);
  290. }
  291. });
  292. chatRoom.addPresenceListener('startmuted', (data, from) => {
  293. let isModerator = false;
  294. if (conference.myUserId() === from && conference.isModerator()) {
  295. isModerator = true;
  296. } else {
  297. const participant = conference.getParticipantById(from);
  298. if (participant && participant.isModerator()) {
  299. isModerator = true;
  300. }
  301. }
  302. if (!isModerator) {
  303. return;
  304. }
  305. const startAudioMuted = data.attributes.audio === 'true';
  306. const startVideoMuted = data.attributes.video === 'true';
  307. let updated = false;
  308. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  309. conference.startMutedPolicy.audio = startAudioMuted;
  310. updated = true;
  311. }
  312. if (startVideoMuted !== conference.startMutedPolicy.video) {
  313. conference.startMutedPolicy.video = startVideoMuted;
  314. updated = true;
  315. }
  316. if (updated) {
  317. conference.eventEmitter.emit(
  318. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  319. conference.startMutedPolicy
  320. );
  321. }
  322. });
  323. chatRoom.addPresenceListener('devices', (data, from) => {
  324. let isAudioAvailable = false;
  325. let isVideoAvailable = false;
  326. data.children.forEach(config => {
  327. if (config.tagName === 'audio') {
  328. isAudioAvailable = config.value === 'true';
  329. }
  330. if (config.tagName === 'video') {
  331. isVideoAvailable = config.value === 'true';
  332. }
  333. });
  334. let availableDevices;
  335. if (conference.myUserId() === from) {
  336. availableDevices = conference.availableDevices;
  337. } else {
  338. const participant = conference.getParticipantById(from);
  339. if (!participant) {
  340. return;
  341. }
  342. availableDevices = participant._availableDevices;
  343. }
  344. let updated = false;
  345. if (availableDevices.audio !== isAudioAvailable) {
  346. updated = true;
  347. availableDevices.audio = isAudioAvailable;
  348. }
  349. if (availableDevices.video !== isVideoAvailable) {
  350. updated = true;
  351. availableDevices.video = isVideoAvailable;
  352. }
  353. if (updated) {
  354. conference.eventEmitter.emit(
  355. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  356. from, availableDevices);
  357. }
  358. });
  359. if (conference.statistics) {
  360. // FIXME ICE related events should end up in RTCEvents eventually
  361. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  362. session => {
  363. conference.statistics.sendIceConnectionFailedEvent(
  364. session.peerconnection);
  365. });
  366. // FIXME XMPPEvents.ADD_ICE_CANDIDATE_FAILED is never emitted
  367. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  368. (e, pc) => {
  369. conference.statistics.sendAddIceCandidateFailed(e, pc);
  370. });
  371. }
  372. };
  373. /**
  374. * Setups event listeners related to conference.rtc
  375. */
  376. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  377. const conference = this.conference;
  378. const rtc = conference.rtc;
  379. rtc.addListener(
  380. RTCEvents.REMOTE_TRACK_ADDED,
  381. conference.onRemoteTrackAdded.bind(conference));
  382. rtc.addListener(
  383. RTCEvents.REMOTE_TRACK_REMOVED,
  384. conference.onRemoteTrackRemoved.bind(conference));
  385. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  386. id => {
  387. if (conference.lastDominantSpeaker !== id && conference.room) {
  388. conference.lastDominantSpeaker = id;
  389. conference.eventEmitter.emit(
  390. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  391. }
  392. if (conference.statistics && conference.myUserId() === id) {
  393. // We are the new dominant speaker.
  394. conference.statistics.sendDominantSpeakerEvent();
  395. }
  396. });
  397. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  398. const now = window.performance.now();
  399. const key = 'data.channel.opened';
  400. // TODO: Move all of the 'connectionTimes' logic to its own module.
  401. logger.log(`(TIME) ${key}`, now);
  402. conference.room.connectionTimes[key] = now;
  403. Statistics.sendAnalytics(
  404. createConnectionStageReachedEvent(key, { value: now }));
  405. conference.eventEmitter.emit(JitsiConferenceEvents.DATA_CHANNEL_OPENED);
  406. });
  407. rtc.addListener(
  408. RTCEvents.AVAILABLE_DEVICES_CHANGED,
  409. devices => conference.room.updateDeviceAvailability(devices));
  410. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  411. (from, payload) => {
  412. const participant = conference.getParticipantById(from);
  413. if (participant) {
  414. conference.eventEmitter.emit(
  415. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  416. participant, payload);
  417. } else {
  418. logger.warn(
  419. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  420. + `participant: ${from}`,
  421. payload);
  422. }
  423. });
  424. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  425. (tpc, ufrag) => {
  426. if (!tpc.isP2P) {
  427. Statistics.sendLog(
  428. JSON.stringify({
  429. id: 'local_ufrag',
  430. value: ufrag
  431. }));
  432. }
  433. });
  434. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  435. (tpc, ufrag) => {
  436. if (!tpc.isP2P) {
  437. Statistics.sendLog(
  438. JSON.stringify({
  439. id: 'remote_ufrag',
  440. value: ufrag
  441. }));
  442. }
  443. });
  444. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  445. (e, tpc) => {
  446. conference.statistics.sendCreateAnswerFailed(e, tpc);
  447. });
  448. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  449. (e, tpc) => {
  450. conference.statistics.sendCreateOfferFailed(e, tpc);
  451. });
  452. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  453. (e, tpc) => {
  454. conference.statistics.sendSetLocalDescFailed(e, tpc);
  455. });
  456. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  457. (e, tpc) => {
  458. conference.statistics.sendSetRemoteDescFailed(e, tpc);
  459. });
  460. rtc.addListener(RTCEvents.LOCAL_TRACK_SSRC_UPDATED,
  461. (track, ssrc) => {
  462. // when starting screen sharing, the track is created and when
  463. // we do set local description and we process the ssrc we
  464. // will be notified for it and we will report it with the event
  465. // for screen sharing
  466. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP) {
  467. conference.statistics.sendScreenSharingEvent(true, ssrc);
  468. }
  469. });
  470. };
  471. /**
  472. * Setups event listeners related to conference.xmpp
  473. */
  474. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  475. const conference = this.conference;
  476. conference.xmpp.caps.addListener(XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  477. from => {
  478. const participant
  479. = conference.getParticipantById(
  480. Strophe.getResourceFromJid(from));
  481. if (participant) {
  482. conference.eventEmitter.emit(
  483. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  484. participant);
  485. }
  486. });
  487. conference.xmpp.addListener(
  488. XMPPEvents.CALL_INCOMING,
  489. conference.onIncomingCall.bind(conference));
  490. conference.xmpp.addListener(
  491. XMPPEvents.CALL_ACCEPTED,
  492. conference.onCallAccepted.bind(conference));
  493. conference.xmpp.addListener(
  494. XMPPEvents.TRANSPORT_INFO,
  495. conference.onTransportInfo.bind(conference));
  496. conference.xmpp.addListener(
  497. XMPPEvents.CALL_ENDED,
  498. conference.onCallEnded.bind(conference));
  499. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  500. (audioMuted, videoMuted) => {
  501. if (conference.options.config.ignoreStartMuted) {
  502. return;
  503. }
  504. conference.startAudioMuted = audioMuted;
  505. conference.startVideoMuted = videoMuted;
  506. // mute existing local tracks because this is initial mute from
  507. // Jicofo
  508. conference.getLocalTracks().forEach(track => {
  509. switch (track.getType()) {
  510. case MediaType.AUDIO:
  511. conference.startAudioMuted && track.mute();
  512. break;
  513. case MediaType.VIDEO:
  514. conference.startVideoMuted && track.mute();
  515. break;
  516. }
  517. });
  518. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  519. });
  520. };
  521. /**
  522. * Setups event listeners related to conference.statistics
  523. */
  524. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  525. const conference = this.conference;
  526. if (!conference.statistics) {
  527. return;
  528. }
  529. /* eslint-disable max-params */
  530. conference.statistics.addAudioLevelListener((tpc, ssrc, level, isLocal) => {
  531. conference.rtc.setAudioLevel(tpc, ssrc, level, isLocal);
  532. });
  533. /* eslint-enable max-params */
  534. // Forward the "before stats disposed" event
  535. conference.statistics.addBeforeDisposedListener(() => {
  536. conference.eventEmitter.emit(
  537. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  538. });
  539. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  540. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  541. const ssrc = tpc.getLocalSSRC(track);
  542. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  543. return;
  544. }
  545. track._onByteSentStatsReceived(tpc, stats[ssrc]);
  546. });
  547. });
  548. };