You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiConferenceEventManager.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* global __filename */
  2. import { Strophe } from 'strophe.js';
  3. import {
  4. _CONNECTION_TIMES_,
  5. BRIDGE_DOWN,
  6. CONFERENCE_ERROR_,
  7. CONNECTION_INTERRUPTED,
  8. CONNECTION_RESTORED,
  9. DATA_CHANNEL_OPEN,
  10. FOCUS_LEFT,
  11. REMOTELY_MUTED
  12. } from './service/statistics/AnalyticsEvents';
  13. import AuthenticationEvents
  14. from './service/authentication/AuthenticationEvents';
  15. import EventEmitterForwarder from './modules/util/EventEmitterForwarder';
  16. import { getLogger } from 'jitsi-meet-logger';
  17. import * as JitsiConferenceErrors from './JitsiConferenceErrors';
  18. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  19. import * as MediaType from './service/RTC/MediaType';
  20. import RTCEvents from './service/RTC/RTCEvents';
  21. import VideoType from './service/RTC/VideoType';
  22. import Statistics from './modules/statistics/statistics';
  23. import XMPPEvents from './service/xmpp/XMPPEvents';
  24. const logger = getLogger(__filename);
  25. /**
  26. * Setups all event listeners related to conference
  27. * @param conference {JitsiConference} the conference
  28. */
  29. export default function JitsiConferenceEventManager(conference) {
  30. this.conference = conference;
  31. // Listeners related to the conference only
  32. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  33. track => {
  34. if (!track.isLocal() || !conference.statistics) {
  35. return;
  36. }
  37. const session
  38. = track.isP2P
  39. ? conference.p2pJingleSession : conference.jvbJingleSession;
  40. // TPC will be null, before the conference starts, but the event
  41. // still should be queued
  42. const tpc = (session && session.peerconnection) || null;
  43. conference.statistics.sendMuteEvent(
  44. tpc,
  45. track.isMuted(),
  46. track.getType());
  47. });
  48. conference.on(
  49. JitsiConferenceEvents.CONNECTION_INTERRUPTED,
  50. Statistics.sendEventToAll.bind(
  51. Statistics, CONNECTION_INTERRUPTED));
  52. conference.on(
  53. JitsiConferenceEvents.CONNECTION_RESTORED,
  54. Statistics.sendEventToAll.bind(
  55. Statistics, CONNECTION_RESTORED));
  56. }
  57. /**
  58. * Setups event listeners related to conference.chatRoom
  59. */
  60. JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
  61. const conference = this.conference;
  62. const chatRoom = conference.room;
  63. this.chatRoomForwarder = new EventEmitterForwarder(chatRoom,
  64. this.conference.eventEmitter);
  65. chatRoom.addListener(XMPPEvents.ICE_RESTARTING, jingleSession => {
  66. if (!jingleSession.isP2P) {
  67. // If using DataChannel as bridge channel, it must be closed
  68. // before ICE restart, otherwise Chrome will not trigger "opened"
  69. // event for the channel established with the new bridge.
  70. // TODO: This may be bypassed when using a WebSocket as bridge
  71. // channel.
  72. conference.rtc.closeBridgeChannel();
  73. }
  74. // else: there are no DataChannels in P2P session (at least for now)
  75. });
  76. chatRoom.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  77. value => {
  78. Statistics.analytics.sendEvent(REMOTELY_MUTED);
  79. // set isMutedByFocus when setAudioMute Promise ends
  80. conference.rtc.setAudioMute(value).then(
  81. () => {
  82. conference.isMutedByFocus = true;
  83. },
  84. () =>
  85. logger.warn(
  86. 'Error while audio muting due to focus request'));
  87. }
  88. );
  89. this.chatRoomForwarder.forward(XMPPEvents.SUBJECT_CHANGED,
  90. JitsiConferenceEvents.SUBJECT_CHANGED);
  91. this.chatRoomForwarder.forward(XMPPEvents.MUC_JOINED,
  92. JitsiConferenceEvents.CONFERENCE_JOINED);
  93. // send some analytics events
  94. chatRoom.addListener(XMPPEvents.MUC_JOINED,
  95. () => {
  96. this.conference.isJvbConnectionInterrupted = false;
  97. Object.keys(chatRoom.connectionTimes).forEach(key => {
  98. const value = chatRoom.connectionTimes[key];
  99. const eventName = `conference.${_CONNECTION_TIMES_}${key}`;
  100. Statistics.analytics.sendEvent(eventName, { value });
  101. });
  102. Object.keys(chatRoom.xmpp.connectionTimes).forEach(key => {
  103. const value = chatRoom.xmpp.connectionTimes[key];
  104. const eventName = `xmpp.${_CONNECTION_TIMES_}${key}`;
  105. Statistics.analytics.sendEvent(eventName, { value });
  106. });
  107. });
  108. this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,
  109. JitsiConferenceEvents.CONFERENCE_FAILED,
  110. JitsiConferenceErrors.CONNECTION_ERROR);
  111. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_ERROR,
  112. JitsiConferenceEvents.CONFERENCE_FAILED,
  113. JitsiConferenceErrors.CONNECTION_ERROR);
  114. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR,
  115. JitsiConferenceEvents.CONFERENCE_FAILED,
  116. JitsiConferenceErrors.NOT_ALLOWED_ERROR);
  117. this.chatRoomForwarder.forward(XMPPEvents.ROOM_MAX_USERS_ERROR,
  118. JitsiConferenceEvents.CONFERENCE_FAILED,
  119. JitsiConferenceErrors.CONFERENCE_MAX_USERS);
  120. this.chatRoomForwarder.forward(XMPPEvents.PASSWORD_REQUIRED,
  121. JitsiConferenceEvents.CONFERENCE_FAILED,
  122. JitsiConferenceErrors.PASSWORD_REQUIRED);
  123. this.chatRoomForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED,
  124. JitsiConferenceEvents.CONFERENCE_FAILED,
  125. JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  126. this.chatRoomForwarder.forward(XMPPEvents.BRIDGE_DOWN,
  127. JitsiConferenceEvents.CONFERENCE_FAILED,
  128. JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  129. chatRoom.addListener(
  130. XMPPEvents.BRIDGE_DOWN,
  131. () => Statistics.analytics.sendEvent(BRIDGE_DOWN));
  132. this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
  133. JitsiConferenceEvents.CONFERENCE_FAILED,
  134. JitsiConferenceErrors.RESERVATION_ERROR);
  135. this.chatRoomForwarder.forward(XMPPEvents.GRACEFUL_SHUTDOWN,
  136. JitsiConferenceEvents.CONFERENCE_FAILED,
  137. JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  138. chatRoom.addListener(XMPPEvents.JINGLE_FATAL_ERROR,
  139. (session, error) => {
  140. if (!session.isP2P) {
  141. conference.eventEmitter.emit(
  142. JitsiConferenceEvents.CONFERENCE_FAILED,
  143. JitsiConferenceErrors.JINGLE_FATAL_ERROR, error);
  144. }
  145. });
  146. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  147. jingleSession => {
  148. conference._onIceConnectionFailed(jingleSession);
  149. });
  150. this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
  151. JitsiConferenceEvents.CONFERENCE_FAILED,
  152. JitsiConferenceErrors.CONFERENCE_DESTROYED);
  153. this.chatRoomForwarder.forward(XMPPEvents.CHAT_ERROR_RECEIVED,
  154. JitsiConferenceEvents.CONFERENCE_ERROR,
  155. JitsiConferenceErrors.CHAT_ERROR);
  156. this.chatRoomForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED,
  157. JitsiConferenceEvents.CONFERENCE_FAILED,
  158. JitsiConferenceErrors.FOCUS_DISCONNECTED);
  159. chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
  160. () => {
  161. Statistics.analytics.sendEvent(FOCUS_LEFT);
  162. conference.eventEmitter.emit(
  163. JitsiConferenceEvents.CONFERENCE_FAILED,
  164. JitsiConferenceErrors.FOCUS_LEFT);
  165. });
  166. const eventLogHandler
  167. = reason => Statistics.sendEventToAll(`${CONFERENCE_ERROR_}.${reason}`);
  168. chatRoom.addListener(XMPPEvents.SESSION_ACCEPT_TIMEOUT,
  169. jingleSession => {
  170. eventLogHandler(
  171. jingleSession.isP2P
  172. ? 'p2pSessionAcceptTimeout' : 'sessionAcceptTimeout');
  173. });
  174. this.chatRoomForwarder.forward(XMPPEvents.RECORDER_STATE_CHANGED,
  175. JitsiConferenceEvents.RECORDER_STATE_CHANGED);
  176. this.chatRoomForwarder.forward(XMPPEvents.TRANSCRIPTION_STATUS_CHANGED,
  177. JitsiConferenceEvents.TRANSCRIPTION_STATUS_CHANGED);
  178. this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
  179. JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
  180. this.chatRoomForwarder.forward(
  181. XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
  182. JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED);
  183. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  184. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  185. chatRoom.addListener(
  186. XMPPEvents.CONFERENCE_SETUP_FAILED,
  187. (jingleSession, error) => {
  188. if (!jingleSession.isP2P) {
  189. conference.eventEmitter.emit(
  190. JitsiConferenceEvents.CONFERENCE_FAILED,
  191. JitsiConferenceErrors.SETUP_FAILED,
  192. error);
  193. }
  194. });
  195. chatRoom.setParticipantPropertyListener((node, from) => {
  196. const participant = conference.getParticipantById(from);
  197. if (!participant) {
  198. return;
  199. }
  200. participant.setProperty(
  201. node.tagName.substring('jitsi_participant_'.length),
  202. node.value);
  203. });
  204. this.chatRoomForwarder.forward(XMPPEvents.KICKED,
  205. JitsiConferenceEvents.KICKED);
  206. chatRoom.addListener(XMPPEvents.KICKED,
  207. () => {
  208. conference.room = null;
  209. conference.leave();
  210. });
  211. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  212. conference.onSuspendDetected.bind(conference));
  213. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  214. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  215. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  216. conference.onMemberJoined.bind(conference));
  217. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  218. conference.onMemberLeft.bind(conference));
  219. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  220. JitsiConferenceEvents.CONFERENCE_LEFT);
  221. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  222. conference.onDisplayNameChanged.bind(conference));
  223. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  224. conference.onLocalRoleChanged(role);
  225. // log all events for the recorder operated by the moderator
  226. if (conference.statistics && conference.isModerator()) {
  227. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  228. (status, error) => {
  229. const logObject = {
  230. id: 'recorder_status',
  231. status
  232. };
  233. if (error) {
  234. logObject.error = error;
  235. }
  236. Statistics.sendLog(JSON.stringify(logObject));
  237. });
  238. }
  239. });
  240. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  241. conference.onUserRoleChanged.bind(conference));
  242. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  243. (authEnabled, authIdentity) => {
  244. conference.authEnabled = authEnabled;
  245. conference.authIdentity = authIdentity;
  246. conference.eventEmitter.emit(
  247. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  248. authIdentity);
  249. });
  250. chatRoom.addListener(
  251. XMPPEvents.MESSAGE_RECEIVED,
  252. // eslint-disable-next-line max-params
  253. (jid, displayName, txt, myJid, ts) => {
  254. const id = Strophe.getResourceFromJid(jid);
  255. conference.eventEmitter.emit(
  256. JitsiConferenceEvents.MESSAGE_RECEIVED,
  257. id, txt, ts);
  258. });
  259. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  260. (jid, status) => {
  261. const id = Strophe.getResourceFromJid(jid);
  262. const participant = conference.getParticipantById(id);
  263. if (!participant || participant._status === status) {
  264. return;
  265. }
  266. participant._status = status;
  267. conference.eventEmitter.emit(
  268. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  269. });
  270. chatRoom.addListener(XMPPEvents.JSON_MESSAGE_RECEIVED,
  271. (from, payload) => {
  272. const id = Strophe.getResourceFromJid(from);
  273. const participant = conference.getParticipantById(id);
  274. if (participant) {
  275. conference.eventEmitter.emit(
  276. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  277. participant, payload);
  278. } else {
  279. logger.warn(
  280. 'Ignored XMPPEvents.JSON_MESSAGE_RECEIVED for not existing '
  281. + `participant: ${from}`,
  282. payload);
  283. }
  284. });
  285. chatRoom.addPresenceListener('startmuted', (data, from) => {
  286. let isModerator = false;
  287. if (conference.myUserId() === from && conference.isModerator()) {
  288. isModerator = true;
  289. } else {
  290. const participant = conference.getParticipantById(from);
  291. if (participant && participant.isModerator()) {
  292. isModerator = true;
  293. }
  294. }
  295. if (!isModerator) {
  296. return;
  297. }
  298. const startAudioMuted = data.attributes.audio === 'true';
  299. const startVideoMuted = data.attributes.video === 'true';
  300. let updated = false;
  301. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  302. conference.startMutedPolicy.audio = startAudioMuted;
  303. updated = true;
  304. }
  305. if (startVideoMuted !== conference.startMutedPolicy.video) {
  306. conference.startMutedPolicy.video = startVideoMuted;
  307. updated = true;
  308. }
  309. if (updated) {
  310. conference.eventEmitter.emit(
  311. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  312. conference.startMutedPolicy
  313. );
  314. }
  315. });
  316. chatRoom.addPresenceListener('devices', (data, from) => {
  317. let isAudioAvailable = false;
  318. let isVideoAvailable = false;
  319. data.children.forEach(config => {
  320. if (config.tagName === 'audio') {
  321. isAudioAvailable = config.value === 'true';
  322. }
  323. if (config.tagName === 'video') {
  324. isVideoAvailable = config.value === 'true';
  325. }
  326. });
  327. let availableDevices;
  328. if (conference.myUserId() === from) {
  329. availableDevices = conference.availableDevices;
  330. } else {
  331. const participant = conference.getParticipantById(from);
  332. if (!participant) {
  333. return;
  334. }
  335. availableDevices = participant._availableDevices;
  336. }
  337. let updated = false;
  338. if (availableDevices.audio !== isAudioAvailable) {
  339. updated = true;
  340. availableDevices.audio = isAudioAvailable;
  341. }
  342. if (availableDevices.video !== isVideoAvailable) {
  343. updated = true;
  344. availableDevices.video = isVideoAvailable;
  345. }
  346. if (updated) {
  347. conference.eventEmitter.emit(
  348. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  349. from, availableDevices);
  350. }
  351. });
  352. if (conference.statistics) {
  353. // FIXME ICE related events should end up in RTCEvents eventually
  354. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  355. session => {
  356. conference.statistics.sendIceConnectionFailedEvent(
  357. session.peerconnection);
  358. });
  359. // FIXME XMPPEvents.ADD_ICE_CANDIDATE_FAILED is never emitted
  360. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  361. (e, pc) => {
  362. conference.statistics.sendAddIceCandidateFailed(e, pc);
  363. });
  364. }
  365. };
  366. /**
  367. * Setups event listeners related to conference.rtc
  368. */
  369. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  370. const conference = this.conference;
  371. const rtc = conference.rtc;
  372. rtc.addListener(
  373. RTCEvents.REMOTE_TRACK_ADDED,
  374. conference.onRemoteTrackAdded.bind(conference));
  375. rtc.addListener(
  376. RTCEvents.REMOTE_TRACK_REMOVED,
  377. conference.onRemoteTrackRemoved.bind(conference));
  378. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  379. id => {
  380. if (conference.lastDominantSpeaker !== id && conference.room) {
  381. conference.lastDominantSpeaker = id;
  382. conference.eventEmitter.emit(
  383. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  384. }
  385. if (conference.statistics && conference.myUserId() === id) {
  386. // We are the new dominant speaker.
  387. conference.statistics.sendDominantSpeakerEvent();
  388. }
  389. });
  390. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  391. const now = window.performance.now();
  392. logger.log('(TIME) data channel opened ', now);
  393. conference.room.connectionTimes['data.channel.opened'] = now;
  394. Statistics.analytics.sendEvent(DATA_CHANNEL_OPEN, { value: now });
  395. conference.eventEmitter.emit(JitsiConferenceEvents.DATA_CHANNEL_OPENED);
  396. });
  397. rtc.addListener(
  398. RTCEvents.AVAILABLE_DEVICES_CHANGED,
  399. devices => conference.room.updateDeviceAvailability(devices));
  400. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  401. (from, payload) => {
  402. const participant = conference.getParticipantById(from);
  403. if (participant) {
  404. conference.eventEmitter.emit(
  405. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  406. participant, payload);
  407. } else {
  408. logger.warn(
  409. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  410. + `participant: ${from}`,
  411. payload);
  412. }
  413. });
  414. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  415. (tpc, ufrag) => {
  416. if (!tpc.isP2P) {
  417. Statistics.sendLog(
  418. JSON.stringify({
  419. id: 'local_ufrag',
  420. value: ufrag
  421. }));
  422. }
  423. });
  424. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  425. (tpc, ufrag) => {
  426. if (!tpc.isP2P) {
  427. Statistics.sendLog(
  428. JSON.stringify({
  429. id: 'remote_ufrag',
  430. value: ufrag
  431. }));
  432. }
  433. });
  434. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  435. (e, tpc) => {
  436. conference.statistics.sendCreateAnswerFailed(e, tpc);
  437. });
  438. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  439. (e, tpc) => {
  440. conference.statistics.sendCreateOfferFailed(e, tpc);
  441. });
  442. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  443. (e, tpc) => {
  444. conference.statistics.sendSetLocalDescFailed(e, tpc);
  445. });
  446. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  447. (e, tpc) => {
  448. conference.statistics.sendSetRemoteDescFailed(e, tpc);
  449. });
  450. rtc.addListener(RTCEvents.LOCAL_TRACK_SSRC_UPDATED,
  451. (track, ssrc) => {
  452. // when starting screen sharing, the track is created and when
  453. // we do set local description and we process the ssrc we
  454. // will be notified for it and we will report it with the event
  455. // for screen sharing
  456. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP) {
  457. conference.statistics.sendScreenSharingEvent(true, ssrc);
  458. }
  459. });
  460. };
  461. /**
  462. * Setups event listeners related to conference.xmpp
  463. */
  464. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  465. const conference = this.conference;
  466. conference.xmpp.caps.addListener(XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  467. from => {
  468. const participant
  469. = conference.getParticipantById(
  470. Strophe.getResourceFromJid(from));
  471. if (participant) {
  472. conference.eventEmitter.emit(
  473. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  474. participant);
  475. }
  476. });
  477. conference.xmpp.addListener(
  478. XMPPEvents.CALL_INCOMING,
  479. conference.onIncomingCall.bind(conference));
  480. conference.xmpp.addListener(
  481. XMPPEvents.CALL_ACCEPTED,
  482. conference.onCallAccepted.bind(conference));
  483. conference.xmpp.addListener(
  484. XMPPEvents.TRANSPORT_INFO,
  485. conference.onTransportInfo.bind(conference));
  486. conference.xmpp.addListener(
  487. XMPPEvents.CALL_ENDED,
  488. conference.onCallEnded.bind(conference));
  489. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  490. (audioMuted, videoMuted) => {
  491. if (conference.options.config.ignoreStartMuted) {
  492. return;
  493. }
  494. conference.startAudioMuted = audioMuted;
  495. conference.startVideoMuted = videoMuted;
  496. // mute existing local tracks because this is initial mute from
  497. // Jicofo
  498. conference.getLocalTracks().forEach(track => {
  499. switch (track.getType()) {
  500. case MediaType.AUDIO:
  501. conference.startAudioMuted && track.mute();
  502. break;
  503. case MediaType.VIDEO:
  504. conference.startVideoMuted && track.mute();
  505. break;
  506. }
  507. });
  508. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  509. });
  510. };
  511. /**
  512. * Setups event listeners related to conference.statistics
  513. */
  514. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  515. const conference = this.conference;
  516. if (!conference.statistics) {
  517. return;
  518. }
  519. /* eslint-disable max-params */
  520. conference.statistics.addAudioLevelListener((tpc, ssrc, level, isLocal) => {
  521. conference.rtc.setAudioLevel(tpc, ssrc, level, isLocal);
  522. });
  523. /* eslint-enable max-params */
  524. // Forward the "before stats disposed" event
  525. conference.statistics.addBeforeDisposedListener(() => {
  526. conference.eventEmitter.emit(
  527. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  528. });
  529. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  530. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  531. const ssrc = tpc.getLocalSSRC(track);
  532. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  533. return;
  534. }
  535. track._onByteSentStatsReceived(tpc, stats[ssrc]);
  536. });
  537. });
  538. };