浏览代码

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
-var xmpp = require("./modules/xmpp/xmpp");
1
+var room = null;
2
+
3
+
2
 /**
4
 /**
3
  * Creates a JitsiConference object with the given name and properties.
5
  * Creates a JitsiConference object with the given name and properties.
4
  * Note: this constructor is not a part of the public API (objects should be
6
  * Note: this constructor is not a part of the public API (objects should be
10
  */
12
  */
11
 
13
 
12
 function JitsiConference(options) {
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
  * Joins the conference.
21
  * Joins the conference.
18
  */
22
  */
19
 JitsiConference.prototype.join = function () {
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
  * Leaves the conference.
28
  * Leaves the conference.
25
  */
29
  */
26
 JitsiConference.prototype.leave = function () {
30
 JitsiConference.prototype.leave = function () {
27
-    xmpp.l
31
+    this.xmpp.leaveRoom(room.roomjid);
32
+    room = null;
28
 }
33
 }
29
 
34
 
30
 /**
35
 /**
55
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
60
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
56
  */
61
  */
57
 JitsiConference.prototype.on = function (eventId, handler) {
62
 JitsiConference.prototype.on = function (eventId, handler) {
58
-
63
+    this.xmpp.addListener(eventId, handler);
59
 }
64
 }
60
 
65
 
61
 /**
66
 /**
66
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
71
  * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
67
  */
72
  */
68
 JitsiConference.prototype.off = function (eventId, handler) {
73
 JitsiConference.prototype.off = function (eventId, handler) {
69
-
74
+    this.xmpp.removeListener(event, listener);
70
 }
75
 }
71
 
76
 
72
 // Common aliases for event emitter
77
 // Common aliases for event emitter
95
  * @param message the text message.
100
  * @param message the text message.
96
  */
101
  */
97
 JitsiConference.prototype.sendTextMessage = function (message) {
102
 JitsiConference.prototype.sendTextMessage = function (message) {
98
-
103
+    room.send
99
 }
104
 }
100
 
105
 
101
 /**
106
 /**
117
  * @param name the display name to set
122
  * @param name the display name to set
118
  */
123
  */
119
 JitsiConference.prototype.setDisplayName = function(name) {
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
 var JitsiConference = require("./JitsiConference");
1
 var JitsiConference = require("./JitsiConference");
2
 var XMPP = require("./modules/xmpp/xmpp");
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
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
10
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6
  * JitsiConference interface.
11
  * JitsiConference interface.
57
  * @param event {JitsiConnectionEvents} the connection event.
62
  * @param event {JitsiConnectionEvents} the connection event.
58
  * @param listener {Function} the function that will receive the event
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
     this.xmpp.addListener(event, listener);
66
     this.xmpp.addListener(event, listener);
62
 }
67
 }
63
 
68
 
66
  * @param event {JitsiConnectionEvents} the connection event.
71
  * @param event {JitsiConnectionEvents} the connection event.
67
  * @param listener {Function} the function that will receive the event
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
     this.xmpp.removeListener(event, listener);
75
     this.xmpp.removeListener(event, listener);
71
 }
76
 }
72
 
77
 

+ 669
- 118
lib-jitsi-meet.js
文件差异内容过多而无法显示
查看文件


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

35
  * Sends statistics to other participants
35
  * Sends statistics to other participants
36
  */
36
  */
37
 function sendStats() {
37
 function sendStats() {
38
-    APP.xmpp.addToPresence("connectionQuality", convertToMUCStats(stats));
38
+    APP.xmpp.addToPresence("stats", convertToMUCStats(stats));
39
 }
39
 }
40
 
40
 
41
 /**
41
 /**
45
  */
45
  */
46
 function convertToMUCStats(stats) {
46
 function convertToMUCStats(stats) {
47
     return {
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
-var email = '';
2
-var displayName = '';
3
-var userId;
4
-var language = null;
5
-
6
-
7
 function supportsLocalStorage() {
1
 function supportsLocalStorage() {
8
     try {
2
     try {
9
         return 'localStorage' in window && window.localStorage !== null;
3
         return 'localStorage' in window && window.localStorage !== null;
21
     return _p8() + _p8() + _p8() + _p8();
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
 module.exports = Settings;
72
 module.exports = Settings;

+ 460
- 560
modules/xmpp/strophe.emuc.js
文件差异内容过多而无法显示
查看文件


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

10
 var RTC = require("../RTC/RTC");
10
 var RTC = require("../RTC/RTC");
11
 
11
 
12
 var authenticatedUser = false;
12
 var authenticatedUser = false;
13
-var disconnectInProgress = false;
14
 
13
 
15
 function createConnection(bosh) {
14
 function createConnection(bosh) {
16
     bosh = bosh || '/http-bind';
15
     bosh = bosh || '/http-bind';
21
 
20
 
22
 
21
 
23
 //!!!!!!!!!! FIXME: ...
22
 //!!!!!!!!!! FIXME: ...
24
-function initStrophePlugins()
23
+function initStrophePlugins(XMPP)
25
 {
24
 {
26
-//    require("./strophe.emuc")(XMPP, eventEmitter);
25
+    require("./strophe.emuc")(XMPP);
27
 //    require("./strophe.jingle")(XMPP, eventEmitter);
26
 //    require("./strophe.jingle")(XMPP, eventEmitter);
28
 //    require("./strophe.moderate")(XMPP, eventEmitter);
27
 //    require("./strophe.moderate")(XMPP, eventEmitter);
29
     require("./strophe.util")();
28
     require("./strophe.util")();
56
     this.sessionTerminated = false;
55
     this.sessionTerminated = false;
57
     this.eventEmitter = new EventEmitter();
56
     this.eventEmitter = new EventEmitter();
58
     this.connection = null;
57
     this.connection = null;
58
+    this.disconnectInProgress = false;
59
 
59
 
60
     this.forceMuted = false;
60
     this.forceMuted = false;
61
     this.options = options;
61
     this.options = options;
62
-    initStrophePlugins();
62
+    initStrophePlugins(this);
63
 //    registerListeners();
63
 //    registerListeners();
64
     Moderator.init(this, this.eventEmitter);
64
     Moderator.init(this, this.eventEmitter);
65
     this.connection = createConnection(options.bosh);
65
     this.connection = createConnection(options.bosh);
110
                 self.connection.jingle.getStunAndTurnCredentials();
110
                 self.connection.jingle.getStunAndTurnCredentials();
111
             }
111
             }
112
 
112
 
113
+
113
             console.info("My Jabber ID: " + self.connection.jid);
114
             console.info("My Jabber ID: " + self.connection.jid);
114
 
115
 
115
             if (password)
116
             if (password)
117
             if (self.connection && self.connection.connected &&
118
             if (self.connection && self.connection.connected &&
118
                 Strophe.getResourceFromJid(self.connection.jid)) {
119
                 Strophe.getResourceFromJid(self.connection.jid)) {
119
                 // .connected is true while connecting?
120
                 // .connected is true while connecting?
121
+                self.connection.send($pres());
120
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
122
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
121
                     Strophe.getResourceFromJid(self.connection.jid));
123
                     Strophe.getResourceFromJid(self.connection.jid));
122
             }
124
             }
130
             }
132
             }
131
             lastErrorMsg = msg;
133
             lastErrorMsg = msg;
132
         } else if (status === Strophe.Status.DISCONNECTED) {
134
         } else if (status === Strophe.Status.DISCONNECTED) {
135
+            self.disconnectInProgress = false;
133
             if (anonymousConnectionFailed) {
136
             if (anonymousConnectionFailed) {
134
                 // prompt user for username and password
137
                 // prompt user for username and password
135
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_FAILED,
138
                 self.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_FAILED,
165
 };
168
 };
166
 
169
 
167
 XMPP.prototype.joinRoom = function(roomName, useNicks, nick) {
170
 XMPP.prototype.joinRoom = function(roomName, useNicks, nick) {
168
-    var roomjid = roomName;
171
+    var roomjid = roomName  + '@' + Strophe.getDomainFromJid(this.connection.jid);
169
 
172
 
170
     if (useNicks) {
173
     if (useNicks) {
171
         if (nick) {
174
         if (nick) {
181
 
184
 
182
         roomjid += '/' + tmpJid;
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
 XMPP.prototype.disposeConference = function (onUnload) {
191
 XMPP.prototype.disposeConference = function (onUnload) {
200
     var handler = this.connection.jingle.activecall;
192
     var handler = this.connection.jingle.activecall;
227
     this.eventEmitter.removeListener(type, listener);
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
     return true;
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
  * Sends 'data' as a log message to the focus. Returns true iff a message
326
  * Sends 'data' as a log message to the focus. Returns true iff a message
372
  * was sent.
327
  * was sent.
408
     return this.connection.logger ? this.connection.logger.log : null;
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
 XMPP.prototype.dial = function (to, from, roomName,roomPass) {
367
 XMPP.prototype.dial = function (to, from, roomName,roomPass) {
424
     this.connection.rayo.dial(to, from, roomName,roomPass);
368
     this.connection.rayo.dial(to, from, roomName,roomPass);
436
     Moderator.logout(callback);
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
 XMPP.prototype.getJidFromSSRC = function (ssrc) {
383
 XMPP.prototype.getJidFromSSRC = function (ssrc) {
448
     if (!this.isConferenceInProgress())
384
     if (!this.isConferenceInProgress())
449
         return null;
385
         return null;
450
     return this.connection.jingle.activecall.getSsrcOwner(ssrc);
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
 XMPP.prototype.getSessions = function () {
389
 XMPP.prototype.getSessions = function () {
459
     return this.connection.jingle.sessions;
390
     return this.connection.jingle.sessions;
460
 };
391
 };
466
 };
397
 };
467
 
398
 
468
 XMPP.prototype.disconnect = function (callback) {
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
         this.eventEmitter.emit(JitsiConnectionEvents.WRONG_STATE);
402
         this.eventEmitter.emit(JitsiConnectionEvents.WRONG_STATE);
472
         return;
403
         return;
473
     }
404
     }
474
 
405
 
475
-    disconnectInProgress = true;
406
+    this.disconnectInProgress = true;
476
 
407
 
477
     this.connection.disconnect();
408
     this.connection.disconnect();
478
 };
409
 };

正在加载...
取消
保存