瀏覽代碼

Adds partial support for multiple chat rooms. Implements join and leave methods.

dev1
hristoterezov 10 年之前
父節點
當前提交
e17e31c274
共有 7 個文件被更改,包括 1239 次插入817 次删除
  1. 13
    8
      JitsiConference.js
  2. 7
    2
      JitsiConnection.js
  3. 669
    118
      lib-jitsi-meet.js
  4. 27
    6
      modules/connectionquality/connectionquality.js
  5. 50
    41
      modules/settings/Settings.js
  6. 460
    560
      modules/xmpp/strophe.emuc.js
  7. 13
    82
      modules/xmpp/xmpp.js

+ 13
- 8
JitsiConference.js 查看文件

@@ -1,4 +1,6 @@
1
-var xmpp = require("./modules/xmpp/xmpp");
1
+var room = null;
2
+
3
+
2 4
 /**
3 5
  * Creates a JitsiConference object with the given name and properties.
4 6
  * Note: this constructor is not a part of the public API (objects should be
@@ -10,21 +12,24 @@ var xmpp = require("./modules/xmpp/xmpp");
10 12
  */
11 13
 
12 14
 function JitsiConference(options) {
13
-   this.options = options;
15
+    this.options = options;
16
+    this.connection = this.options.connection;
17
+    this.xmpp = this.connection.xmpp;
14 18
 }
15 19
 
16 20
 /**
17 21
  * Joins the conference.
18 22
  */
19 23
 JitsiConference.prototype.join = function () {
20
-    xmpp.joinRoom(this.options.name, null, null);
24
+    room = this.xmpp.joinRoom(this.options.name, null, null);
21 25
 }
22 26
 
23 27
 /**
24 28
  * Leaves the conference.
25 29
  */
26 30
 JitsiConference.prototype.leave = function () {
27
-    xmpp.l
31
+    this.xmpp.leaveRoom(room.roomjid);
32
+    room = null;
28 33
 }
29 34
 
30 35
 /**
@@ -55,7 +60,7 @@ JitsiConference.prototype.getLocalTracks = function () {
55 60
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
56 61
  */
57 62
 JitsiConference.prototype.on = function (eventId, handler) {
58
-
63
+    this.xmpp.addListener(eventId, handler);
59 64
 }
60 65
 
61 66
 /**
@@ -66,7 +71,7 @@ JitsiConference.prototype.on = function (eventId, handler) {
66 71
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
67 72
  */
68 73
 JitsiConference.prototype.off = function (eventId, handler) {
69
-
74
+    this.xmpp.removeListener(event, listener);
70 75
 }
71 76
 
72 77
 // Common aliases for event emitter
@@ -95,7 +100,7 @@ JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off
95 100
  * @param message the text message.
96 101
  */
97 102
 JitsiConference.prototype.sendTextMessage = function (message) {
98
-
103
+    room.send
99 104
 }
100 105
 
101 106
 /**
@@ -117,7 +122,7 @@ JitsiConference.prototype.sendCommand = function (name, values, persistent) {
117 122
  * @param name the display name to set
118 123
  */
119 124
 JitsiConference.prototype.setDisplayName = function(name) {
120
-
125
+    room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
121 126
 }
122 127
 
123 128
 /**

+ 7
- 2
JitsiConnection.js 查看文件

@@ -1,6 +1,11 @@
1 1
 var JitsiConference = require("./JitsiConference");
2 2
 var XMPP = require("./modules/xmpp/xmpp");
3 3
 
4
+function wrapper()
5
+{
6
+    var jitsiconnectioninstance = new JitsiConnection();
7
+    this.a = jitsiconnectioninstance.a();
8
+}
4 9
 /**
5 10
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6 11
  * JitsiConference interface.
@@ -57,7 +62,7 @@ JitsiConnection.prototype.initJitsiConference = function (name, options) {
57 62
  * @param event {JitsiConnectionEvents} the connection event.
58 63
  * @param listener {Function} the function that will receive the event
59 64
  */
60
-JitsiConnection.prototype.addListener = function (event, listener) {
65
+JitsiConnection.prototype.addEventListener = function (event, listener) {
61 66
     this.xmpp.addListener(event, listener);
62 67
 }
63 68
 
@@ -66,7 +71,7 @@ JitsiConnection.prototype.addListener = function (event, listener) {
66 71
  * @param event {JitsiConnectionEvents} the connection event.
67 72
  * @param listener {Function} the function that will receive the event
68 73
  */
69
-JitsiConnection.prototype.removeListener = function (event, listener) {
74
+JitsiConnection.prototype.removeEventListener = function (event, listener) {
70 75
     this.xmpp.removeListener(event, listener);
71 76
 }
72 77
 

+ 669
- 118
lib-jitsi-meet.js
文件差異過大導致無法顯示
查看文件


+ 27
- 6
modules/connectionquality/connectionquality.js 查看文件

@@ -35,7 +35,7 @@ function startSendingStats() {
35 35
  * Sends statistics to other participants
36 36
  */
37 37
 function sendStats() {
38
-    APP.xmpp.addToPresence("connectionQuality", convertToMUCStats(stats));
38
+    APP.xmpp.addToPresence("stats", convertToMUCStats(stats));
39 39
 }
40 40
 
41 41
 /**
@@ -45,11 +45,32 @@ function sendStats() {
45 45
  */
46 46
 function convertToMUCStats(stats) {
47 47
     return {
48
-        "bitrate_download": stats.bitrate.download,
49
-        "bitrate_upload": stats.bitrate.upload,
50
-        "packetLoss_total": stats.packetLoss.total,
51
-        "packetLoss_download": stats.packetLoss.download,
52
-        "packetLoss_upload": stats.packetLoss.upload
48
+        tagName: "stats",
49
+        attributes: {
50
+            xmlns: 'http://jitsi.org/jitmeet/stats'
51
+        },
52
+        children: [
53
+            {
54
+                tagName: "stat",
55
+                attributes: {name: "bitrate_download", value: stats.bitrate.download}
56
+            },
57
+            {
58
+                tagName: "stat",
59
+                attributes: {name: "bitrate_upload", value: stats.bitrate.upload}
60
+            },
61
+            {
62
+                tagName: "stat",
63
+                attributes: {name: "packetLoss_total", value: stats.packetLoss.total}
64
+            },
65
+            {
66
+                tagName: "stat",
67
+                attributes: {name: "packetLoss_download", value: stats.packetLoss.download}
68
+            },
69
+            {
70
+                tagName: "stat",
71
+                attributes: {name: "packetLoss_upload", value: stats.packetLoss.upload}
72
+            }
73
+        ]
53 74
     };
54 75
 }
55 76
 

+ 50
- 41
modules/settings/Settings.js 查看文件

@@ -1,9 +1,3 @@
1
-var email = '';
2
-var displayName = '';
3
-var userId;
4
-var language = null;
5
-
6
-
7 1
 function supportsLocalStorage() {
8 2
     try {
9 3
         return 'localStorage' in window && window.localStorage !== null;
@@ -21,43 +15,58 @@ function generateUniqueId() {
21 15
     return _p8() + _p8() + _p8() + _p8();
22 16
 }
23 17
 
24
-if (supportsLocalStorage()) {
25
-    if (!window.localStorage.jitsiMeetId) {
26
-        window.localStorage.jitsiMeetId = generateUniqueId();
27
-        console.log("generated id", window.localStorage.jitsiMeetId);
18
+function Settings(conferenceID) {
19
+    this.email = '';
20
+    this.displayName = '';
21
+    this.userId;
22
+    this.language = null;
23
+    this.confSettings = null;
24
+    if (supportsLocalStorage()) {
25
+        if(!window.localStorage.jitsiConferences)
26
+            window.localStorage.jitsiConferences = {}
27
+        if (!window.localStorage.jitsiConferences[conferenceID]) {
28
+            window.localStorage.jitsiConferences[conferenceID] = {}
29
+        }
30
+        this.confSettings = window.localStorage.jitsiConferences[conferenceID];
31
+        if(!this.confSettings.jitsiMeetId) {
32
+            this.confSettings.jitsiMeetId = generateUniqueId();
33
+            console.log("generated id",
34
+                this.confSettings.jitsiMeetId);
35
+        }
36
+        this.userId = this.confSettings.jitsiMeetId || '';
37
+        this.email = this.confSettings.email || '';
38
+        this.displayName = this.confSettings.displayname || '';
39
+        this.language = this.confSettings.language;
40
+    } else {
41
+        console.log("local storage is not supported");
42
+        this.userId = generateUniqueId();
28 43
     }
29
-    userId = window.localStorage.jitsiMeetId || '';
30
-    email = window.localStorage.email || '';
31
-    displayName = window.localStorage.displayname || '';
32
-    language = window.localStorage.language;
33
-} else {
34
-    console.log("local storage is not supported");
35
-    userId = generateUniqueId();
36 44
 }
37 45
 
38
-var Settings = {
39
-    setDisplayName: function (newDisplayName) {
40
-        displayName = newDisplayName;
41
-        window.localStorage.displayname = displayName;
42
-        return displayName;
43
-    },
44
-    setEmail: function (newEmail) {
45
-        email = newEmail;
46
-        window.localStorage.email = newEmail;
47
-        return email;
48
-    },
49
-    getSettings: function () {
50
-        return {
51
-            email: email,
52
-            displayName: displayName,
53
-            uid: userId,
54
-            language: language
55
-        };
56
-    },
57
-    setLanguage: function (lang) {
58
-        language = lang;
59
-        window.localStorage.language = lang;
60
-    }
61
-};
46
+Settings.prototype.setDisplayName = function (newDisplayName) {
47
+    this.displayName = newDisplayName;
48
+    if(this.confSettings != null)
49
+        this.confSettings.displayname = displayName;
50
+    return this.displayName;
51
+},
52
+Settings.prototype.setEmail = function (newEmail) {
53
+    this.email = newEmail;
54
+    if(this.confSettings != null)
55
+        this.confSettings.email = newEmail;
56
+    return this.email;
57
+},
58
+Settings.prototype.getSettings = function () {
59
+    return {
60
+        email: this.email,
61
+        displayName: this.displayName,
62
+        uid: this.userId,
63
+        language: this.language
64
+    };
65
+},
66
+Settings.prototype.setLanguage = function (lang) {
67
+    this.language = lang;
68
+    if(this.confSettings != null)
69
+        this.confSettings.language = lang;
70
+}
62 71
 
63 72
 module.exports = Settings;

+ 460
- 560
modules/xmpp/strophe.emuc.js
文件差異過大導致無法顯示
查看文件


+ 13
- 82
modules/xmpp/xmpp.js 查看文件

@@ -10,7 +10,6 @@ var JitsiConnectionEvents = require("../../JitsiConnectionEvents");
10 10
 var RTC = require("../RTC/RTC");
11 11
 
12 12
 var authenticatedUser = false;
13
-var disconnectInProgress = false;
14 13
 
15 14
 function createConnection(bosh) {
16 15
     bosh = bosh || '/http-bind';
@@ -21,9 +20,9 @@ function createConnection(bosh) {
21 20
 
22 21
 
23 22
 //!!!!!!!!!! FIXME: ...
24
-function initStrophePlugins()
23
+function initStrophePlugins(XMPP)
25 24
 {
26
-//    require("./strophe.emuc")(XMPP, eventEmitter);
25
+    require("./strophe.emuc")(XMPP);
27 26
 //    require("./strophe.jingle")(XMPP, eventEmitter);
28 27
 //    require("./strophe.moderate")(XMPP, eventEmitter);
29 28
     require("./strophe.util")();
@@ -56,10 +55,11 @@ function XMPP(options) {
56 55
     this.sessionTerminated = false;
57 56
     this.eventEmitter = new EventEmitter();
58 57
     this.connection = null;
58
+    this.disconnectInProgress = false;
59 59
 
60 60
     this.forceMuted = false;
61 61
     this.options = options;
62
-    initStrophePlugins();
62
+    initStrophePlugins(this);
63 63
 //    registerListeners();
64 64
     Moderator.init(this, this.eventEmitter);
65 65
     this.connection = createConnection(options.bosh);
@@ -110,6 +110,7 @@ XMPP.prototype._connect = function (jid, password) {
110 110
                 self.connection.jingle.getStunAndTurnCredentials();
111 111
             }
112 112
 
113
+
113 114
             console.info("My Jabber ID: " + self.connection.jid);
114 115
 
115 116
             if (password)
@@ -117,6 +118,7 @@ XMPP.prototype._connect = function (jid, password) {
117 118
             if (self.connection && self.connection.connected &&
118 119
                 Strophe.getResourceFromJid(self.connection.jid)) {
119 120
                 // .connected is true while connecting?
121
+                self.connection.send($pres());
120 122
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
121 123
                     Strophe.getResourceFromJid(self.connection.jid));
122 124
             }
@@ -130,6 +132,7 @@ XMPP.prototype._connect = function (jid, password) {
130 132
             }
131 133
             lastErrorMsg = msg;
132 134
         } else if (status === Strophe.Status.DISCONNECTED) {
135
+            self.disconnectInProgress = false;
133 136
             if (anonymousConnectionFailed) {
134 137
                 // prompt user for username and password
135 138
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_FAILED,
@@ -165,7 +168,7 @@ XMPP.prototype.connect = function (jid, password) {
165 168
 };
166 169
 
167 170
 XMPP.prototype.joinRoom = function(roomName, useNicks, nick) {
168
-    var roomjid = roomName;
171
+    var roomjid = roomName  + '@' + Strophe.getDomainFromJid(this.connection.jid);
169 172
 
170 173
     if (useNicks) {
171 174
         if (nick) {
@@ -181,20 +184,9 @@ XMPP.prototype.joinRoom = function(roomName, useNicks, nick) {
181 184
 
182 185
         roomjid += '/' + tmpJid;
183 186
     }
184
-    this.connection.emuc.doJoin(roomjid);
187
+    return this.connection.emuc.doJoin(roomjid, null, this.eventEmitter);
185 188
 };
186 189
 
187
-XMPP.prototype.myJid = function () {
188
-    if(!this.connection)
189
-        return null;
190
-    return this.connection.emuc.myroomjid;
191
-}
192
-
193
-XMPP.prototype.myResource = function () {
194
-    if(!this.connection || ! this.connection.emuc.myroomjid)
195
-        return null;
196
-    return Strophe.getResourceFromJid(this.connection.emuc.myroomjid);
197
-}
198 190
 
199 191
 XMPP.prototype.disposeConference = function (onUnload) {
200 192
     var handler = this.connection.jingle.activecall;
@@ -227,8 +219,8 @@ XMPP.prototype.removeListener = function (type, listener) {
227 219
     this.eventEmitter.removeListener(type, listener);
228 220
 };
229 221
 
230
-XMPP.prototype.leaveRoom = function () {
231
-    this.connection.emuc.doLeave();
222
+XMPP.prototype.leaveRoom = function (jid) {
223
+    this.connection.emuc.doLeave(jid);
232 224
 };
233 225
 
234 226
 
@@ -330,43 +322,6 @@ XMPP.prototype.sendAudioInfoPresence = function(mute, callback) {
330 322
     return true;
331 323
 };
332 324
 
333
-XMPP.prototype.addToPresence = function (name, value, dontSend) {
334
-    switch (name) {
335
-        case "displayName":
336
-            this.connection.emuc.addDisplayNameToPresence(value);
337
-            break;
338
-        case "prezi":
339
-            this.connection.emuc.addPreziToPresence(value, 0);
340
-            break;
341
-        case "preziSlide":
342
-            this.connection.emuc.addCurrentSlideToPresence(value);
343
-            break;
344
-        case "connectionQuality":
345
-            this.connection.emuc.addConnectionInfoToPresence(value);
346
-            break;
347
-        case "email":
348
-            this.connection.emuc.addEmailToPresence(value);
349
-            break;
350
-        case "devices":
351
-            this.connection.emuc.addDevicesToPresence(value);
352
-            break;
353
-        case "videoType":
354
-            this.connection.emuc.addVideoTypeToPresence(value);
355
-            break;
356
-        case "startMuted":
357
-            if(!Moderator.isModerator())
358
-                return;
359
-            this.connection.emuc.addStartMutedToPresence(value[0],
360
-                value[1]);
361
-            break;
362
-        default :
363
-            console.log("Unknown tag for presence: " + name);
364
-            return;
365
-    }
366
-    if (!dontSend)
367
-        this.connection.emuc.sendPresence();
368
-};
369
-
370 325
 /**
371 326
  * Sends 'data' as a log message to the focus. Returns true iff a message
372 327
  * was sent.
@@ -408,17 +363,6 @@ XMPP.prototype.getXmppLog = function () {
408 363
     return this.connection.logger ? this.connection.logger.log : null;
409 364
 };
410 365
 
411
-XMPP.prototype.sendChatMessage = function (message, nickname) {
412
-    this.connection.emuc.sendMessage(message, nickname);
413
-};
414
-
415
-XMPP.prototype.setSubject = function (topic) {
416
-    this.connection.emuc.setSubject(topic);
417
-};
418
-
419
-XMPP.prototype.lockRoom = function (key, onSuccess, onError, onNotSupported) {
420
-    this.connection.emuc.lockRoom(key, onSuccess, onError, onNotSupported);
421
-};
422 366
 
423 367
 XMPP.prototype.dial = function (to, from, roomName,roomPass) {
424 368
     this.connection.rayo.dial(to, from, roomName,roomPass);
@@ -436,25 +380,12 @@ XMPP.prototype.logout = function (callback) {
436 380
     Moderator.logout(callback);
437 381
 };
438 382
 
439
-XMPP.prototype.findJidFromResource = function (resource) {
440
-    return this.connection.emuc.findJidFromResource(resource);
441
-};
442
-
443
-XMPP.prototype.getMembers = function () {
444
-    return this.connection.emuc.members;
445
-};
446
-
447 383
 XMPP.prototype.getJidFromSSRC = function (ssrc) {
448 384
     if (!this.isConferenceInProgress())
449 385
         return null;
450 386
     return this.connection.jingle.activecall.getSsrcOwner(ssrc);
451 387
 };
452 388
 
453
-// Returns true iff we have joined the MUC.
454
-XMPP.prototype.isMUCJoined = function () {
455
-    return this.connection.emuc.joined;
456
-};
457
-
458 389
 XMPP.prototype.getSessions = function () {
459 390
     return this.connection.jingle.sessions;
460 391
 };
@@ -466,13 +397,13 @@ XMPP.prototype.removeStream = function (stream) {
466 397
 };
467 398
 
468 399
 XMPP.prototype.disconnect = function (callback) {
469
-    if (disconnectInProgress || !this.connection || !this.connection.connected)
400
+    if (this.disconnectInProgress || !this.connection || !this.connection.connected)
470 401
     {
471 402
         this.eventEmitter.emit(JitsiConnectionEvents.WRONG_STATE);
472 403
         return;
473 404
     }
474 405
 
475
-    disconnectInProgress = true;
406
+    this.disconnectInProgress = true;
476 407
 
477 408
     this.connection.disconnect();
478 409
 };

Loading…
取消
儲存