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,
  2. setAudioMuted, Strophe */
  3. /**
  4. * Moderate connection plugin.
  5. */
  6. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  7. module.exports = function (XMPP, eventEmitter) {
  8. Strophe.addConnectionPlugin('moderate', {
  9. connection: null,
  10. init: function (conn) {
  11. this.connection = conn;
  12. this.connection.addHandler(this.onMute.bind(this),
  13. 'http://jitsi.org/jitmeet/audio',
  14. 'iq',
  15. 'set',
  16. null,
  17. null);
  18. },
  19. setMute: function (jid, mute) {
  20. console.info("set mute", mute);
  21. var iqToFocus = $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. }