You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jvb121EventGenerator.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { getLogger } from '@jitsi/logger';
  2. import JitsiConference from '../../JitsiConference';
  3. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  4. const logger = getLogger('modules/event/Jvb121EventGenerator');
  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. private _conference: JitsiConference;
  12. private _jvb121: boolean;
  13. /**
  14. * Creates new <tt>Jvb121EventGenerator</tt> for the given conference.
  15. * @param {JitsiConference} conference
  16. */
  17. constructor(conference: JitsiConference) {
  18. this._conference = conference;
  19. /**
  20. * Indicates whether it's a one to one JVB conference (<tt>true</tt>)
  21. * or a multiparty (<tt>false</tt>). Will be also <tt>false</tt> if
  22. * the conference is currently in the P2P mode.
  23. * @type {boolean}
  24. * @private
  25. */
  26. this._jvb121 = true;
  27. this._conference.addEventListener(
  28. JitsiConferenceEvents.USER_JOINED, () => this.evaluateStatus());
  29. this._conference.addEventListener(
  30. JitsiConferenceEvents.USER_LEFT, () => this.evaluateStatus());
  31. this._conference.addEventListener(
  32. JitsiConferenceEvents.P2P_STATUS, () => this.evaluateStatus());
  33. }
  34. /**
  35. * Checks whether the JVB121 value should be updated and a new event
  36. * emitted.
  37. */
  38. evaluateStatus() {
  39. const oldStatus = this._jvb121;
  40. const newStatus
  41. = !this._conference.isP2PActive()
  42. && this._conference.getParticipantCount() <= 2;
  43. if (oldStatus !== newStatus) {
  44. this._jvb121 = newStatus;
  45. logger.debug(`JVB121 status ${oldStatus} => ${newStatus}`);
  46. this._conference.eventEmitter.emit(
  47. JitsiConferenceEvents.JVB121_STATUS, oldStatus, newStatus);
  48. }
  49. }
  50. }