소스 검색

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,6 +37,7 @@ function JitsiConference(options) {
37 37
     this.eventEmitter = new EventEmitter();
38 38
     this.settings = new Settings();
39 39
     this._init(options);
40
+    this.componentsVersions = new ComponentsVersions(this);
40 41
     this.rtc = new RTC(this, options);
41 42
     this.statistics = new Statistics(this.xmpp, {
42 43
         callStatsID: this.options.config.callStatsID,
@@ -86,7 +87,11 @@ JitsiConference.prototype._init = function (options) {
86 87
 
87 88
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
88 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 95
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
91 96
 }
92 97
 
@@ -95,14 +100,22 @@ JitsiConference.prototype._init = function (options) {
95 100
  * @param options {object} options to be overriden
96 101
  */
97 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 116
     this._init(options || {});
102 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 119
     this.join();
107 120
 }
108 121
 
@@ -126,24 +139,32 @@ JitsiConference.prototype.isJoined = function () {
126 139
  * Leaves the conference and calls onMemberLeft for every participant.
127 140
  */
128 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 147
     // leave the conference
130 148
     if (this.room) {
131 149
         this.room.leave();
132 150
     }
133 151
 
134 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 155
  * Leaves the conference.
142 156
  * @returns {Promise}
143 157
  */
144
-JitsiConference.prototype.leave = function () {
158
+JitsiConference.prototype.leave = function (dontRemoveLocalTracks) {
145 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 168
     return Promise.all(
148 169
         conference.getLocalTracks().map(function (track) {
149 170
             return conference.removeTrack(track);
@@ -1084,5 +1105,22 @@ JitsiConference.prototype._setupListeners = function () {
1084 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 1126
 module.exports = JitsiConference;

+ 6
- 1
JitsiConferenceErrors.js 파일 보기

@@ -59,7 +59,12 @@ var JitsiConferenceErrors = {
59 59
     /**
60 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 69
      * Many more errors TBD here.
65 70
      */

+ 33
- 0
JitsiConnection.js 파일 보기

@@ -1,5 +1,6 @@
1 1
 var JitsiConference = require("./JitsiConference");
2 2
 var XMPP = require("./modules/xmpp/xmpp");
3
+var JitsiConnectionEvents = require("./JitsiConnectionEvents");
3 4
 
4 5
 /**
5 6
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
@@ -40,6 +41,38 @@ JitsiConnection.prototype.attach = function (options) {
40 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 77
  * Disconnect the client from the server.
45 78
  */

+ 14
- 8
modules/version/ComponentsVersions.js 파일 보기

@@ -19,17 +19,18 @@ ComponentsVersions.XMPP_SERVER_COMPONENT = "xmpp";
19 19
 
20 20
 /**
21 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 26
  * @constructor
26 27
  */
27
-function ComponentsVersions(chatRoom) {
28
+function ComponentsVersions(conference) {
28 29
 
29 30
     this.versions = {};
30 31
 
31
-    this.chatRoom = chatRoom;
32
-    this.chatRoom.addPresenceListener(
32
+    this.conference = conference;
33
+    this.conference.addCommandListener(
33 34
         'versions', this.processPresence.bind(this));
34 35
 }
35 36
 
@@ -41,7 +42,7 @@ function(node, mucResource, mucJid) {
41 42
         return;
42 43
     }
43 44
 
44
-    if (!this.chatRoom.isFocus(mucJid)) {
45
+    if (!this.conference._isFocus(mucJid)) {
45 46
         logger.warn(
46 47
             "Received versions not from the focus user: " + node, mucJid);
47 48
         return;
@@ -62,6 +63,12 @@ function(node, mucResource, mucJid) {
62 63
 
63 64
         var version = item.value;
64 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 72
             this.versions[componentName] = version;
66 73
             logger.info("Got " + componentName + " version: " + version);
67 74
 
@@ -87,4 +94,3 @@ ComponentsVersions.prototype.getComponentVersion = function(componentName) {
87 94
 };
88 95
 
89 96
 module.exports = ComponentsVersions;
90
-

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

@@ -74,7 +74,7 @@ function ChatRoom(connection, jid, password, XMPP, options, settings) {
74 74
     this.presMap = {};
75 75
     this.presHandlers = {};
76 76
     this.joined = false;
77
-    this.role = 'none';
77
+    this.role = null;
78 78
     this.focusMucJid = null;
79 79
     this.bridgeIsDown = false;
80 80
     this.options = options || {};
@@ -271,8 +271,9 @@ ChatRoom.prototype.onPresence = function (pres) {
271 271
     }
272 272
 
273 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 277
             this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
277 278
         }
278 279
         if (!this.joined) {
@@ -592,6 +593,30 @@ ChatRoom.prototype.removePresenceListener = function (name) {
592 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 621
  * Checks if the user identified by given <tt>mucJid</tt> is the conference
597 622
  * focus.

+ 45
- 0
modules/xmpp/xmpp.js 파일 보기

@@ -41,6 +41,8 @@ function XMPP(options, token) {
41 41
     this.connectionTimes = {};
42 42
     this.forceMuted = false;
43 43
     this.options = options;
44
+    this.connectParams = {};
45
+    this.token = token;
44 46
     initStrophePlugins(this);
45 47
 
46 48
     this.connection = createConnection(options.bosh, token);
@@ -56,6 +58,45 @@ function XMPP(options, token) {
56 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 101
  * Initializes the list of feature advertised through the disco-info mechanism
61 102
  */
@@ -218,6 +259,10 @@ XMPP.prototype._connect = function (jid, password) {
218 259
 }
219 260
 
220 261
 XMPP.prototype.connect = function (jid, password) {
262
+    this.connectParams = {
263
+        jid: jid,
264
+        password: password
265
+    };
221 266
     if (!jid) {
222 267
         var configDomain
223 268
             = this.options.hosts.anonymousdomain || this.options.hosts.domain;

Loading…
취소
저장