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

JitsiConferenceEventManager.js 26KB

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