Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Jvb121EventGenerator.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* global __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  4. const logger = getLogger(__filename);
  5. /**
  6. * Emits {@link JitsiConferenceEvents.JVB121_STATUS} events based on the current
  7. * P2P status and the conference participants count. See the event description
  8. * for more info.
  9. */
  10. export default class Jvb121EventGenerator {
  11. /**
  12. * Creates new <tt>Jvb121EventGenerator</tt> for the given conference.
  13. * @param {JitsiConference} conference
  14. */
  15. constructor(conference) {
  16. this._conference = conference;
  17. /**
  18. * Indicates whether it's a one to one JVB conference (<tt>true</tt>)
  19. * or a multiparty (<tt>false</tt>). Will be also <tt>false</tt> if
  20. * the conference is currently in the P2P mode.
  21. * @type {boolean}
  22. * @private
  23. */
  24. this._jvb121 = true;
  25. this._conference.addEventListener(
  26. JitsiConferenceEvents.USER_JOINED, () => this.evaluateStatus());
  27. this._conference.addEventListener(
  28. JitsiConferenceEvents.USER_LEFT, () => this.evaluateStatus());
  29. this._conference.addEventListener(
  30. JitsiConferenceEvents.P2P_STATUS, () => this.evaluateStatus());
  31. }
  32. /**
  33. * Checks whether the JVB121 value should be updated and a new event
  34. * emitted.
  35. */
  36. evaluateStatus() {
  37. const oldStatus = this._jvb121;
  38. const newStatus
  39. = !this._conference.isP2PActive()
  40. && this._conference.getParticipantCount() <= 2;
  41. if (oldStatus !== newStatus) {
  42. this._jvb121 = newStatus;
  43. logger.debug(`JVB121 status ${oldStatus} => ${newStatus}`);
  44. this._conference.eventEmitter.emit(
  45. JitsiConferenceEvents.JVB121_STATUS, oldStatus, newStatus);
  46. }
  47. }
  48. }