Skip to content

Commit

Permalink
add "kick participant" support
Browse files Browse the repository at this point in the history
  • Loading branch information
isymchych committed Dec 21, 2015
1 parent c5c0326 commit 81eb706
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 24 deletions.
20 changes: 18 additions & 2 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,24 @@ JitsiConference.prototype.getParticipantById = function(id) {
return this.participants[id];
};

/**
* Kick participant from this conference.
* @param {string} id id of the participant to kick
*/
JitsiConference.prototype.kickParticipant = function (id) {
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
this.room.kick(participant.getJid());
};

JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus') {
return;
}
var participant = new JitsiParticipant(id, this, nick);
var participant = new JitsiParticipant(jid, this, nick);
this.participants[id] = participant;
this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
this.xmpp.connection.disco.info(
Expand All @@ -406,7 +418,7 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {

JitsiConference.prototype.onMemberLeft = function (jid) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus') {
if (id === 'focus' || this.myUserId() === id) {
return;
}
var participant = this.participants[id];
Expand Down Expand Up @@ -566,6 +578,10 @@ function setupListeners(conference) {
// conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
// });

conference.room.addListener(XMPPEvents.KICKED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
});

conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));

Expand Down
4 changes: 4 additions & 0 deletions JitsiConferenceEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ var JitsiConferenceEvents = {
* Indicates that conference has been left.
*/
CONFERENCE_LEFT: "conference.left",
/**
* You are kicked from the conference.
*/
KICKED: "conferenece.kicked",
/**
* Indicates that DTMF support changed.
*/
Expand Down
31 changes: 23 additions & 8 deletions JitsiParticipant.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* global Strophe */

/**
* Represents a participant in (a member of) a conference.
*/
function JitsiParticipant(id, conference, displayName){
this._id = id;
function JitsiParticipant(jid, conference, displayName){
this._jid = jid;
this._id = Strophe.getResourceFromJid(jid);
this._conference = conference;
this._displayName = displayName;
this._supportsDTMF = false;
Expand All @@ -25,12 +28,19 @@ JitsiParticipant.prototype.getTracks = function() {
};

/**
* @returns {String} The ID (i.e. JID) of this participant.
* @returns {String} The ID of this participant.
*/
JitsiParticipant.prototype.getId = function() {
return this._id;
};

/**
* @returns {String} The JID of this participant.
*/
JitsiParticipant.prototype.getJid = function() {
return this._jid;
};

/**
* @returns {String} The human-readable display name of this participant.
*/
Expand Down Expand Up @@ -70,7 +80,8 @@ JitsiParticipant.prototype.isVideoMuted = function() {
};

/*
* @returns {???} The latest statistics reported by this participant (i.e. info used to populate the GSM bars)
* @returns {???} The latest statistics reported by this participant
* (i.e. info used to populate the GSM bars)
* TODO: do we expose this or handle it internally?
*/
JitsiParticipant.prototype.getLatestStats = function() {
Expand All @@ -85,14 +96,16 @@ JitsiParticipant.prototype.getRole = function() {
};

/*
* @returns {Boolean} Whether this participant is the conference focus (i.e. jicofo).
* @returns {Boolean} Whether this participant is
* the conference focus (i.e. jicofo).
*/
JitsiParticipant.prototype.isFocus = function() {

};

/*
* @returns {Boolean} Whether this participant is a conference recorder (i.e. jirecon).
* @returns {Boolean} Whether this participant is
* a conference recorder (i.e. jirecon).
*/
JitsiParticipant.prototype.isRecorder = function() {

Expand All @@ -106,14 +119,16 @@ JitsiParticipant.prototype.isSipGateway = function() {
};

/**
* @returns {Boolean} Whether this participant is currently sharing their screen.
* @returns {Boolean} Whether this participant
* is currently sharing their screen.
*/
JitsiParticipant.prototype.isScreenSharing = function() {

};

/**
* @returns {String} The user agent of this participant (i.e. browser userAgent string).
* @returns {String} The user agent of this participant
* (i.e. browser userAgent string).
*/
JitsiParticipant.prototype.getUserAgent = function() {

Expand Down
4 changes: 4 additions & 0 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
- DTMF_SUPPORT_CHANGED - notifies if at least one user supports DTMF. (parameters - supports(boolean))
- USER_ROLE_CHANGED - notifies that role of some user changed. (parameters - id(string), role(string))
- CONFERENCE_FAILED - notifies that user failed to join the conference. (parameters - errorCode(JitsiMeetJS.errors.conference))
- KICKED - notifies that user has been kicked from the conference.

2. connection
- CONNECTION_FAILED - indicates that the server connection failed.
Expand Down Expand Up @@ -238,6 +239,9 @@ The object represents a conference. We have the following methods to control the
Note: available only for moderator
24. kick(id) - Kick participant from the conference
- id - string participant id
JitsiTrack
======
The object represents single track - video or audio. They can be remote tracks ( from the other participants in the call) or local tracks (from the devices of the local participant).
Expand Down
60 changes: 48 additions & 12 deletions lib-jitsi-meet.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,24 @@ JitsiConference.prototype.getParticipantById = function(id) {
return this.participants[id];
};

/**
* Kick participant from this conference.
* @param {string} id id of the participant to kick
*/
JitsiConference.prototype.kickParticipant = function (id) {
var participant = this.getParticipantById(id);
if (!participant) {
return;
}
this.room.kick(participant.getJid());
};

JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus') {
return;
}
var participant = new JitsiParticipant(id, this, nick);
var participant = new JitsiParticipant(jid, this, nick);
this.participants[id] = participant;
this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
this.xmpp.connection.disco.info(
Expand All @@ -408,7 +420,7 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {

JitsiConference.prototype.onMemberLeft = function (jid) {
var id = Strophe.getResourceFromJid(jid);
if (id === 'focus') {
if (id === 'focus' || this.myUserId() === id) {
return;
}
var participant = this.participants[id];
Expand Down Expand Up @@ -568,6 +580,10 @@ function setupListeners(conference) {
// conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
// });

conference.room.addListener(XMPPEvents.KICKED, function () {
conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
});

conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));

Expand Down Expand Up @@ -765,6 +781,10 @@ var JitsiConferenceEvents = {
* Indicates that conference has been left.
*/
CONFERENCE_LEFT: "conference.left",
/**
* You are kicked from the conference.
*/
KICKED: "conferenece.kicked",
/**
* Indicates that DTMF support changed.
*/
Expand Down Expand Up @@ -1021,11 +1041,14 @@ window.Promise = window.Promise || require("es6-promise").Promise;
module.exports = LibJitsiMeet;

},{"./JitsiConferenceErrors":2,"./JitsiConferenceEvents":3,"./JitsiConnection":4,"./JitsiConnectionErrors":5,"./JitsiConnectionEvents":6,"./JitsiTrackErrors":9,"./JitsiTrackEvents":10,"./modules/RTC/RTC":16,"./modules/statistics/statistics":24,"es6-promise":45,"jitsi-meet-logger":47}],8:[function(require,module,exports){
/* global Strophe */

/**
* Represents a participant in (a member of) a conference.
*/
function JitsiParticipant(id, conference, displayName){
this._id = id;
function JitsiParticipant(jid, conference, displayName){
this._jid = jid;
this._id = Strophe.getResourceFromJid(jid);
this._conference = conference;
this._displayName = displayName;
this._supportsDTMF = false;
Expand All @@ -1048,12 +1071,19 @@ JitsiParticipant.prototype.getTracks = function() {
};

/**
* @returns {String} The ID (i.e. JID) of this participant.
* @returns {String} The ID of this participant.
*/
JitsiParticipant.prototype.getId = function() {
return this._id;
};

/**
* @returns {String} The JID of this participant.
*/
JitsiParticipant.prototype.getJid = function() {
return this._jid;
};

/**
* @returns {String} The human-readable display name of this participant.
*/
Expand Down Expand Up @@ -1093,7 +1123,8 @@ JitsiParticipant.prototype.isVideoMuted = function() {
};

/*
* @returns {???} The latest statistics reported by this participant (i.e. info used to populate the GSM bars)
* @returns {???} The latest statistics reported by this participant
* (i.e. info used to populate the GSM bars)
* TODO: do we expose this or handle it internally?
*/
JitsiParticipant.prototype.getLatestStats = function() {
Expand All @@ -1108,14 +1139,16 @@ JitsiParticipant.prototype.getRole = function() {
};

/*
* @returns {Boolean} Whether this participant is the conference focus (i.e. jicofo).
* @returns {Boolean} Whether this participant is
* the conference focus (i.e. jicofo).
*/
JitsiParticipant.prototype.isFocus = function() {

};

/*
* @returns {Boolean} Whether this participant is a conference recorder (i.e. jirecon).
* @returns {Boolean} Whether this participant is
* a conference recorder (i.e. jirecon).
*/
JitsiParticipant.prototype.isRecorder = function() {

Expand All @@ -1129,14 +1162,16 @@ JitsiParticipant.prototype.isSipGateway = function() {
};

/**
* @returns {Boolean} Whether this participant is currently sharing their screen.
* @returns {Boolean} Whether this participant
* is currently sharing their screen.
*/
JitsiParticipant.prototype.isScreenSharing = function() {

};

/**
* @returns {String} The user agent of this participant (i.e. browser userAgent string).
* @returns {String} The user agent of this participant
* (i.e. browser userAgent string).
*/
JitsiParticipant.prototype.getUserAgent = function() {

Expand Down Expand Up @@ -6240,7 +6275,8 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
reason = reasonSelect.text();
}

this.xmpp.disposeConference(false);
this.xmpp.leaveRoom(this.roomjid);

this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
return true;
Expand All @@ -6262,7 +6298,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
}
if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
if (this.myroomjid === from) {
this.xmpp.disposeConference(false);
this.xmpp.leaveRoom(this.roomjid);
this.eventEmitter.emit(XMPPEvents.KICKED);
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
reason = reasonSelect.text();
}

this.xmpp.disposeConference(false);
this.xmpp.leaveRoom(this.roomjid);

this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
return true;
Expand All @@ -365,7 +366,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
}
if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
if (this.myroomjid === from) {
this.xmpp.disposeConference(false);
this.xmpp.leaveRoom(this.roomjid);
this.eventEmitter.emit(XMPPEvents.KICKED);
}
}
Expand Down

0 comments on commit 81eb706

Please sign in to comment.