選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JitsiConferenceEventManager.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /* global __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import { Strophe } from 'strophe.js';
  4. import * as JitsiConferenceErrors from './JitsiConferenceErrors';
  5. import * as JitsiConferenceEvents from './JitsiConferenceEvents';
  6. import Statistics from './modules/statistics/statistics';
  7. import EventEmitterForwarder from './modules/util/EventEmitterForwarder';
  8. import * as MediaType from './service/RTC/MediaType';
  9. import RTCEvents from './service/RTC/RTCEvents';
  10. import VideoType from './service/RTC/VideoType';
  11. import AuthenticationEvents
  12. from './service/authentication/AuthenticationEvents';
  13. import {
  14. ACTION_JINGLE_SA_TIMEOUT,
  15. createBridgeDownEvent,
  16. createConnectionStageReachedEvent,
  17. createFocusLeftEvent,
  18. createJingleEvent,
  19. createRemotelyMutedEvent
  20. } from './service/statistics/AnalyticsEvents';
  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. chatRoom.addListener(XMPPEvents.RENEGOTIATION_FAILED, (e, session) => {
  123. if (!session.isP2P) {
  124. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  125. JitsiConferenceErrors.OFFER_ANSWER_FAILED, e);
  126. }
  127. });
  128. this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,
  129. JitsiConferenceEvents.CONFERENCE_FAILED,
  130. JitsiConferenceErrors.CONNECTION_ERROR);
  131. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_ERROR,
  132. JitsiConferenceEvents.CONFERENCE_FAILED,
  133. JitsiConferenceErrors.CONNECTION_ERROR);
  134. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR,
  135. JitsiConferenceEvents.CONFERENCE_FAILED,
  136. JitsiConferenceErrors.NOT_ALLOWED_ERROR);
  137. this.chatRoomForwarder.forward(XMPPEvents.ROOM_CONNECT_MEMBERS_ONLY_ERROR,
  138. JitsiConferenceEvents.CONFERENCE_FAILED,
  139. JitsiConferenceErrors.MEMBERS_ONLY_ERROR);
  140. this.chatRoomForwarder.forward(XMPPEvents.ROOM_MAX_USERS_ERROR,
  141. JitsiConferenceEvents.CONFERENCE_FAILED,
  142. JitsiConferenceErrors.CONFERENCE_MAX_USERS);
  143. this.chatRoomForwarder.forward(XMPPEvents.PASSWORD_REQUIRED,
  144. JitsiConferenceEvents.CONFERENCE_FAILED,
  145. JitsiConferenceErrors.PASSWORD_REQUIRED);
  146. this.chatRoomForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED,
  147. JitsiConferenceEvents.CONFERENCE_FAILED,
  148. JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  149. this.chatRoomForwarder.forward(XMPPEvents.BRIDGE_DOWN,
  150. JitsiConferenceEvents.CONFERENCE_FAILED,
  151. JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  152. chatRoom.addListener(
  153. XMPPEvents.BRIDGE_DOWN,
  154. () => Statistics.sendAnalytics(createBridgeDownEvent()));
  155. this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
  156. JitsiConferenceEvents.CONFERENCE_FAILED,
  157. JitsiConferenceErrors.RESERVATION_ERROR);
  158. this.chatRoomForwarder.forward(XMPPEvents.GRACEFUL_SHUTDOWN,
  159. JitsiConferenceEvents.CONFERENCE_FAILED,
  160. JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  161. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  162. jingleSession => {
  163. conference._onIceConnectionFailed(jingleSession);
  164. });
  165. this.chatRoomForwarder.forward(XMPPEvents.MUC_DESTROYED,
  166. JitsiConferenceEvents.CONFERENCE_FAILED,
  167. JitsiConferenceErrors.CONFERENCE_DESTROYED);
  168. this.chatRoomForwarder.forward(XMPPEvents.CHAT_ERROR_RECEIVED,
  169. JitsiConferenceEvents.CONFERENCE_ERROR,
  170. JitsiConferenceErrors.CHAT_ERROR);
  171. this.chatRoomForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED,
  172. JitsiConferenceEvents.CONFERENCE_FAILED,
  173. JitsiConferenceErrors.FOCUS_DISCONNECTED);
  174. chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
  175. () => {
  176. Statistics.sendAnalytics(createFocusLeftEvent());
  177. conference.eventEmitter.emit(
  178. JitsiConferenceEvents.CONFERENCE_FAILED,
  179. JitsiConferenceErrors.FOCUS_LEFT);
  180. });
  181. chatRoom.addListener(XMPPEvents.SESSION_ACCEPT_TIMEOUT,
  182. jingleSession => {
  183. Statistics.sendAnalyticsAndLog(
  184. createJingleEvent(
  185. ACTION_JINGLE_SA_TIMEOUT,
  186. { p2p: jingleSession.isP2P }));
  187. });
  188. chatRoom.addListener(XMPPEvents.RECORDER_STATE_CHANGED,
  189. (session, jid) => {
  190. if (jid) {
  191. const participant = conference.getParticipantById(
  192. Strophe.getResourceFromJid(jid));
  193. if (session.getStatus() === 'off') {
  194. session.setTerminator(participant);
  195. } else if (session.getStatus() === 'on') {
  196. session.setInitiator(participant);
  197. }
  198. }
  199. conference.eventEmitter.emit(
  200. JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  201. session);
  202. });
  203. this.chatRoomForwarder.forward(XMPPEvents.TRANSCRIPTION_STATUS_CHANGED,
  204. JitsiConferenceEvents.TRANSCRIPTION_STATUS_CHANGED);
  205. this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
  206. JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
  207. this.chatRoomForwarder.forward(
  208. XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
  209. JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED);
  210. this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
  211. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  212. chatRoom.setParticipantPropertyListener((node, from) => {
  213. const participant = conference.getParticipantById(from);
  214. if (!participant) {
  215. return;
  216. }
  217. participant.setProperty(
  218. node.tagName.substring('jitsi_participant_'.length),
  219. node.value);
  220. });
  221. chatRoom.addListener(XMPPEvents.KICKED,
  222. conference.onMemberKicked.bind(conference));
  223. chatRoom.addListener(XMPPEvents.SUSPEND_DETECTED,
  224. conference.onSuspendDetected.bind(conference));
  225. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOCK_CHANGED,
  226. JitsiConferenceEvents.LOCK_STATE_CHANGED);
  227. this.chatRoomForwarder.forward(XMPPEvents.MUC_MEMBERS_ONLY_CHANGED,
  228. JitsiConferenceEvents.MEMBERS_ONLY_CHANGED);
  229. chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
  230. conference.onMemberJoined.bind(conference));
  231. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOBBY_MEMBER_JOINED,
  232. JitsiConferenceEvents.LOBBY_USER_JOINED);
  233. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOBBY_MEMBER_UPDATED,
  234. JitsiConferenceEvents.LOBBY_USER_UPDATED);
  235. this.chatRoomForwarder.forward(XMPPEvents.MUC_LOBBY_MEMBER_LEFT,
  236. JitsiConferenceEvents.LOBBY_USER_LEFT);
  237. chatRoom.addListener(XMPPEvents.MUC_MEMBER_BOT_TYPE_CHANGED,
  238. conference._onMemberBotTypeChanged.bind(conference));
  239. chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
  240. conference.onMemberLeft.bind(conference));
  241. this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
  242. JitsiConferenceEvents.CONFERENCE_LEFT);
  243. this.chatRoomForwarder.forward(XMPPEvents.MUC_DENIED_ACCESS,
  244. JitsiConferenceEvents.CONFERENCE_FAILED,
  245. JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED);
  246. chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
  247. conference.onDisplayNameChanged.bind(conference));
  248. chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
  249. conference.onLocalRoleChanged(role);
  250. // log all events for the recorder operated by the moderator
  251. if (conference.statistics && conference.isModerator()) {
  252. conference.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED,
  253. recorderSession => {
  254. const logObject = {
  255. error: recorderSession.getError(),
  256. id: 'recorder_status',
  257. status: recorderSession.getStatus()
  258. };
  259. Statistics.sendLog(JSON.stringify(logObject));
  260. });
  261. }
  262. });
  263. chatRoom.addListener(XMPPEvents.MUC_ROLE_CHANGED,
  264. conference.onUserRoleChanged.bind(conference));
  265. chatRoom.addListener(AuthenticationEvents.IDENTITY_UPDATED,
  266. (authEnabled, authIdentity) => {
  267. conference.authEnabled = authEnabled;
  268. conference.authIdentity = authIdentity;
  269. conference.eventEmitter.emit(
  270. JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled,
  271. authIdentity);
  272. });
  273. chatRoom.addListener(
  274. XMPPEvents.MESSAGE_RECEIVED,
  275. // eslint-disable-next-line max-params
  276. (jid, displayName, txt, myJid, ts) => {
  277. const id = Strophe.getResourceFromJid(jid);
  278. conference.eventEmitter.emit(
  279. JitsiConferenceEvents.MESSAGE_RECEIVED,
  280. id, txt, ts, displayName);
  281. });
  282. chatRoom.addListener(
  283. XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
  284. // eslint-disable-next-line max-params
  285. (jid, displayName, txt, myJid, ts) => {
  286. const id = Strophe.getResourceFromJid(jid);
  287. conference.eventEmitter.emit(
  288. JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
  289. id, txt, ts);
  290. });
  291. chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
  292. (jid, status) => {
  293. const id = Strophe.getResourceFromJid(jid);
  294. const participant = conference.getParticipantById(id);
  295. if (!participant || participant._status === status) {
  296. return;
  297. }
  298. participant._status = status;
  299. conference.eventEmitter.emit(
  300. JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  301. });
  302. chatRoom.addListener(XMPPEvents.JSON_MESSAGE_RECEIVED,
  303. (from, payload) => {
  304. const id = Strophe.getResourceFromJid(from);
  305. const participant = conference.getParticipantById(id);
  306. if (participant) {
  307. conference.eventEmitter.emit(
  308. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  309. participant, payload);
  310. } else {
  311. logger.warn(
  312. 'Ignored XMPPEvents.JSON_MESSAGE_RECEIVED for not existing '
  313. + `participant: ${from}`,
  314. payload);
  315. }
  316. });
  317. chatRoom.addPresenceListener('startmuted', (data, from) => {
  318. let isModerator = false;
  319. if (conference.myUserId() === from && conference.isModerator()) {
  320. isModerator = true;
  321. } else {
  322. const participant = conference.getParticipantById(from);
  323. if (participant && participant.isModerator()) {
  324. isModerator = true;
  325. }
  326. }
  327. if (!isModerator) {
  328. return;
  329. }
  330. const startAudioMuted = data.attributes.audio === 'true';
  331. const startVideoMuted = data.attributes.video === 'true';
  332. let updated = false;
  333. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  334. conference.startMutedPolicy.audio = startAudioMuted;
  335. updated = true;
  336. }
  337. if (startVideoMuted !== conference.startMutedPolicy.video) {
  338. conference.startMutedPolicy.video = startVideoMuted;
  339. updated = true;
  340. }
  341. if (updated) {
  342. conference.eventEmitter.emit(
  343. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  344. conference.startMutedPolicy
  345. );
  346. }
  347. });
  348. if (conference.statistics) {
  349. // FIXME ICE related events should end up in RTCEvents eventually
  350. chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
  351. session => {
  352. conference.statistics.sendIceConnectionFailedEvent(
  353. session.peerconnection);
  354. });
  355. // FIXME XMPPEvents.ADD_ICE_CANDIDATE_FAILED is never emitted
  356. chatRoom.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  357. (e, pc) => {
  358. conference.statistics.sendAddIceCandidateFailed(e, pc);
  359. });
  360. }
  361. };
  362. /**
  363. * Setups event listeners related to conference.rtc
  364. */
  365. JitsiConferenceEventManager.prototype.setupRTCListeners = function() {
  366. const conference = this.conference;
  367. const rtc = conference.rtc;
  368. rtc.addListener(
  369. RTCEvents.REMOTE_TRACK_ADDED,
  370. conference.onRemoteTrackAdded.bind(conference));
  371. rtc.addListener(
  372. RTCEvents.REMOTE_TRACK_REMOVED,
  373. conference.onRemoteTrackRemoved.bind(conference));
  374. rtc.addListener(RTCEvents.DOMINANT_SPEAKER_CHANGED,
  375. id => {
  376. if (conference.lastDominantSpeaker !== id && conference.room) {
  377. conference.lastDominantSpeaker = id;
  378. conference.eventEmitter.emit(
  379. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  380. if (conference.statistics && conference.myUserId() === id) {
  381. // We are the new dominant speaker.
  382. conference.statistics.sendDominantSpeakerEvent(
  383. conference.room.roomjid);
  384. }
  385. }
  386. });
  387. rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, () => {
  388. const now = window.performance.now();
  389. const key = 'data.channel.opened';
  390. // TODO: Move all of the 'connectionTimes' logic to its own module.
  391. logger.log(`(TIME) ${key}:\t`, now);
  392. conference.room.connectionTimes[key] = now;
  393. Statistics.sendAnalytics(
  394. createConnectionStageReachedEvent(key, { value: now }));
  395. conference.eventEmitter.emit(JitsiConferenceEvents.DATA_CHANNEL_OPENED);
  396. });
  397. rtc.addListener(RTCEvents.ENDPOINT_MESSAGE_RECEIVED,
  398. (from, payload) => {
  399. const participant = conference.getParticipantById(from);
  400. if (participant) {
  401. conference.eventEmitter.emit(
  402. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  403. participant, payload);
  404. } else {
  405. logger.warn(
  406. 'Ignored ENDPOINT_MESSAGE_RECEIVED for not existing '
  407. + `participant: ${from}`,
  408. payload);
  409. }
  410. });
  411. rtc.addListener(RTCEvents.LOCAL_UFRAG_CHANGED,
  412. (tpc, ufrag) => {
  413. if (!tpc.isP2P) {
  414. Statistics.sendLog(
  415. JSON.stringify({
  416. id: 'local_ufrag',
  417. value: ufrag
  418. }));
  419. }
  420. });
  421. rtc.addListener(RTCEvents.REMOTE_UFRAG_CHANGED,
  422. (tpc, ufrag) => {
  423. if (!tpc.isP2P) {
  424. Statistics.sendLog(
  425. JSON.stringify({
  426. id: 'remote_ufrag',
  427. value: ufrag
  428. }));
  429. }
  430. });
  431. rtc.addListener(RTCEvents.CREATE_ANSWER_FAILED,
  432. (e, tpc) => {
  433. conference.statistics.sendCreateAnswerFailed(e, tpc);
  434. if (!tpc.isP2P) {
  435. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  436. JitsiConferenceErrors.OFFER_ANSWER_FAILED, e);
  437. }
  438. });
  439. rtc.addListener(RTCEvents.CREATE_OFFER_FAILED,
  440. (e, tpc) => {
  441. conference.statistics.sendCreateOfferFailed(e, tpc);
  442. if (!tpc.isP2P) {
  443. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  444. JitsiConferenceErrors.OFFER_ANSWER_FAILED, e);
  445. }
  446. });
  447. rtc.addListener(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  448. (e, tpc) => {
  449. conference.statistics.sendSetLocalDescFailed(e, tpc);
  450. if (!tpc.isP2P) {
  451. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  452. JitsiConferenceErrors.OFFER_ANSWER_FAILED, e);
  453. }
  454. });
  455. rtc.addListener(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  456. (e, tpc) => {
  457. conference.statistics.sendSetRemoteDescFailed(e, tpc);
  458. if (!tpc.isP2P) {
  459. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  460. JitsiConferenceErrors.OFFER_ANSWER_FAILED, e);
  461. }
  462. });
  463. rtc.addListener(RTCEvents.LOCAL_TRACK_SSRC_UPDATED,
  464. (track, ssrc) => {
  465. // when starting screen sharing, the track is created and when
  466. // we do set local description and we process the ssrc we
  467. // will be notified for it and we will report it with the event
  468. // for screen sharing
  469. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP) {
  470. conference.statistics.sendScreenSharingEvent(true, ssrc);
  471. }
  472. });
  473. };
  474. /**
  475. * Removes event listeners related to conference.xmpp
  476. */
  477. JitsiConferenceEventManager.prototype.removeXMPPListeners = function() {
  478. const conference = this.conference;
  479. conference.xmpp.caps.removeListener(
  480. XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  481. this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED]);
  482. delete this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED];
  483. Object.keys(this.xmppListeners).forEach(eventName => {
  484. conference.xmpp.removeListener(
  485. eventName,
  486. this.xmppListeners[eventName]);
  487. });
  488. this.xmppListeners = {};
  489. };
  490. /**
  491. * Setups event listeners related to conference.xmpp
  492. */
  493. JitsiConferenceEventManager.prototype.setupXMPPListeners = function() {
  494. const conference = this.conference;
  495. const featuresChangedListener = from => {
  496. const participant
  497. = conference.getParticipantById(
  498. Strophe.getResourceFromJid(from));
  499. if (participant) {
  500. conference.eventEmitter.emit(
  501. JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  502. participant);
  503. }
  504. };
  505. conference.xmpp.caps.addListener(
  506. XMPPEvents.PARTCIPANT_FEATURES_CHANGED,
  507. featuresChangedListener);
  508. this.xmppListeners[XMPPEvents.PARTCIPANT_FEATURES_CHANGED]
  509. = featuresChangedListener;
  510. this._addConferenceXMPPListener(
  511. XMPPEvents.CALL_INCOMING,
  512. conference.onIncomingCall.bind(conference));
  513. this._addConferenceXMPPListener(
  514. XMPPEvents.CALL_ACCEPTED,
  515. conference.onCallAccepted.bind(conference));
  516. this._addConferenceXMPPListener(
  517. XMPPEvents.TRANSPORT_INFO,
  518. conference.onTransportInfo.bind(conference));
  519. this._addConferenceXMPPListener(
  520. XMPPEvents.CALL_ENDED,
  521. conference.onCallEnded.bind(conference));
  522. this._addConferenceXMPPListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  523. (audioMuted, videoMuted) => {
  524. if (conference.options.config.ignoreStartMuted) {
  525. return;
  526. }
  527. conference.startAudioMuted = audioMuted;
  528. conference.startVideoMuted = videoMuted;
  529. // mute existing local tracks because this is initial mute from
  530. // Jicofo
  531. conference.getLocalTracks().forEach(track => {
  532. switch (track.getType()) {
  533. case MediaType.AUDIO:
  534. conference.startAudioMuted && track.mute();
  535. break;
  536. case MediaType.VIDEO:
  537. conference.startVideoMuted && track.mute();
  538. break;
  539. }
  540. });
  541. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  542. });
  543. this._addConferenceXMPPListener(XMPPEvents.CONFERENCE_TIMESTAMP_RECEIVED,
  544. createdTimestamp => {
  545. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_CREATED_TIMESTAMP, createdTimestamp);
  546. });
  547. };
  548. /**
  549. * Add XMPP listener and save its reference for remove on leave conference.
  550. */
  551. JitsiConferenceEventManager.prototype._addConferenceXMPPListener = function(
  552. eventName, listener) {
  553. this.xmppListeners[eventName] = listener;
  554. this.conference.xmpp.addListener(eventName, listener);
  555. };
  556. /**
  557. * Setups event listeners related to conference.statistics
  558. */
  559. JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
  560. const conference = this.conference;
  561. if (!conference.statistics) {
  562. return;
  563. }
  564. /* eslint-disable max-params */
  565. conference.statistics.addAudioLevelListener((tpc, ssrc, level, isLocal) => {
  566. conference.rtc.setAudioLevel(tpc, ssrc, level, isLocal);
  567. });
  568. /* eslint-enable max-params */
  569. // Forward the "before stats disposed" event
  570. conference.statistics.addBeforeDisposedListener(() => {
  571. conference.eventEmitter.emit(
  572. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
  573. });
  574. // if we are in startSilent mode we will not be sending/receiving so nothing to detect
  575. if (!conference.options.config.startSilent) {
  576. conference.statistics.addByteSentStatsListener((tpc, stats) => {
  577. conference.getLocalTracks(MediaType.AUDIO).forEach(track => {
  578. const ssrc = tpc.getLocalSSRC(track);
  579. if (!ssrc || !stats.hasOwnProperty(ssrc)) {
  580. return;
  581. }
  582. track._onByteSentStatsReceived(tpc, stats[ssrc]);
  583. });
  584. });
  585. }
  586. };