2015-01-07 14:54:03 +00:00
|
|
|
/* global $, $iq, config, connection, focusMucJid, forceMuted,
|
2014-11-28 15:20:43 +00:00
|
|
|
setAudioMuted, Strophe, toggleAudio */
|
2014-05-11 22:41:58 +00:00
|
|
|
/**
|
|
|
|
* Moderate connection plugin.
|
|
|
|
*/
|
|
|
|
Strophe.addConnectionPlugin('moderate', {
|
|
|
|
connection: null,
|
|
|
|
init: function (conn) {
|
|
|
|
this.connection = conn;
|
|
|
|
|
2014-11-28 15:16:04 +00:00
|
|
|
this.connection.addHandler(this.onMute.bind(this),
|
|
|
|
'http://jitsi.org/jitmeet/audio',
|
|
|
|
'iq',
|
|
|
|
'set',
|
|
|
|
null,
|
|
|
|
null);
|
2014-05-11 22:41:58 +00:00
|
|
|
},
|
2014-11-28 15:16:04 +00:00
|
|
|
setMute: function (jid, mute) {
|
2014-11-28 15:20:43 +00:00
|
|
|
console.info("set mute", mute);
|
2014-12-16 13:54:13 +00:00
|
|
|
var iqToFocus = $iq({to: focusMucJid, type: 'set'})
|
2014-11-28 15:20:43 +00:00
|
|
|
.c('mute', {
|
|
|
|
xmlns: 'http://jitsi.org/jitmeet/audio',
|
|
|
|
jid: jid
|
|
|
|
})
|
|
|
|
.t(mute.toString())
|
|
|
|
.up();
|
2014-05-11 22:41:58 +00:00
|
|
|
|
|
|
|
this.connection.sendIQ(
|
2014-11-28 15:20:43 +00:00
|
|
|
iqToFocus,
|
|
|
|
function (result) {
|
|
|
|
console.log('set mute', result);
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.log('set mute error', error);
|
|
|
|
});
|
2014-05-11 22:41:58 +00:00
|
|
|
},
|
2014-11-28 15:16:04 +00:00
|
|
|
onMute: function (iq) {
|
2014-11-28 15:20:43 +00:00
|
|
|
var from = iq.getAttribute('from');
|
2014-12-16 13:54:13 +00:00
|
|
|
if (from !== focusMucJid) {
|
2014-11-28 15:20:43 +00:00
|
|
|
console.warn("Ignored mute from non focus peer");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-11 22:41:58 +00:00
|
|
|
var mute = $(iq).find('mute');
|
|
|
|
if (mute.length) {
|
2014-11-28 15:20:43 +00:00
|
|
|
var doMuteAudio = mute.text() === "true";
|
|
|
|
setAudioMuted(doMuteAudio);
|
|
|
|
forceMuted = doMuteAudio;
|
2014-05-11 22:41:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2014-11-28 15:16:04 +00:00
|
|
|
eject: function (jid) {
|
2014-11-28 15:18:58 +00:00
|
|
|
// We're not the focus, so can't terminate
|
|
|
|
//connection.jingle.terminateRemoteByJid(jid, 'kick');
|
2014-05-11 22:41:58 +00:00
|
|
|
connection.emuc.kick(jid);
|
|
|
|
}
|
|
|
|
});
|