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

JitsiConferenceEventManager.js 25KB

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