您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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