Implements remote participant audio mute

This commit is contained in:
hristoterezov 2015-12-31 16:01:03 -06:00
parent f14809a8f2
commit 7106c7890a
7 changed files with 197 additions and 90 deletions

View File

@ -399,6 +399,18 @@ JitsiConference.prototype.kickParticipant = function (id) {
this.room.kick(participant.getJid());
};
/**
* Kick participant from this conference.
* @param {string} id id of the participant to kick
*/
JitsiConference.prototype.muteParticipant = function (id) {
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
this.room.muteParticipant(participant.getJid(), true);
};
JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus' || this.myUserId() === id) {
@ -658,6 +670,12 @@ function setupListeners(conference) {
}
);
conference.room.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
function (value) {
conference.rtc.setAudioMute(value);
}
);
conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
});

View File

@ -401,6 +401,18 @@ JitsiConference.prototype.kickParticipant = function (id) {
this.room.kick(participant.getJid());
};
/**
* Kick participant from this conference.
* @param {string} id id of the participant to kick
*/
JitsiConference.prototype.muteParticipant = function (id) {
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
this.room.muteParticipant(participant.getJid(), true);
};
JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus' || this.myUserId() === id) {
@ -660,6 +672,12 @@ function setupListeners(conference) {
}
);
conference.room.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
function (value) {
conference.rtc.setAudioMute(value);
}
);
conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
});
@ -907,11 +925,7 @@ var JitsiConferenceEvents = {
/**
* Indicates that phone number changed.
*/
PHONE_NUMBER_CHANGED: "conference.phoneNumberChanged",
/**
* Indicates that recording status changed.
*/
RECORDING_STATE_CHANGED: "conferenece.recordingStateChanged"
PHONE_NUMBER_CHANGED: "conference.phoneNumberChanged"
};
module.exports = JitsiConferenceEvents;
@ -2209,6 +2223,20 @@ RTC.prototype.addLocalStream = function (stream) {
}
};
/**
* Set mute for all local audio streams attached to the conference.
* @param value the mute value
*/
RTC.prototype.setAudioMute = function (value) {
for(var i = 0; i < this.localStreams.length; i++) {
var stream = this.localStreams[i];
if(stream.getType() !== "audio") {
continue;
}
stream._setMute(value);
}
}
RTC.prototype.removeLocalStream = function (stream) {
for(var i = 0; i < this.localStreams.length; i++) {
if(this.localStreams[i].getOriginalStream() === stream) {
@ -6824,6 +6852,46 @@ ChatRoom.prototype.getConnectionState = function () {
return this.session.getIceConnectionState();
}
/**
* Mutes remote participant.
* @param jid of the participant
* @param mute
*/
ChatRoom.prototype.muteParticipant = function (jid, mute) {
logger.info("set mute", mute);
var iqToFocus = $iq(
{to: this.focusMucJid, type: 'set'})
.c('mute', {
xmlns: 'http://jitsi.org/jitmeet/audio',
jid: jid
})
.t(mute.toString())
.up();
this.connection.sendIQ(
iqToFocus,
function (result) {
logger.log('set mute', result);
},
function (error) {
logger.log('set mute error', error);
});
}
ChatRoom.prototype.onMute = function (iq) {
var from = iq.getAttribute('from');
if (from !== this.focusMucJid) {
logger.warn("Ignored mute from non focus peer");
return false;
}
var mute = $(iq).find('mute');
if (mute.length) {
var doMuteAudio = mute.text() === "true";
this.eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, doMuteAudio);
}
return true;
}
module.exports = ChatRoom;
}).call(this,"/modules/xmpp/ChatRoom.js")
@ -11246,10 +11314,16 @@ module.exports = function(XMPP) {
init: function (conn) {
this.connection = conn;
// add handlers (just once)
this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, null, null);
this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null);
this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null);
this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null);
this.connection.addHandler(this.onPresence.bind(this), null,
'presence', null, null, null, null);
this.connection.addHandler(this.onPresenceUnavailable.bind(this),
null, 'presence', 'unavailable', null);
this.connection.addHandler(this.onPresenceError.bind(this), null,
'presence', 'error', null);
this.connection.addHandler(this.onMessage.bind(this), null,
'message', null, null);
this.connection.addHandler(this.onMute.bind(this),
'http://jitsi.org/jitmeet/audio', 'iq', 'set',null,null);
},
createRoom: function (jid, password, options) {
var roomJid = Strophe.getBareJidFromJid(jid);
@ -11320,11 +11394,20 @@ module.exports = function(XMPP) {
return;
room.setJingleSession(session);
},
onMute: function(iq) {
var from = iq.getAttribute('from');
var room = this.rooms[Strophe.getBareJidFromJid(from)];
if(!room)
return;
room.onMute(iq);
return true;
}
});
};
}).call(this,"/modules/xmpp/strophe.emuc.js")
},{"./ChatRoom":26,"jitsi-meet-logger":48}],37:[function(require,module,exports){
(function (__filename){

24
lib-jitsi-meet.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -122,6 +122,20 @@ RTC.prototype.addLocalStream = function (stream) {
}
};
/**
* Set mute for all local audio streams attached to the conference.
* @param value the mute value
*/
RTC.prototype.setAudioMute = function (value) {
for(var i = 0; i < this.localStreams.length; i++) {
var stream = this.localStreams[i];
if(stream.getType() !== "audio") {
continue;
}
stream._setMute(value);
}
}
RTC.prototype.removeLocalStream = function (stream) {
for(var i = 0; i < this.localStreams.length; i++) {
if(this.localStreams[i].getOriginalStream() === stream) {

View File

@ -758,4 +758,44 @@ ChatRoom.prototype.getConnectionState = function () {
return this.session.getIceConnectionState();
}
/**
* Mutes remote participant.
* @param jid of the participant
* @param mute
*/
ChatRoom.prototype.muteParticipant = function (jid, mute) {
logger.info("set mute", mute);
var iqToFocus = $iq(
{to: this.focusMucJid, type: 'set'})
.c('mute', {
xmlns: 'http://jitsi.org/jitmeet/audio',
jid: jid
})
.t(mute.toString())
.up();
this.connection.sendIQ(
iqToFocus,
function (result) {
logger.log('set mute', result);
},
function (error) {
logger.log('set mute error', error);
});
}
ChatRoom.prototype.onMute = function (iq) {
var from = iq.getAttribute('from');
if (from !== this.focusMucJid) {
logger.warn("Ignored mute from non focus peer");
return false;
}
var mute = $(iq).find('mute');
if (mute.length) {
var doMuteAudio = mute.text() === "true";
this.eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, doMuteAudio);
}
return true;
}
module.exports = ChatRoom;

View File

@ -13,10 +13,16 @@ module.exports = function(XMPP) {
init: function (conn) {
this.connection = conn;
// add handlers (just once)
this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, null, null);
this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null);
this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null);
this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null);
this.connection.addHandler(this.onPresence.bind(this), null,
'presence', null, null, null, null);
this.connection.addHandler(this.onPresenceUnavailable.bind(this),
null, 'presence', 'unavailable', null);
this.connection.addHandler(this.onPresenceError.bind(this), null,
'presence', 'error', null);
this.connection.addHandler(this.onMessage.bind(this), null,
'message', null, null);
this.connection.addHandler(this.onMute.bind(this),
'http://jitsi.org/jitmeet/audio', 'iq', 'set',null,null);
},
createRoom: function (jid, password, options) {
var roomJid = Strophe.getBareJidFromJid(jid);
@ -87,7 +93,16 @@ module.exports = function(XMPP) {
return;
room.setJingleSession(session);
},
onMute: function(iq) {
var from = iq.getAttribute('from');
var room = this.rooms[Strophe.getBareJidFromJid(from)];
if(!room)
return;
room.onMute(iq);
return true;
}
});
};

View File

@ -1,63 +0,0 @@
/* global $, $iq, config, connection, focusMucJid, forceMuted,
setAudioMuted, Strophe */
/**
* Moderate connection plugin.
*/
var logger = require("jitsi-meet-logger").getLogger(__filename);
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
module.exports = function (XMPP, eventEmitter) {
Strophe.addConnectionPlugin('moderate', {
connection: null,
init: function (conn) {
this.connection = conn;
this.connection.addHandler(this.onMute.bind(this),
'http://jitsi.org/jitmeet/audio',
'iq',
'set',
null,
null);
},
setMute: function (jid, mute) {
logger.info("set mute", mute);
var iqToFocus = $iq(
{to: this.connection.emuc.focusMucJid, type: 'set'})
.c('mute', {
xmlns: 'http://jitsi.org/jitmeet/audio',
jid: jid
})
.t(mute.toString())
.up();
this.connection.sendIQ(
iqToFocus,
function (result) {
logger.log('set mute', result);
},
function (error) {
logger.log('set mute error', error);
});
},
onMute: function (iq) {
var from = iq.getAttribute('from');
if (from !== this.connection.emuc.focusMucJid) {
logger.warn("Ignored mute from non focus peer");
return false;
}
var mute = $(iq).find('mute');
if (mute.length) {
var doMuteAudio = mute.text() === "true";
eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, doMuteAudio);
XMPP.forceMuted = doMuteAudio;
}
return true;
},
eject: function (jid) {
// We're not the focus, so can't terminate
//connection.jingle.terminateRemoteByJid(jid, 'kick');
this.connection.emuc.kick(jid);
}
});
};