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.

ComponentsVersions.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { getLogger } from '@jitsi/logger';
  2. const logger = getLogger(__filename);
  3. /**
  4. * Discovers component versions in a conference.
  5. */
  6. export default class ComponentsVersions {
  7. versions: { [key: string]: string; };
  8. conference: any;
  9. /**
  10. * Creates new instance of <tt>ComponentsVersions</tt> which will be discovering
  11. * the versions of conferencing system components in given
  12. * <tt>JitsiConference</tt>.
  13. * @param conference <tt>JitsiConference</tt> instance which will be used to
  14. * listen for focus presence updates.
  15. * @constructor
  16. */
  17. constructor(conference) {
  18. this.versions = {};
  19. this.conference = conference;
  20. this.conference.addCommandListener('versions', this._processVersions.bind(this));
  21. }
  22. /**
  23. * Processes versions information from presence.
  24. *
  25. * @param {*} versions - The versions element.
  26. * @param {*} mucJid - MUC JID for the sender.
  27. * @returns {void}
  28. */
  29. _processVersions(versions, _, mucJid) {
  30. if (!this.conference.isFocus(mucJid)) {
  31. logger.warn(
  32. `Received versions not from the focus user: ${versions}`,
  33. mucJid);
  34. return;
  35. }
  36. versions.children.forEach(component => {
  37. const name = component.attributes.name;
  38. const version = component.value;
  39. if (this.versions[name] !== version) {
  40. this.versions[name] = version;
  41. logger.info(`Got ${name} version: ${version}`);
  42. }
  43. });
  44. }
  45. /**
  46. * Obtains the version of conferencing system component.
  47. * @param componentName the name of the component for which we want to obtain
  48. * the version.
  49. * @returns {String} which describes the version of the component identified by
  50. * given <tt>componentName</tt> or <tt>undefined</tt> if not found.
  51. */
  52. getComponentVersion(componentName) {
  53. return this.versions[componentName];
  54. }
  55. }