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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 =
  22. $iq({to: this.connection.emuc.focusMucJid, type: 'set'})
  23. .c('mute', {
  24. xmlns: 'http://jitsi.org/jitmeet/audio',
  25. jid: jid
  26. })
  27. .t(mute.toString())
  28. .up();
  29. this.connection.sendIQ(
  30. iqToFocus,
  31. function (result) {
  32. console.log('set mute', result);
  33. },
  34. function (error) {
  35. console.log('set mute error', error);
  36. });
  37. },
  38. onMute: function (iq) {
  39. var from = iq.getAttribute('from');
  40. if (from !== this.connection.emuc.focusMucJid) {
  41. console.warn("Ignored mute from non focus peer");
  42. return false;
  43. }
  44. var mute = $(iq).find('mute');
  45. if (mute.length) {
  46. var doMuteAudio = mute.text() === "true";
  47. eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, doMuteAudio);
  48. XMPP.forceMuted = doMuteAudio;
  49. }
  50. return true;
  51. },
  52. eject: function (jid) {
  53. // We're not the focus, so can't terminate
  54. //connection.jingle.terminateRemoteByJid(jid, 'kick');
  55. this.connection.emuc.kick(jid);
  56. }
  57. });
  58. };