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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. this.xmppListeners = {};
  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. }
  48. /**
  49. * Setups event listeners related to conference.chatRoom
  50. */
  51. JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
  52. const conference = this.conference;
  53. const chatRoom = conference.room;
  54. this.chatRoomForwarder = new EventEmitterForwarder(chatRoom,
  55. this.conference.eventEmitter);
  56. chatRoom.addListener(XMPPEvents.ICE_RESTARTING, jingleSession => {
  57. if (!jingleSession.isP2P) {
  58. // If using DataChannel as bridge channel, it must be closed
  59. // before ICE restart, otherwise Chrome will not trigger "opened"
  60. // event for the channel established with the new bridge.
  61. // TODO: This may be bypassed when using a WebSocket as bridge
  62. // channel.
  63. conference.rtc.closeBridgeChannel();
  64. }
  65. // else: there are no DataChannels in P2P session (at least for now)
  66. });
  67. chatRoom.addListener(
  68. XMPPEvents.ICE_RESTART_SUCCESS,
  69. (jingleSession, offerIq) => {
  70. // The JVB data chanel needs to be reopened in case the conference
  71. // has been moved to a new bridge.
  72. !jingleSession.isP2P
  73. && conference._setBridgeChannel(
  74. offerIq, jingleSession.peerconnection);
  75. });
  76. chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  77. () => {
  78. // TODO: Add a way to differentiate between commands which caused
  79. // us to mute and those that did not change our state (i.e. we were
  80. // already muted).
  81. Statistics.sendAnalytics(createRemotelyMutedEvent());
  82. // set isMutedByFocus when setAudioMute Promise ends
  83. conference.rtc.setAudioMute(true).then(
  84. () => {
  85. conference.isMutedByFocus = true;
  86. },
  87. () =>
  88. logger.warn(
  89. 'Error while audio muting due to focus request'));
  90. }
  91. );
  92. this.chatRoomForwarder.forward(XMPPEvents.SUBJECT_CHANGED,
  93. JitsiConferenceEvents.SUBJECT_CHANGED);
  94. this.chatRoomForwarder.forward(XMPPEvents.MUC_JOINED,
  95. JitsiConferenceEvents.CONFERENCE_JOINED);
  96. // send some analytics events
  97. chatRoom.addListener(XMPPEvents.MUC_JOINED,
  98. () => {
  99. this.conference.isJvbConnectionInterrupted = false;
  100. // TODO: Move all of the 'connectionTimes' logic to its own module.
  101. Object.keys(chatRoom.connectionTimes).forEach(key => {
  102. const event
  103. = createConnectionStageReachedEvent(
  104. `conference_${key}`,
  105. { value: chatRoom.connectionTimes[key] });
  106. Statistics.sendAnalytics(event);
  107. });
  108. // TODO: Move all of the 'connectionTimes' logic to its own module.
  109. Object.keys(chatRoom.xmpp.connectionTimes).forEach(key => {
  110. const event
  111. = createConnectionStageReachedEvent(
  112. `xmpp_${key}`,
  113. { value: chatRoom.xmpp.connectionTimes[key] });
  114. Statistics.sendAnalytics(event);
  115. });
  116. });
  117. this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,
  118. JitsiConferenceEvents.CONFERENCE_FAILED,
  119. JitsiConferenceErrors.CONNECTION_ERROR);
  120. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_ERROR,
  121. JitsiConferenceEvents.CONFERENCE_FAILED,
  122. JitsiConferenceErrors.CONNECTION_ERROR);
  123. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR,
  124. JitsiConferenceEvents.CONFERENCE_FAILED,
  125. JitsiConferenceErrors.NOT_ALLOWED_ERROR);
  126. this.chatRoomForwarder.forward(XMPPEvents.ROOM_MAX_USERS_ERROR,
  127. JitsiConferenceEvents.CONFERENCE_FAILED,
  128. JitsiConferenceErrors.CONFERENCE_MAX_USERS);
  129. this.chatRoomForwarder.forward(XMPPEvents.PASSWORD_REQUIRED,
  130. JitsiConferenceEvents.CONFERENCE_FAILED,
  131. JitsiConferenceErrors.PASSWORD_REQUIRED);
  132. this.chatRoomForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED,
  133. JitsiConferenceEvents.CONFERENCE_FAILED,
  134. JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  135. this.chatRoomForwarder.forward(XMPPEvents.BRIDGE_DOWN,
  136. JitsiConferenceEvents.CONFERENCE_FAILED,
  137. JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  138. chatRoom.addListener(
  139. XMPPEvents.BRIDGE_DOWN,
  140. () => Statistics.sendAnalytics(createBridgeDownEvent()));
  141. this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
  142. JitsiConferenceEvents.CONFERENCE_FAILED,
  143. JitsiConferenceErrors.RESERVATION_ERROR);
  144. this.chatRoomForwarder.forward(XMPPEvents.GRACEFUL_SHUTDOWN,
  145. JitsiConferenceEvents.CONFERENCE_FAILED,
  146. JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  147. chatRoom.addListener(XMPPEvents.JINGLE_FATAL_ERROR,
  148. (session, error) => {
  149. if (!session.isP2P) {
  150. conference.eventEmitter.emit(
  151. JitsiConferenceEvents.CONFERENCE_FAILED,
  152. JitsiConferenceErrors.JINGLE_FATAL_ERROR, error);
  153. }
  154. });
  155. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  156. jingleSession => {
  157. conference._onIceConnectionFailed(jingleSession);
  158. });
  159. this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
  160. JitsiConferenceEvents.CONFERENCE_FAILED,
  161. JitsiConferenceErrors.CONFERENCE_DESTROYED);
  162. this.chatRoomForwarder.forward(XMPPEvents.CHAT_ERROR_RECEIVED,
  163. JitsiConferenceEvents.CONFERENCE_ERROR,
  164. JitsiConferenceErrors.CHAT_ERROR);
  165. this.chatRoomForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED,
  166. JitsiConferenceEvents.CONFERENCE_FAILED,
  167. JitsiConferenceErrors.FOCUS_DISCONNECTED);
  168. chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
  169. () => {
  170. Statistics.sendAnalytics(createFocusLeftEvent());
  171. conference.eventEmitter.emit(
  172. JitsiConferenceEvents.CONFERENCE_FAILED,
  173. JitsiConferenceErrors.FOCUS_LEFT);
  174. });
  175. chatRoom.addListener(XMPPEvents.SESSION_ACCEPT_TIMEOUT,
  176. jingleSession => {
  177. Statistics.sendAnalyticsAndLog(
  178. createJingleEvent(
  179. ACTION_JINGLE_SA_TIMEOUT,
  180. { p2p: jingleSession.isP2P }));
  181. });
  182. this.chatRoomForwarder.forward(XMPPEvents.RECORDER_STATE_CHANGED,
  183. JitsiConferenceEvents.RECORDER_STATE_CHANGED);
  184. this.chatRoomForwarder.forward(XMPPEvents.TRANSCRIPTION_STATUS_CHANGED,
  185. JitsiConferenceEvents.TRANSCRIPTION_STATUS_CHANGED);
  186. this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
  187. JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
  188. this.chatRoomForwarder.forward(
  189. XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
  190. JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED);
  191. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  192. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  193. chatRoom.addListener(
  194. XMPPEvents.CONFERENCE_SETUP_FAILED,
  195. (jingleSession, error) => {
  196. if (!jingleSession.isP2P) {
  197. conference.eventEmitter.emit(
  198. JitsiConferenceEvents.CONFERENCE_FAILED,
  199. JitsiConferenceErrors.SETUP_FAILED,
  200. error);
  201. }
  202. });
  203. chatRoom.setParticipantPropertyListener((node, from) => {
  204. const participant = conference.getParticipantById(from);
  205. if (!participant) {
  206. return;
  207. }
  208. participant.setProperty(
  209. node.tagName.substring('jitsi_participant_'.length),
  210. node.value);
  211. });
  212. this.chatRoomForwarder.forward(XMPPEvents.KICKED,
  213. JitsiConferenceEvents.KICKED);
  214. chatRoom.addListener(XMPPEvents.KICKED,
  215. () => {
  216. conference.leave();
  217. });
  218. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  219. conference.onSuspendDetected.bind(conference));
  220. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  221. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  222. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  223. conference.onMemberJoined.bind(conference));
  224. chatRoom.addListener(XMPPEvents.MUC_MEMBER_BOT_TYPE_CHANGED,
  225. conference._onMemberBotTypeChanged.bind(conference));
  226. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  227. conference.onMemberLeft.bind(conference));
  228. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  229. JitsiConferenceEvents.CONFERENCE_LEFT);
  230. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  231. conference.onDisplayNameChanged.bind(conference));
  232. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  233. conference.onLocalRoleChanged(role);
  234. // log all events for the recorder operated by the moderator
  235. if (conference.statistics && conference.isModerator()) {
  236. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  237. recorderSession => {
  238. const logObject = {
  239. error: recorderSession.getError(),
  240. id: 'recorder_status',
  241. status: recorderSession.getStatus()
  242. };
  243. Statistics.sendLog(JSON.stringify(logObject));
  244. });
  245. }
  246. });
  247. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  248. conference.onUserRoleChanged.bind(conference));
  249. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  250. (authEnabled, authIdentity) => {
  251. conference.authEnabled = authEnabled;
  252. conference.authIdentity = authIdentity;
  253. conference.eventEmitter.emit(
  254. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  255. authIdentity);
  256. });
  257. chatRoom.addListener(
  258. XMPPEvents.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.MESSAGE_RECEIVED,
  264. id, txt, ts);
  265. });
  266. chatRoom.addListener(
  267. XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
  268. // eslint-disable-next-line max-params
  269. (jid, displayName, txt, myJid, ts) => {
  270. const id = Strophe.getResourceFromJid(jid);
  271. conference.eventEmitter.emit(
  272. JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
  273. id, txt, ts);
  274. });
  275. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  276. (jid, status) => {
  277. const id = Strophe.getResourceFromJid(jid);
  278. const participant = conference.getParticipantById(id);
  279. if (!participant || participant._status === status) {
  280. return;
  281. }
  282. participant._status = status;
  283. conference.eventEmitter.emit(
  284. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  285. });
  286. chatRoom.addListener(XMPPEvents.JSON_MESSAGE_RECEIVED,
  287. (from, payload) => {
  288. const id = Strophe.getResourceFromJid(from);
  289. const participant = conference.getParticipantById(id);
  290. if (participant) {
  291. conference.eventEmitter.emit(
  292. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  293. participant, payload);
  294. } else {
  295. logger.warn(
  296. 'Ignored XMPPEvents.JSON_MESSAGE_RECEIVED for not existing '
  297. + `participant: ${from}`,
  298. payload);
  299. }
  300. });
  301. chatRoom.addPresenceListener('startmuted', (data, from) => {
  302. let isModerator = false;
  303. if (conference.myUserId() === from && conference.isModerator()) {
  304. isModerator = true;
  305. } else {
  306. const participant = conference.getParticipantById(from);
  307. if (participant && participant.isModerator()) {
  308. isModerator = true;
  309. }
  310. }
  311. if (!isModerator) {
  312. return;
  313. }
  314. const startAudioMuted = data.attributes.audio === 'true';
  315. const startVideoMuted = data.attributes.video === 'true';
  316. let updated = false;
  317. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  318. conference.startMutedPolicy.audio = startAudioMuted;
  319. updated = true;
  320. }
  321. if (startVideoMuted !== conference.startMutedPolicy.video) {
  322. conference.startMutedPolicy.video = startVideoMuted;
  323. updated = true;
  324. }
  325. if (updated) {
  326. conference.eventEmitter.emit(
  327. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  328. conference.startMutedPolicy
  329. );
  330. }
  331. });
  332. if (conference.statistics) {
  333. // FIXME ICE related events should end up in RTCEvents eventually
  334. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  335. session => {
  336. conference.statistics.sendIceConnectionFailedEvent(
  337. session.peerconnection);
  338. });
  339. // FIXME XMPPEvents.ADD_ICE_CANDIDATE_FAILED is never emitted
  340. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  341. (e, pc) => {
  342. conference.statistics.sendAddIceCandidateFailed(e, pc);
  343. });
  344. }
  345. };
  346. /**
  347. * Setups event listeners related to conference.rtc
  348. */
  349. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  350. const conference = this.conference;
  351. const rtc = conference.rtc;
  352. rtc.addListener(
  353. RTCEvents.REMOTE_TRACK_ADDED,
  354. conference.onRemoteTrackAdded.bind(conference));
  355. rtc.addListener(
  356. RTCEvents.REMOTE_TRACK_REMOVED,
  357. conference.onRemoteTrackRemoved.bind(conference));
  358. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  359. id => {
  360. if (conference.lastDominantSpeaker !== id && conference.room) {
  361. conference.lastDominantSpeaker = id;
  362. conference.eventEmitter.emit(
  363. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  364. }
  365. if (conference.statistics && conference.myUserId() === id) {
  366. // We are the new dominant speaker.
  367. conference.statistics.sendDominantSpeakerEvent(
  368. conference.room.roomjid);
  369. }
  370. });
  371. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  372. const now = window.performance.now();
  373. const key = 'data.channel.opened';
  374. // TODO: Move all of the 'connectionTimes' logic to its own module.
  375. logger.log(`(TIME) ${key}`, now);
  376. conference.room.connectionTimes[key] = now;
  377. Statistics.sendAnalytics(
  378. createConnectionStageReachedEvent(key, { value: now }));
  379. conference.eventEmitter.emit(JitsiConferenceEvents.DATA_CHANNEL_OPENED);
  380. });
  381. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  382. (from, payload) => {
  383. const participant = conference.getParticipantById(from);
  384. if (participant) {
  385. conference.eventEmitter.emit(
  386. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  387. participant, payload);
  388. } else {
  389. logger.warn(
  390. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  391. + `participant: ${from}`,
  392. payload);
  393. }
  394. });
  395. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  396. (tpc, ufrag) => {
  397. if (!tpc.isP2P) {
  398. Statistics.sendLog(
  399. JSON.stringify({
  400. id: 'local_ufrag',
  401. value: ufrag
  402. }));
  403. }
  404. });
  405. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  406. (tpc, ufrag) => {
  407. if (!tpc.isP2P) {
  408. Statistics.sendLog(
  409. JSON.stringify({
  410. id: 'remote_ufrag',
  411. value: ufrag
  412. }));
  413. }
  414. });
  415. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  416. (e, tpc) => {
  417. conference.statistics.sendCreateAnswerFailed(e, tpc);
  418. });
  419. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  420. (e, tpc) => {
  421. conference.statistics.sendCreateOfferFailed(e, tpc);
  422. });
  423. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  424. (e, tpc) => {
  425. conference.statistics.sendSetLocalDescFailed(e, tpc);
  426. });
  427. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  428. (e, tpc) => {
  429. conference.statistics.sendSetRemoteDescFailed(e, tpc);
  430. });
  431. rtc.addListener(RTCEvents.LOCAL_TRACK_SSRC_UPDATED,
  432. (track, ssrc) => {
  433. // when starting screen sharing, the track is created and when
  434. // we do set local description and we process the ssrc we
  435. // will be notified for it and we will report it with the event
  436. // for screen sharing
  437. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP) {
  438. conference.statistics.sendScreenSharingEvent(true, ssrc);
  439. }
  440. });
  441. };
  442. /**
  443. * Removes event listeners related to conference.xmpp
  444. */
  445. JitsiConferenceEventManager.prototype.removeXMPPListeners = function() {
  446. const conference = this.conference;
  447. conference.xmpp.caps.removeListener(
  448. XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  449. this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED]);
  450. delete this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED];
  451. Object.keys(this.xmppListeners).forEach(eventName => {
  452. conference.xmpp.removeListener(
  453. eventName,
  454. this.xmppListeners[eventName]);
  455. });
  456. this.xmppListeners = {};
  457. };
  458. /**
  459. * Setups event listeners related to conference.xmpp
  460. */
  461. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  462. const conference = this.conference;
  463. const featuresChangedListener = from => {
  464. const participant
  465. = conference.getParticipantById(
  466. Strophe.getResourceFromJid(from));
  467. if (participant) {
  468. conference.eventEmitter.emit(
  469. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  470. participant);
  471. }
  472. };
  473. conference.xmpp.caps.addListener(
  474. XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  475. featuresChangedListener);
  476. this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED]
  477. = featuresChangedListener;
  478. this._addConferenceXMPPListener(
  479. XMPPEvents.CALL_INCOMING,
  480. conference.onIncomingCall.bind(conference));
  481. this._addConferenceXMPPListener(
  482. XMPPEvents.CALL_ACCEPTED,
  483. conference.onCallAccepted.bind(conference));
  484. this._addConferenceXMPPListener(
  485. XMPPEvents.TRANSPORT_INFO,
  486. conference.onTransportInfo.bind(conference));
  487. this._addConferenceXMPPListener(
  488. XMPPEvents.CALL_ENDED,
  489. conference.onCallEnded.bind(conference));
  490. this._addConferenceXMPPListener(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. * Add XMPP listener and save its reference for remove on leave conference.
  514. */
  515. JitsiConferenceEventManager.prototype._addConferenceXMPPListener = function(
  516. eventName, listener) {
  517. this.xmppListeners[eventName] = listener;
  518. this.conference.xmpp.addListener(eventName, listener);
  519. };
  520. /**
  521. * Setups event listeners related to conference.statistics
  522. */
  523. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  524. const conference = this.conference;
  525. if (!conference.statistics) {
  526. return;
  527. }
  528. /* eslint-disable max-params */
  529. conference.statistics.addAudioLevelListener((tpc, ssrc, level, isLocal) => {
  530. conference.rtc.setAudioLevel(tpc, ssrc, level, isLocal);
  531. });
  532. /* eslint-enable max-params */
  533. // Forward the "before stats disposed" event
  534. conference.statistics.addBeforeDisposedListener(() => {
  535. conference.eventEmitter.emit(
  536. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  537. });
  538. // if we are in startSilent mode we will not be sending/receiving so nothing to detect
  539. if (!conference.options.config.startSilent) {
  540. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  541. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  542. const ssrc = tpc.getLocalSSRC(track);
  543. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  544. return;
  545. }
  546. track._onByteSentStatsReceived(tpc, stats[ssrc]);
  547. });
  548. });
  549. }
  550. };