Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JitsiConferenceEventManager.js 23KB

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