Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

strophe.moderate.js 1.9KB

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