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.

strophe.moderate.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* global $, $iq, config, connection, focusMucJid, forceMuted,
  2. setAudioMuted, Strophe */
  3. /**
  4. * Moderate connection plugin.
  5. */
  6. var logger = require("jitsi-meet-logger").getLogger(__filename);
  7. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  8. module.exports = function (XMPP, eventEmitter) {
  9. Strophe.addConnectionPlugin('moderate', {
  10. connection: null,
  11. init: function (conn) {
  12. this.connection = conn;
  13. this.connection.addHandler(this.onMute.bind(this),
  14. 'http://jitsi.org/jitmeet/audio',
  15. 'iq',
  16. 'set',
  17. null,
  18. null);
  19. },
  20. setMute: function (jid, mute) {
  21. logger.info("set mute", mute);
  22. var iqToFocus = $iq(
  23. {to: this.connection.emuc.focusMucJid, type: 'set'})
  24. .c('mute', {
  25. xmlns: 'http://jitsi.org/jitmeet/audio',
  26. jid: jid
  27. })
  28. .t(mute.toString())
  29. .up();
  30. this.connection.sendIQ(
  31. iqToFocus,
  32. function (result) {
  33. logger.log('set mute', result);
  34. },
  35. function (error) {
  36. logger.log('set mute error', error);
  37. });
  38. },
  39. onMute: function (iq) {
  40. var from = iq.getAttribute('from');
  41. if (from !== this.connection.emuc.focusMucJid) {
  42. logger.warn("Ignored mute from non focus peer");
  43. return false;
  44. }
  45. var mute = $(iq).find('mute');
  46. if (mute.length) {
  47. var doMuteAudio = mute.text() === "true";
  48. eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, doMuteAudio);
  49. XMPP.forceMuted = doMuteAudio;
  50. }
  51. return true;
  52. },
  53. eject: function (jid) {
  54. // We're not the focus, so can't terminate
  55. //connection.jingle.terminateRemoteByJid(jid, 'kick');
  56. this.connection.emuc.kick(jid);
  57. }
  58. });
  59. };