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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* global $, $iq, config, connection, focusMucJid, forceMuted,
  17. setAudioMuted, Strophe */
  18. /**
  19. * Moderate connection plugin.
  20. */
  21. module.exports = function (XMPP) {
  22. Strophe.addConnectionPlugin('moderate', {
  23. connection: null,
  24. init: function (conn) {
  25. this.connection = conn;
  26. this.connection.addHandler(this.onMute.bind(this),
  27. 'http://jitsi.org/jitmeet/audio',
  28. 'iq',
  29. 'set',
  30. null,
  31. null);
  32. },
  33. setMute: function (jid, mute) {
  34. console.info("set mute", mute);
  35. var iqToFocus = $iq({to: this.connection.emuc.focusMucJid, type: 'set'})
  36. .c('mute', {
  37. xmlns: 'http://jitsi.org/jitmeet/audio',
  38. jid: jid
  39. })
  40. .t(mute.toString())
  41. .up();
  42. this.connection.sendIQ(
  43. iqToFocus,
  44. function (result) {
  45. console.log('set mute', result);
  46. },
  47. function (error) {
  48. console.log('set mute error', error);
  49. });
  50. },
  51. onMute: function (iq) {
  52. var from = iq.getAttribute('from');
  53. if (from !== this.connection.emuc.focusMucJid) {
  54. console.warn("Ignored mute from non focus peer");
  55. return false;
  56. }
  57. var mute = $(iq).find('mute');
  58. if (mute.length) {
  59. var doMuteAudio = mute.text() === "true";
  60. APP.UI.setAudioMuted(doMuteAudio);
  61. XMPP.forceMuted = doMuteAudio;
  62. }
  63. return true;
  64. },
  65. eject: function (jid) {
  66. // We're not the focus, so can't terminate
  67. //connection.jingle.terminateRemoteByJid(jid, 'kick');
  68. this.connection.emuc.kick(jid);
  69. }
  70. });
  71. }