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.0KB

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