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

JitsiConferenceEventManager.js 29KB

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