telemersive-bus 0.6.13 → 0.6.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/BusManager.js +19 -6
- package/package.json +2 -2
package/lib/BusManager.js
CHANGED
|
@@ -31,6 +31,7 @@ class BusManager {
|
|
|
31
31
|
this.peerHousekeep = {};
|
|
32
32
|
this.roomHousekeep = {};
|
|
33
33
|
this.houseKeepingInProgress = false;
|
|
34
|
+
this.housekeepingId = 0;
|
|
34
35
|
this.chatManagers = {};
|
|
35
36
|
this.switchBoardURI = null;
|
|
36
37
|
}
|
|
@@ -122,6 +123,10 @@ class BusManager {
|
|
|
122
123
|
// we dont want to start another housekeeping process until the previous one has finished
|
|
123
124
|
if(!this.houseKeepingInProgress){
|
|
124
125
|
this.houseKeepingInProgress = true;
|
|
126
|
+
// each cycle gets a unique id so stale timers from an interrupted cycle can detect
|
|
127
|
+
// they no longer own the housekeeping state and bail out.
|
|
128
|
+
this.housekeepingId += 1;
|
|
129
|
+
const myId = this.housekeepingId;
|
|
125
130
|
console.log(` -> starting housekeeping -> gather all peers ...`);
|
|
126
131
|
this.peerHousekeep = {};
|
|
127
132
|
this.roomHousekeep = Object.assign({}, this.rooms); // clone the current room list
|
|
@@ -130,7 +135,7 @@ class BusManager {
|
|
|
130
135
|
await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomPeerJoin('+', '+').build(), this.onAllPeers, PeerInfo, 0));
|
|
131
136
|
|
|
132
137
|
// now we have to wait a moment
|
|
133
|
-
setTimeout(this.pingAllPeersAlive, houseKeepingTimeOut);
|
|
138
|
+
setTimeout(() => this.pingAllPeersAlive(myId), houseKeepingTimeOut);
|
|
134
139
|
} else {
|
|
135
140
|
// if there is already a housekeeping going on,
|
|
136
141
|
// we wait for some time to finish it and try again.
|
|
@@ -154,7 +159,11 @@ class BusManager {
|
|
|
154
159
|
/**
|
|
155
160
|
* ping all peers that are subscribed to each individual rooms
|
|
156
161
|
*/
|
|
157
|
-
pingAllPeersAlive = async () => {
|
|
162
|
+
pingAllPeersAlive = async (myId) => {
|
|
163
|
+
// if a newer cycle has started, this callback belongs to an interrupted cycle — drop it.
|
|
164
|
+
if (myId !== this.housekeepingId) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
158
167
|
if(this.houseKeepingInProgress) {
|
|
159
168
|
console.log(` -> housekeeping -> pinging all rooms ...`);
|
|
160
169
|
const keys = Object.keys(this.rooms);
|
|
@@ -174,11 +183,11 @@ class BusManager {
|
|
|
174
183
|
));
|
|
175
184
|
}
|
|
176
185
|
// now we have to wait a moment
|
|
177
|
-
setTimeout(this.cleanOut, houseKeepingTimeOut);
|
|
186
|
+
setTimeout(() => this.cleanOut(myId), houseKeepingTimeOut);
|
|
178
187
|
} else {
|
|
179
188
|
// this means the housekeeping got interrupted and
|
|
180
189
|
// needs to finish as fast as possible to cleaning up all subscriptions.
|
|
181
|
-
setTimeout(this.cleanOut, 0);
|
|
190
|
+
setTimeout(() => this.cleanOut(myId), 0);
|
|
182
191
|
}
|
|
183
192
|
}
|
|
184
193
|
|
|
@@ -252,7 +261,11 @@ class BusManager {
|
|
|
252
261
|
/**
|
|
253
262
|
* cleanout dead peers and rooms
|
|
254
263
|
*/
|
|
255
|
-
cleanOut = async () => {
|
|
264
|
+
cleanOut = async (myId) => {
|
|
265
|
+
// if a newer cycle has started, this callback belongs to an interrupted cycle — drop it.
|
|
266
|
+
if (myId !== this.housekeepingId) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
256
269
|
if(this.houseKeepingInProgress) {
|
|
257
270
|
console.log(` -> housekeeping -> cleaning out ...`);
|
|
258
271
|
// flag the room as being in the process to be removed
|
|
@@ -511,7 +524,7 @@ class BusManager {
|
|
|
511
524
|
// Generate short UUID as peerId
|
|
512
525
|
let roomUUID = this.translator.new(); // mhvXdrZT4jP5T8vBxuvm75
|
|
513
526
|
|
|
514
|
-
if(roomID === null)
|
|
527
|
+
if(roomID === null || roomID === undefined)
|
|
515
528
|
roomID = this.findUnusedRoomId();
|
|
516
529
|
this.rooms[_roomName] = {
|
|
517
530
|
roomName: _roomName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telemersive-bus",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "MQTT based data protocol to manage unlimited peers, connected by rooms, where all peers joined to a room can exchange private data. It provides a simple chat mechanism, latency pinging, publish-subscribe mechanism (based on mqtt) and a OSC-like data stream. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"crypto-js": "^4.0.0",
|
|
12
12
|
"internal-ip": "^6.2.0",
|
|
13
13
|
"mqtt": "^5.3.5",
|
|
14
|
-
"protobufjs": "^
|
|
14
|
+
"protobufjs": "^7.5.5",
|
|
15
15
|
"public-ip": "^4.0.2",
|
|
16
16
|
"sha1": "^1.1.1",
|
|
17
17
|
"short-uuid": "^4.1.0",
|