浏览代码

Implements JitsiConnection.reload. Minor fixes related to JitsiConference.reload.

dev1
hristoterezov 8 年前
父节点
当前提交
0449071f89
共有 6 个文件被更改,包括 176 次插入24 次删除
  1. 50
    12
      JitsiConference.js
  2. 6
    1
      JitsiConferenceErrors.js
  3. 33
    0
      JitsiConnection.js
  4. 14
    8
      modules/version/ComponentsVersions.js
  5. 28
    3
      modules/xmpp/ChatRoom.js
  6. 45
    0
      modules/xmpp/xmpp.js

+ 50
- 12
JitsiConference.js 查看文件

37
     this.eventEmitter = new EventEmitter();
37
     this.eventEmitter = new EventEmitter();
38
     this.settings = new Settings();
38
     this.settings = new Settings();
39
     this._init(options);
39
     this._init(options);
40
+    this.componentsVersions = new ComponentsVersions(this);
40
     this.rtc = new RTC(this, options);
41
     this.rtc = new RTC(this, options);
41
     this.statistics = new Statistics(this.xmpp, {
42
     this.statistics = new Statistics(this.xmpp, {
42
         callStatsID: this.options.config.callStatsID,
43
         callStatsID: this.options.config.callStatsID,
86
 
87
 
87
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
88
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
88
         this.settings);
89
         this.settings);
89
-    this.componentsVersions = new ComponentsVersions(this.room);
90
+
91
+    //restore previous presence options
92
+    if(options.roomState) {
93
+        this.room.loadState(options.roomState);
94
+    }
90
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
95
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
91
 }
96
 }
92
 
97
 
95
  * @param options {object} options to be overriden
100
  * @param options {object} options to be overriden
96
  */
101
  */
97
 JitsiConference.prototype.reload = function (options) {
102
 JitsiConference.prototype.reload = function (options) {
98
-    this.statistics.stopCallStats();
99
-    this.rtc.closeAllDataChannels();
100
-    this._leaveRoomAndRemoveParticipants();
103
+    var roomState = this.room.exportState();
104
+    if(!options)
105
+        options = {};
106
+    options.roomState = roomState;
107
+    this.leave(true);
108
+    this.reinitialize(options);
109
+}
110
+
111
+/**
112
+ * Reinitializes JitsiConference instance
113
+ * @param options {object} options to be overriden
114
+ */
115
+JitsiConference.prototype.reinitialize = function (options) {
101
     this._init(options || {});
116
     this._init(options || {});
102
     this.eventManager.setupChatRoomListeners();
117
     this.eventManager.setupChatRoomListeners();
103
-    //if we have new xmpp instance we should set it's listeners again.
104
-    if(options.connection)
105
-        this.eventManager.setupXMPPListeners();
118
+    this.eventManager.setupStatisticsListeners();
106
     this.join();
119
     this.join();
107
 }
120
 }
108
 
121
 
126
  * Leaves the conference and calls onMemberLeft for every participant.
139
  * Leaves the conference and calls onMemberLeft for every participant.
127
  */
140
  */
128
 JitsiConference.prototype._leaveRoomAndRemoveParticipants = function () {
141
 JitsiConference.prototype._leaveRoomAndRemoveParticipants = function () {
142
+    // remove all participants
143
+    this.getParticipants().forEach(function (participant) {
144
+        this.onMemberLeft(participant.getJid());
145
+    }.bind(this));
146
+
129
     // leave the conference
147
     // leave the conference
130
     if (this.room) {
148
     if (this.room) {
131
         this.room.leave();
149
         this.room.leave();
132
     }
150
     }
133
 
151
 
134
     this.room = null;
152
     this.room = null;
135
-    // remove all participants
136
-    this.getParticipants().forEach(function (participant) {
137
-        this.onMemberLeft(participant.getJid());
138
-    }.bind(this));
139
 }
153
 }
140
 /**
154
 /**
141
  * Leaves the conference.
155
  * Leaves the conference.
142
  * @returns {Promise}
156
  * @returns {Promise}
143
  */
157
  */
144
-JitsiConference.prototype.leave = function () {
158
+JitsiConference.prototype.leave = function (dontRemoveLocalTracks) {
145
     var conference = this;
159
     var conference = this;
146
 
160
 
161
+    this.statistics.stopCallStats();
162
+    this.rtc.closeAllDataChannels();
163
+    if(dontRemoveLocalTracks) {
164
+        this._leaveRoomAndRemoveParticipants();
165
+        return  Promise.resolve();
166
+    }
167
+
147
     return Promise.all(
168
     return Promise.all(
148
         conference.getLocalTracks().map(function (track) {
169
         conference.getLocalTracks().map(function (track) {
149
             return conference.removeTrack(track);
170
             return conference.removeTrack(track);
1084
     this.eventManager.setupStatisticsListeners();
1105
     this.eventManager.setupStatisticsListeners();
1085
 }
1106
 }
1086
 
1107
 
1108
+/**
1109
+ * Checks if the user identified by given <tt>mucJid</tt> is the conference
1110
+ * focus.
1111
+ * @param mucJid the full MUC address of the user to be checked.
1112
+ * @returns {boolean} <tt>true</tt> if MUC user is the conference focus.
1113
+ */
1114
+JitsiConference.prototype._isFocus = function (mucJid) {
1115
+    return this.room.isFocus(mucJid);
1116
+}
1117
+
1118
+/**
1119
+ * Fires CONFERENCE_FAILED event with INCOMPATIBLE_SERVER_VERSIONS parameter
1120
+ */
1121
+JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
1122
+    this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
1123
+        JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
1124
+}
1087
 
1125
 
1088
 module.exports = JitsiConference;
1126
 module.exports = JitsiConference;

+ 6
- 1
JitsiConferenceErrors.js 查看文件

59
     /**
59
     /**
60
      * Indicates that max users limit has been reached.
60
      * Indicates that max users limit has been reached.
61
      */
61
      */
62
-    CONFERENCE_MAX_USERS: "conference.max_users"
62
+    CONFERENCE_MAX_USERS: "conference.max_users",
63
+    /**
64
+     * Indicates that the versions of the server side components are
65
+     * incompatible with the client side.
66
+     */
67
+    INCOMPATIBLE_SERVER_VERSIONS: "conference.incompatible_server_versions"
63
     /**
68
     /**
64
      * Many more errors TBD here.
69
      * Many more errors TBD here.
65
      */
70
      */

+ 33
- 0
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
+var JitsiConnectionEvents = require("./JitsiConnectionEvents");
3
 
4
 
4
 /**
5
 /**
5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
40
     this.xmpp.attach(options);
41
     this.xmpp.attach(options);
41
 }
42
 }
42
 
43
 
44
+/**
45
+ * Reloads the JitsiConnection instance and all related conferences
46
+ * @param options {object} options to be overriden
47
+ */
48
+JitsiConnection.prototype.reload = function (options) {
49
+    var states = {};
50
+    for(var name in this.conferences) {
51
+        states[name] = this.conferences[name].room.exportState();
52
+        this.conferences[name].leave(true);
53
+    }
54
+    this.connectionEstablishedHandler =
55
+        this.reloadConferneces.bind(this, states);
56
+    this.addEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
57
+        this.connectionEstablishedHandler);
58
+    this.xmpp.reload(options || {});
59
+}
60
+
61
+/**
62
+ * Reloads all conferences related to this JitsiConnection instance
63
+ * @param states {object} the exported states per conference
64
+ */
65
+JitsiConnection.prototype.reloadConferences = function (states) {
66
+    this.removeEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
67
+        this.connectionEstablishedHandler);
68
+    this.connectionEstablishedHandler = null;
69
+    states = states || {};
70
+    for(var name in this.conferences) {
71
+        this.conferences[name].reinitialize({connection: this,
72
+            roomState: states[name]});
73
+    }
74
+}
75
+
43
 /**
76
 /**
44
  * Disconnect the client from the server.
77
  * Disconnect the client from the server.
45
  */
78
  */

+ 14
- 8
modules/version/ComponentsVersions.js 查看文件

19
 
19
 
20
 /**
20
 /**
21
  * Creates new instance of <tt>ComponentsVersions</tt> which will be discovering
21
  * Creates new instance of <tt>ComponentsVersions</tt> which will be discovering
22
- * the versions of conferencing system components in given <tt>ChatRoom</tt>.
23
- * @param chatRoom <tt>ChatRoom</tt> instance which will be used to listen for
24
- *        focus presence updates.
22
+ * the versions of conferencing system components in given
23
+ * <tt>JitsiConference</tt>.
24
+ * @param conference <tt>JitsiConference</tt> instance which will be used to
25
+ *        listen for focus presence updates.
25
  * @constructor
26
  * @constructor
26
  */
27
  */
27
-function ComponentsVersions(chatRoom) {
28
+function ComponentsVersions(conference) {
28
 
29
 
29
     this.versions = {};
30
     this.versions = {};
30
 
31
 
31
-    this.chatRoom = chatRoom;
32
-    this.chatRoom.addPresenceListener(
32
+    this.conference = conference;
33
+    this.conference.addCommandListener(
33
         'versions', this.processPresence.bind(this));
34
         'versions', this.processPresence.bind(this));
34
 }
35
 }
35
 
36
 
41
         return;
42
         return;
42
     }
43
     }
43
 
44
 
44
-    if (!this.chatRoom.isFocus(mucJid)) {
45
+    if (!this.conference._isFocus(mucJid)) {
45
         logger.warn(
46
         logger.warn(
46
             "Received versions not from the focus user: " + node, mucJid);
47
             "Received versions not from the focus user: " + node, mucJid);
47
         return;
48
         return;
62
 
63
 
63
         var version = item.value;
64
         var version = item.value;
64
         if (this.versions[componentName] !== version) {
65
         if (this.versions[componentName] !== version) {
66
+            if(this.versions[componentName] &&
67
+                componentName !== ComponentsVersions.FOCUS_COMPONENT &&
68
+                componentName !== ComponentsVersions.VIDEOBRIDGE_COMPONENT) {
69
+                //version is changed during the call
70
+                this.conference._fireIncompatibleVersionsEvent();
71
+            }
65
             this.versions[componentName] = version;
72
             this.versions[componentName] = version;
66
             logger.info("Got " + componentName + " version: " + version);
73
             logger.info("Got " + componentName + " version: " + version);
67
 
74
 
87
 };
94
 };
88
 
95
 
89
 module.exports = ComponentsVersions;
96
 module.exports = ComponentsVersions;
90
-

+ 28
- 3
modules/xmpp/ChatRoom.js 查看文件

74
     this.presMap = {};
74
     this.presMap = {};
75
     this.presHandlers = {};
75
     this.presHandlers = {};
76
     this.joined = false;
76
     this.joined = false;
77
-    this.role = 'none';
77
+    this.role = null;
78
     this.focusMucJid = null;
78
     this.focusMucJid = null;
79
     this.bridgeIsDown = false;
79
     this.bridgeIsDown = false;
80
     this.options = options || {};
80
     this.options = options || {};
271
     }
271
     }
272
 
272
 
273
     if (from == this.myroomjid) {
273
     if (from == this.myroomjid) {
274
-        if (member.affiliation == 'owner' && this.role !== member.role) {
275
-            this.role = member.role;
274
+        var newRole = member.affiliation == "owner"? member.role : "none";
275
+        if (this.role !== newRole) {
276
+            this.role = newRole;
276
             this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
277
             this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
277
         }
278
         }
278
         if (!this.joined) {
279
         if (!this.joined) {
592
     delete this.presHandlers[name];
593
     delete this.presHandlers[name];
593
 };
594
 };
594
 
595
 
596
+/**
597
+ * Exports the current state of the ChatRoom instance.
598
+ * @returns {object}
599
+ */
600
+ChatRoom.prototype.exportState = function () {
601
+    return {
602
+        presHandlers: this.presHandlers,
603
+        presMapNodes: this.presMap.nodes
604
+    }
605
+}
606
+
607
+/**
608
+ * Loads previously exported state object from ChatRoom instance into current
609
+ * ChatRoom instance.
610
+ * @param state {object} the state received by ChatRoom.exportState method.
611
+ */
612
+ChatRoom.prototype.loadState = function (state) {
613
+    if(!state || !state.presHandlers || !state.presMapNodes)
614
+        throw new Error("Invalid state object passed");
615
+
616
+    this.presHandlers = state.presHandlers;
617
+    this.presMap.nodes = state.presMapNodes;
618
+}
619
+
595
 /**
620
 /**
596
  * Checks if the user identified by given <tt>mucJid</tt> is the conference
621
  * Checks if the user identified by given <tt>mucJid</tt> is the conference
597
  * focus.
622
  * focus.

+ 45
- 0
modules/xmpp/xmpp.js 查看文件

41
     this.connectionTimes = {};
41
     this.connectionTimes = {};
42
     this.forceMuted = false;
42
     this.forceMuted = false;
43
     this.options = options;
43
     this.options = options;
44
+    this.connectParams = {};
45
+    this.token = token;
44
     initStrophePlugins(this);
46
     initStrophePlugins(this);
45
 
47
 
46
     this.connection = createConnection(options.bosh, token);
48
     this.connection = createConnection(options.bosh, token);
56
     $(window).on('beforeunload unload', this.disconnect.bind(this));
58
     $(window).on('beforeunload unload', this.disconnect.bind(this));
57
 }
59
 }
58
 
60
 
61
+/**
62
+ * Reloads the XMPP module
63
+ * @param options {object} options to be overriden
64
+ */
65
+XMPP.prototype.reload = function (options) {
66
+    if(!options)
67
+        options = {};
68
+    if(!this.options) {
69
+        this.options = options;
70
+    } else {
71
+        // Override config options
72
+        for(var key in options)
73
+            this.options[key] = options[key] || this.options[key];
74
+    }
75
+
76
+    this.disconnect();
77
+    this.connection.pause();
78
+    this.connection = createConnection(this.options.bosh, this.token);
79
+
80
+    // Initialize features advertised in disco-info
81
+    this.initFeaturesList();
82
+
83
+    //getData for attach
84
+    if(this.options.prebindURL &&
85
+        typeof(createConnectionExternally) === "function") {
86
+        var self = this;
87
+        createConnectionExternally(this.options.prebindURL, function (data) {
88
+            self.attach(data);
89
+        }, function (error) {
90
+            //connect
91
+            self.connect(this.connectParams.jid, this.connectParams.password);
92
+        });
93
+    } else {
94
+        //connect
95
+        this.connect(this.connectParams.jid, this.connectParams.password);
96
+    }
97
+
98
+}
99
+
59
 /**
100
 /**
60
  * Initializes the list of feature advertised through the disco-info mechanism
101
  * Initializes the list of feature advertised through the disco-info mechanism
61
  */
102
  */
218
 }
259
 }
219
 
260
 
220
 XMPP.prototype.connect = function (jid, password) {
261
 XMPP.prototype.connect = function (jid, password) {
262
+    this.connectParams = {
263
+        jid: jid,
264
+        password: password
265
+    };
221
     if (!jid) {
266
     if (!jid) {
222
         var configDomain
267
         var configDomain
223
             = this.options.hosts.anonymousdomain || this.options.hosts.domain;
268
             = this.options.hosts.anonymousdomain || this.options.hosts.domain;

正在加载...
取消
保存