telemersive-bus 0.6.9 → 0.6.11
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 +47 -13
- 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
|
@@ -222,14 +222,28 @@ class BusManager {
|
|
|
222
222
|
console.log(` -> peer '${_message.peerName}' not joined anymore - reject from room`);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
let room_ID = -1;
|
|
226
|
+
let room_UUID = -1;
|
|
227
|
+
|
|
228
|
+
// we also check if the room is still existing..
|
|
229
|
+
if (this.rooms[_message.roomName] !== undefined){
|
|
230
|
+
// we only set the id and UUID if the room still exists.
|
|
231
|
+
room_ID = this.rooms[_message.roomName].roomId;
|
|
232
|
+
room_UUID = this.rooms[_message.roomName].roomUUID;
|
|
233
|
+
} else {
|
|
234
|
+
accessGrant = false;
|
|
235
|
+
reason = "room doesn't exist anymore";
|
|
236
|
+
console.log(` -> peer '${_message.peerName}' reject from non existing room '${_message.roomName}'`);
|
|
237
|
+
}
|
|
238
|
+
|
|
225
239
|
await this.publishRoomAccess(
|
|
226
240
|
accessGrant,
|
|
227
241
|
_message.peerId,
|
|
228
242
|
_message.clientId,
|
|
229
243
|
_message.peerName,
|
|
230
244
|
_message.roomName,
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
room_ID,
|
|
246
|
+
room_UUID,
|
|
233
247
|
_message.roomPwd,
|
|
234
248
|
reason);
|
|
235
249
|
|
|
@@ -241,7 +255,12 @@ class BusManager {
|
|
|
241
255
|
cleanOut = async () => {
|
|
242
256
|
if(this.houseKeepingInProgress) {
|
|
243
257
|
console.log(` -> housekeeping -> cleaning out ...`);
|
|
244
|
-
|
|
258
|
+
// flag the room as being in the process to be removed
|
|
259
|
+
const flag4cleanupRooms = (currentRoom) => this.rooms[currentRoom.roomName].flagRoom4cleanup = true;
|
|
260
|
+
Object.values(this.roomHousekeep).forEach(flag4cleanupRooms);
|
|
261
|
+
|
|
262
|
+
// kick out the non-responding peers
|
|
263
|
+
const kickOutPeer = async (currentPeer) => {
|
|
245
264
|
console.log(` <- remove peer '${currentPeer.peerName}' from room '${currentPeer.roomName}' `);
|
|
246
265
|
// first we send clear retain message to peer joined addresses that have not replied:
|
|
247
266
|
await this.communicator.clearRetain(this.busTopics.roomPeerJoin(currentPeer.roomName, currentPeer.peerId).build());
|
|
@@ -260,12 +279,22 @@ class BusManager {
|
|
|
260
279
|
this.busTopics.roomPeerLeft(currentPeer.roomName, currentPeer.peerId).build(),
|
|
261
280
|
PeerInfo, 2, true).encode(infoPayload));
|
|
262
281
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
282
|
+
const peerCleanup = async () => {
|
|
283
|
+
for (const peer of Object.values(this.peerHousekeep)) {
|
|
284
|
+
await kickOutPeer(peer);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
await peerCleanup();
|
|
288
|
+
|
|
289
|
+
// And now remove the rooms
|
|
266
290
|
const cleanupRooms = async (currentRoom) => await this.deleteRoom(currentRoom.roomName);
|
|
267
|
-
|
|
268
|
-
|
|
291
|
+
const housekeeping = async () => {
|
|
292
|
+
for (const room of Object.values(this.roomHousekeep)) {
|
|
293
|
+
await cleanupRooms(room);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
await housekeeping();
|
|
297
|
+
|
|
269
298
|
console.log(` -> housekeeping DONE`);
|
|
270
299
|
} else {
|
|
271
300
|
console.log(` -> housekeeping was interrupted`);
|
|
@@ -348,6 +377,10 @@ class BusManager {
|
|
|
348
377
|
console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | incompatible app version`);
|
|
349
378
|
accessGrant = false;
|
|
350
379
|
reason = `app version incompatible: required version is '${this.rooms[_message.roomName].appVersion}', yours is '${_message.appVersion}'`;
|
|
380
|
+
} else if (this.rooms[_message.roomName].flagRoom4cleanup) {
|
|
381
|
+
console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | room is in process of being removed`);
|
|
382
|
+
accessGrant = false;
|
|
383
|
+
reason = `room is in process of being removed. try again in a few seconds.`;
|
|
351
384
|
} else {
|
|
352
385
|
accessGrant = true;
|
|
353
386
|
console.log(` -> peer '${_message.peerName}' joining room '${_message.roomName}'`);
|
|
@@ -485,7 +518,8 @@ class BusManager {
|
|
|
485
518
|
roomId: roomID,
|
|
486
519
|
roomUUID: roomUUID,
|
|
487
520
|
roomPwd: _roomPwd,
|
|
488
|
-
appVersion: _appVersion
|
|
521
|
+
appVersion: _appVersion,
|
|
522
|
+
flagRoom4cleanup: false
|
|
489
523
|
}
|
|
490
524
|
console.log(`-> generate room: '${_roomName}' with id '${roomID}' and uuid: '${roomID}'`);
|
|
491
525
|
console.log(` with uuid: '${roomUUID}'`);
|
|
@@ -519,9 +553,6 @@ class BusManager {
|
|
|
519
553
|
if (this.rooms.hasOwnProperty(_roomName)) {
|
|
520
554
|
console.log(` <- remove room '${_roomName}' with id '${this.rooms[_roomName].roomId}' `);
|
|
521
555
|
try {
|
|
522
|
-
// stop the ports
|
|
523
|
-
await this.stopServerSidePortScripts(_roomName, this.rooms[_roomName].roomId);
|
|
524
|
-
|
|
525
556
|
// stop the and cleanup the room chat
|
|
526
557
|
if (this.chatManagers.hasOwnProperty(_roomName)) {
|
|
527
558
|
// stop the chatManager and delete it for this rom
|
|
@@ -547,7 +578,8 @@ class BusManager {
|
|
|
547
578
|
// and by now all retained messages in this room have been cleaned up
|
|
548
579
|
await this.communicator.unsubscribe(this.busTopics.baseRoomSubTopics(_roomName).build());
|
|
549
580
|
|
|
550
|
-
delete
|
|
581
|
+
// stop the ports and delete room for good
|
|
582
|
+
await this.stopServerSidePortScripts(_roomName, this.rooms[_roomName].roomId);
|
|
551
583
|
} catch (e) {
|
|
552
584
|
console.log(` <! exception while removing room '${_roomName}': '${e.message}' `);
|
|
553
585
|
}
|
|
@@ -661,6 +693,8 @@ class BusManager {
|
|
|
661
693
|
console.error(` ...: ${err}. Interrupting process of stopping open stage control instance on port ${_roomId * 1000 + 900}.`);
|
|
662
694
|
}
|
|
663
695
|
console.log(` <- stopped all ports for room ${_roomName}`);
|
|
696
|
+
delete this.rooms[_roomName];
|
|
697
|
+
console.log(` <- removed room ${_roomName}`);
|
|
664
698
|
}else {
|
|
665
699
|
console.log(` ...stopped no ports for room ${_roomName}: no switchboard url/port defined`);
|
|
666
700
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telemersive-bus",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.11",
|
|
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": {
|