Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JitsiConferenceEventManager.js 26KB

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