소스 검색

add "kick participant" support

tags/v0.0.2
isymchych 9 년 전
부모
커밋
8f94abff1b
6개의 변경된 파일100개의 추가작업 그리고 24개의 파일을 삭제
  1. 18
    2
      JitsiConference.js
  2. 4
    0
      JitsiConferenceEvents.js
  3. 23
    8
      JitsiParticipant.js
  4. 4
    0
      doc/API.md
  5. 48
    12
      lib-jitsi-meet.js
  6. 3
    2
      modules/xmpp/ChatRoom.js

+ 18
- 2
JitsiConference.js 파일 보기

@@ -387,12 +387,24 @@ JitsiConference.prototype.getParticipantById = function(id) {
387 387
     return this.participants[id];
388 388
 };
389 389
 
390
+/**
391
+ * Kick participant from this conference.
392
+ * @param {string} id id of the participant to kick
393
+ */
394
+JitsiConference.prototype.kickParticipant = function (id) {
395
+    var participant = this.getParticipantById(id);
396
+    if (!participant) {
397
+        return;
398
+    }
399
+    this.room.kick(participant.getJid());
400
+};
401
+
390 402
 JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
391 403
     var id = Strophe.getResourceFromJid(jid);
392 404
     if (id === 'focus') {
393 405
        return;
394 406
     }
395
-    var participant = new JitsiParticipant(id, this, nick);
407
+    var participant = new JitsiParticipant(jid, this, nick);
396 408
     this.participants[id] = participant;
397 409
     this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
398 410
     this.xmpp.connection.disco.info(
@@ -406,7 +418,7 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
406 418
 
407 419
 JitsiConference.prototype.onMemberLeft = function (jid) {
408 420
     var id = Strophe.getResourceFromJid(jid);
409
-    if (id === 'focus') {
421
+    if (id === 'focus' || this.myUserId() === id) {
410 422
        return;
411 423
     }
412 424
     var participant = this.participants[id];
@@ -566,6 +578,10 @@ function setupListeners(conference) {
566 578
 //        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
567 579
 //    });
568 580
 
581
+    conference.room.addListener(XMPPEvents.KICKED, function () {
582
+        conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
583
+    });
584
+
569 585
     conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
570 586
     conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
571 587
 

+ 4
- 0
JitsiConferenceEvents.js 파일 보기

@@ -80,6 +80,10 @@ var JitsiConferenceEvents = {
80 80
      * Indicates that conference has been left.
81 81
      */
82 82
     CONFERENCE_LEFT: "conference.left",
83
+    /**
84
+     * You are kicked from the conference.
85
+     */
86
+    KICKED: "conferenece.kicked",
83 87
     /**
84 88
      * Indicates that DTMF support changed.
85 89
      */

+ 23
- 8
JitsiParticipant.js 파일 보기

@@ -1,8 +1,11 @@
1
+/* global Strophe */
2
+
1 3
 /**
2 4
  * Represents a participant in (a member of) a conference.
3 5
  */
4
-function JitsiParticipant(id, conference, displayName){
5
-    this._id = id;
6
+function JitsiParticipant(jid, conference, displayName){
7
+    this._jid = jid;
8
+    this._id = Strophe.getResourceFromJid(jid);
6 9
     this._conference = conference;
7 10
     this._displayName = displayName;
8 11
     this._supportsDTMF = false;
@@ -25,12 +28,19 @@ JitsiParticipant.prototype.getTracks = function() {
25 28
 };
26 29
 
27 30
 /**
28
- * @returns {String} The ID (i.e. JID) of this participant.
31
+ * @returns {String} The ID of this participant.
29 32
  */
30 33
 JitsiParticipant.prototype.getId = function() {
31 34
     return this._id;
32 35
 };
33 36
 
37
+/**
38
+ * @returns {String} The JID of this participant.
39
+ */
40
+JitsiParticipant.prototype.getJid = function() {
41
+    return this._jid;
42
+};
43
+
34 44
 /**
35 45
  * @returns {String} The human-readable display name of this participant.
36 46
  */
@@ -70,7 +80,8 @@ JitsiParticipant.prototype.isVideoMuted = function() {
70 80
 };
71 81
 
72 82
 /*
73
- * @returns {???} The latest statistics reported by this participant (i.e. info used to populate the GSM bars)
83
+ * @returns {???} The latest statistics reported by this participant
84
+ * (i.e. info used to populate the GSM bars)
74 85
  * TODO: do we expose this or handle it internally?
75 86
  */
76 87
 JitsiParticipant.prototype.getLatestStats = function() {
@@ -85,14 +96,16 @@ JitsiParticipant.prototype.getRole = function() {
85 96
 };
86 97
 
87 98
 /*
88
- * @returns {Boolean} Whether this participant is the conference focus (i.e. jicofo).
99
+ * @returns {Boolean} Whether this participant is
100
+ * the conference focus (i.e. jicofo).
89 101
  */
90 102
 JitsiParticipant.prototype.isFocus = function() {
91 103
 
92 104
 };
93 105
 
94 106
 /*
95
- * @returns {Boolean} Whether this participant is a conference recorder (i.e. jirecon).
107
+ * @returns {Boolean} Whether this participant is
108
+ * a conference recorder (i.e. jirecon).
96 109
  */
97 110
 JitsiParticipant.prototype.isRecorder = function() {
98 111
 
@@ -106,14 +119,16 @@ JitsiParticipant.prototype.isSipGateway = function() {
106 119
 };
107 120
 
108 121
 /**
109
- * @returns {Boolean} Whether this participant is currently sharing their screen.
122
+ * @returns {Boolean} Whether this participant
123
+ * is currently sharing their screen.
110 124
  */
111 125
 JitsiParticipant.prototype.isScreenSharing = function() {
112 126
 
113 127
 };
114 128
 
115 129
 /**
116
- * @returns {String} The user agent of this participant (i.e. browser userAgent string).
130
+ * @returns {String} The user agent of this participant
131
+ * (i.e. browser userAgent string).
117 132
  */
118 133
 JitsiParticipant.prototype.getUserAgent = function() {
119 134
 

+ 4
- 0
doc/API.md 파일 보기

@@ -80,6 +80,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
80 80
         - DTMF_SUPPORT_CHANGED - notifies if at least one user supports DTMF. (parameters - supports(boolean))
81 81
         - USER_ROLE_CHANGED - notifies that role of some user changed. (parameters - id(string), role(string))
82 82
         - CONFERENCE_FAILED - notifies that user failed to join the conference. (parameters - errorCode(JitsiMeetJS.errors.conference))
83
+        - KICKED - notifies that user has been kicked from the conference.
83 84
 
84 85
     2. connection
85 86
         - CONNECTION_FAILED - indicates that the server connection failed.
@@ -238,6 +239,9 @@ The object represents a conference. We have the following methods to control the
238 239
 
239 240
     Note: available only for moderator
240 241
 
242
+24. kick(id) - Kick participant from the conference
243
+    - id - string participant id
244
+
241 245
 JitsiTrack
242 246
 ======
243 247
 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).

+ 48
- 12
lib-jitsi-meet.js 파일 보기

@@ -389,12 +389,24 @@ JitsiConference.prototype.getParticipantById = function(id) {
389 389
     return this.participants[id];
390 390
 };
391 391
 
392
+/**
393
+ * Kick participant from this conference.
394
+ * @param {string} id id of the participant to kick
395
+ */
396
+JitsiConference.prototype.kickParticipant = function (id) {
397
+    var participant = this.getParticipantById(id);
398
+    if (!participant) {
399
+        return;
400
+    }
401
+    this.room.kick(participant.getJid());
402
+};
403
+
392 404
 JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
393 405
     var id = Strophe.getResourceFromJid(jid);
394 406
     if (id === 'focus') {
395 407
        return;
396 408
     }
397
-    var participant = new JitsiParticipant(id, this, nick);
409
+    var participant = new JitsiParticipant(jid, this, nick);
398 410
     this.participants[id] = participant;
399 411
     this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
400 412
     this.xmpp.connection.disco.info(
@@ -408,7 +420,7 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
408 420
 
409 421
 JitsiConference.prototype.onMemberLeft = function (jid) {
410 422
     var id = Strophe.getResourceFromJid(jid);
411
-    if (id === 'focus') {
423
+    if (id === 'focus' || this.myUserId() === id) {
412 424
        return;
413 425
     }
414 426
     var participant = this.participants[id];
@@ -568,6 +580,10 @@ function setupListeners(conference) {
568 580
 //        conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
569 581
 //    });
570 582
 
583
+    conference.room.addListener(XMPPEvents.KICKED, function () {
584
+        conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
585
+    });
586
+
571 587
     conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
572 588
     conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
573 589
 
@@ -765,6 +781,10 @@ var JitsiConferenceEvents = {
765 781
      * Indicates that conference has been left.
766 782
      */
767 783
     CONFERENCE_LEFT: "conference.left",
784
+    /**
785
+     * You are kicked from the conference.
786
+     */
787
+    KICKED: "conferenece.kicked",
768 788
     /**
769 789
      * Indicates that DTMF support changed.
770 790
      */
@@ -1021,11 +1041,14 @@ window.Promise = window.Promise || require("es6-promise").Promise;
1021 1041
 module.exports = LibJitsiMeet;
1022 1042
 
1023 1043
 },{"./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){
1044
+/* global Strophe */
1045
+
1024 1046
 /**
1025 1047
  * Represents a participant in (a member of) a conference.
1026 1048
  */
1027
-function JitsiParticipant(id, conference, displayName){
1028
-    this._id = id;
1049
+function JitsiParticipant(jid, conference, displayName){
1050
+    this._jid = jid;
1051
+    this._id = Strophe.getResourceFromJid(jid);
1029 1052
     this._conference = conference;
1030 1053
     this._displayName = displayName;
1031 1054
     this._supportsDTMF = false;
@@ -1048,12 +1071,19 @@ JitsiParticipant.prototype.getTracks = function() {
1048 1071
 };
1049 1072
 
1050 1073
 /**
1051
- * @returns {String} The ID (i.e. JID) of this participant.
1074
+ * @returns {String} The ID of this participant.
1052 1075
  */
1053 1076
 JitsiParticipant.prototype.getId = function() {
1054 1077
     return this._id;
1055 1078
 };
1056 1079
 
1080
+/**
1081
+ * @returns {String} The JID of this participant.
1082
+ */
1083
+JitsiParticipant.prototype.getJid = function() {
1084
+    return this._jid;
1085
+};
1086
+
1057 1087
 /**
1058 1088
  * @returns {String} The human-readable display name of this participant.
1059 1089
  */
@@ -1093,7 +1123,8 @@ JitsiParticipant.prototype.isVideoMuted = function() {
1093 1123
 };
1094 1124
 
1095 1125
 /*
1096
- * @returns {???} The latest statistics reported by this participant (i.e. info used to populate the GSM bars)
1126
+ * @returns {???} The latest statistics reported by this participant
1127
+ * (i.e. info used to populate the GSM bars)
1097 1128
  * TODO: do we expose this or handle it internally?
1098 1129
  */
1099 1130
 JitsiParticipant.prototype.getLatestStats = function() {
@@ -1108,14 +1139,16 @@ JitsiParticipant.prototype.getRole = function() {
1108 1139
 };
1109 1140
 
1110 1141
 /*
1111
- * @returns {Boolean} Whether this participant is the conference focus (i.e. jicofo).
1142
+ * @returns {Boolean} Whether this participant is
1143
+ * the conference focus (i.e. jicofo).
1112 1144
  */
1113 1145
 JitsiParticipant.prototype.isFocus = function() {
1114 1146
 
1115 1147
 };
1116 1148
 
1117 1149
 /*
1118
- * @returns {Boolean} Whether this participant is a conference recorder (i.e. jirecon).
1150
+ * @returns {Boolean} Whether this participant is
1151
+ * a conference recorder (i.e. jirecon).
1119 1152
  */
1120 1153
 JitsiParticipant.prototype.isRecorder = function() {
1121 1154
 
@@ -1129,14 +1162,16 @@ JitsiParticipant.prototype.isSipGateway = function() {
1129 1162
 };
1130 1163
 
1131 1164
 /**
1132
- * @returns {Boolean} Whether this participant is currently sharing their screen.
1165
+ * @returns {Boolean} Whether this participant
1166
+ * is currently sharing their screen.
1133 1167
  */
1134 1168
 JitsiParticipant.prototype.isScreenSharing = function() {
1135 1169
 
1136 1170
 };
1137 1171
 
1138 1172
 /**
1139
- * @returns {String} The user agent of this participant (i.e. browser userAgent string).
1173
+ * @returns {String} The user agent of this participant
1174
+ * (i.e. browser userAgent string).
1140 1175
  */
1141 1176
 JitsiParticipant.prototype.getUserAgent = function() {
1142 1177
 
@@ -6240,7 +6275,8 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
6240 6275
             reason = reasonSelect.text();
6241 6276
         }
6242 6277
 
6243
-        this.xmpp.disposeConference(false);
6278
+        this.xmpp.leaveRoom(this.roomjid);
6279
+
6244 6280
         this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
6245 6281
         delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
6246 6282
         return true;
@@ -6262,7 +6298,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
6262 6298
     }
6263 6299
     if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
6264 6300
         if (this.myroomjid === from) {
6265
-            this.xmpp.disposeConference(false);
6301
+            this.xmpp.leaveRoom(this.roomjid);
6266 6302
             this.eventEmitter.emit(XMPPEvents.KICKED);
6267 6303
         }
6268 6304
     }

+ 3
- 2
modules/xmpp/ChatRoom.js 파일 보기

@@ -374,7 +374,8 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
374 374
             reason = reasonSelect.text();
375 375
         }
376 376
 
377
-        this.xmpp.disposeConference(false);
377
+        this.xmpp.leaveRoom(this.roomjid);
378
+
378 379
         this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
379 380
         delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
380 381
         return true;
@@ -396,7 +397,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
396 397
     }
397 398
     if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
398 399
         if (this.myroomjid === from) {
399
-            this.xmpp.disposeConference(false);
400
+            this.xmpp.leaveRoom(this.roomjid);
400 401
             this.eventEmitter.emit(XMPPEvents.KICKED);
401 402
         }
402 403
     }

Loading…
취소
저장