telemersive-bus 0.6.8 → 0.6.10
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/LICENSE.txt +7 -0
- package/lib/BusManager.js +33 -11
- package/package.json +1 -1
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2021-2024 ZHdK.ch / immersive-arts.ch
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/BusManager.js
CHANGED
|
@@ -12,7 +12,7 @@ const {RoomAccess, RoomInfo, PeerCredentials, PeerInfo} = require('./protos/BusM
|
|
|
12
12
|
|
|
13
13
|
/* time the housekeeping thread waits until it continues with the next step
|
|
14
14
|
*/
|
|
15
|
-
const houseKeepingTimeOut =
|
|
15
|
+
const houseKeepingTimeOut = 1500;
|
|
16
16
|
const houseKeepingTimeOut_onRepeat = 1500;
|
|
17
17
|
const houseKeepingTimeOut_onPeerLeft= 1000;
|
|
18
18
|
const houseKeepingTimeOut_onPeerJoined = 5000;
|
|
@@ -164,7 +164,7 @@ class BusManager {
|
|
|
164
164
|
|
|
165
165
|
for (const key of keys) {
|
|
166
166
|
// send ping message
|
|
167
|
-
console.log(` -> room '${key}' with id '${this.rooms[key].roomId}'...`);
|
|
167
|
+
console.log(` -> room '${key}' with id '${this.rooms[key].roomId}' pings joined peers ...`);
|
|
168
168
|
await this.communicator.publish(new BusMsgPub(this.busTopics.baseRoomAlive(key).build(), RoomInfo, 1, false).encode(
|
|
169
169
|
{
|
|
170
170
|
"timestamp": Math.round(new Date().getTime() / 1000),
|
|
@@ -240,9 +240,13 @@ class BusManager {
|
|
|
240
240
|
*/
|
|
241
241
|
cleanOut = async () => {
|
|
242
242
|
if(this.houseKeepingInProgress) {
|
|
243
|
-
this.houseKeepingInProgress = false;
|
|
244
243
|
console.log(` -> housekeeping -> cleaning out ...`);
|
|
245
|
-
|
|
244
|
+
// flag the room as being in the process to be removed
|
|
245
|
+
const flag4cleanupRooms = (currentRoom) => this.rooms[currentRoom.roomName].flagRoom4cleanup = true;
|
|
246
|
+
Object.values(this.roomHousekeep).forEach(flag4cleanupRooms);
|
|
247
|
+
|
|
248
|
+
// kick out the non-responding peers
|
|
249
|
+
const kickOutPeer = async (currentPeer) => {
|
|
246
250
|
console.log(` <- remove peer '${currentPeer.peerName}' from room '${currentPeer.roomName}' `);
|
|
247
251
|
// first we send clear retain message to peer joined addresses that have not replied:
|
|
248
252
|
await this.communicator.clearRetain(this.busTopics.roomPeerJoin(currentPeer.roomName, currentPeer.peerId).build());
|
|
@@ -261,12 +265,22 @@ class BusManager {
|
|
|
261
265
|
this.busTopics.roomPeerLeft(currentPeer.roomName, currentPeer.peerId).build(),
|
|
262
266
|
PeerInfo, 2, true).encode(infoPayload));
|
|
263
267
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
268
|
+
const peerCleanup = async () => {
|
|
269
|
+
for (const peer of Object.values(this.peerHousekeep)) {
|
|
270
|
+
await kickOutPeer(peer);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
await peerCleanup();
|
|
274
|
+
|
|
275
|
+
// And now remove the rooms
|
|
267
276
|
const cleanupRooms = async (currentRoom) => await this.deleteRoom(currentRoom.roomName);
|
|
268
|
-
|
|
269
|
-
|
|
277
|
+
const housekeeping = async () => {
|
|
278
|
+
for (const room of Object.values(this.roomHousekeep)) {
|
|
279
|
+
await cleanupRooms(room);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
await housekeeping();
|
|
283
|
+
|
|
270
284
|
console.log(` -> housekeeping DONE`);
|
|
271
285
|
} else {
|
|
272
286
|
console.log(` -> housekeeping was interrupted`);
|
|
@@ -278,6 +292,9 @@ class BusManager {
|
|
|
278
292
|
await this.communicator.unsubscribe(this.busTopics.baseRoomAlivePing("+").build());
|
|
279
293
|
// cleanup the communicator
|
|
280
294
|
this.communicator.clearAutoGeneratedSubscriptions();
|
|
295
|
+
// set this flag to false at the end to make sure a new houskeeping cycle can only be started once
|
|
296
|
+
// all topics are unsubscribed - otherwise it won't gather the joined peers inside the room.
|
|
297
|
+
this.houseKeepingInProgress = false;
|
|
281
298
|
}
|
|
282
299
|
|
|
283
300
|
/**
|
|
@@ -346,6 +363,10 @@ class BusManager {
|
|
|
346
363
|
console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | incompatible app version`);
|
|
347
364
|
accessGrant = false;
|
|
348
365
|
reason = `app version incompatible: required version is '${this.rooms[_message.roomName].appVersion}', yours is '${_message.appVersion}'`;
|
|
366
|
+
} else if (this.rooms[_message.roomName].flagRoom4cleanup) {
|
|
367
|
+
console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | room is in process of being removed`);
|
|
368
|
+
accessGrant = false;
|
|
369
|
+
reason = `room is in process of being removed. try again in a few seconds.`;
|
|
349
370
|
} else {
|
|
350
371
|
accessGrant = true;
|
|
351
372
|
console.log(` -> peer '${_message.peerName}' joining room '${_message.roomName}'`);
|
|
@@ -483,7 +504,8 @@ class BusManager {
|
|
|
483
504
|
roomId: roomID,
|
|
484
505
|
roomUUID: roomUUID,
|
|
485
506
|
roomPwd: _roomPwd,
|
|
486
|
-
appVersion: _appVersion
|
|
507
|
+
appVersion: _appVersion,
|
|
508
|
+
flagRoom4cleanup: false
|
|
487
509
|
}
|
|
488
510
|
console.log(`-> generate room: '${_roomName}' with id '${roomID}' and uuid: '${roomID}'`);
|
|
489
511
|
console.log(` with uuid: '${roomUUID}'`);
|
|
@@ -547,7 +569,7 @@ class BusManager {
|
|
|
547
569
|
|
|
548
570
|
delete this.rooms[_roomName];
|
|
549
571
|
} catch (e) {
|
|
550
|
-
console.log(
|
|
572
|
+
console.log(` <! exception while removing room '${_roomName}': '${e.message}' `);
|
|
551
573
|
}
|
|
552
574
|
}
|
|
553
575
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telemersive-bus",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
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": {
|