Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

JitsiConferenceEventManager.js 23KB

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