telemersive-bus 0.6.9 → 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 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
@@ -241,7 +241,12 @@ class BusManager {
241
241
  cleanOut = async () => {
242
242
  if(this.houseKeepingInProgress) {
243
243
  console.log(` -> housekeeping -> cleaning out ...`);
244
- const cleanupAndLeave = async (currentPeer) => {
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) => {
245
250
  console.log(` <- remove peer '${currentPeer.peerName}' from room '${currentPeer.roomName}' `);
246
251
  // first we send clear retain message to peer joined addresses that have not replied:
247
252
  await this.communicator.clearRetain(this.busTopics.roomPeerJoin(currentPeer.roomName, currentPeer.peerId).build());
@@ -260,12 +265,22 @@ class BusManager {
260
265
  this.busTopics.roomPeerLeft(currentPeer.roomName, currentPeer.peerId).build(),
261
266
  PeerInfo, 2, true).encode(infoPayload));
262
267
  }
263
- await Object.values(this.peerHousekeep).every(cleanupAndLeave);
264
-
265
- // and now we can delete the rooms
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
266
276
  const cleanupRooms = async (currentRoom) => await this.deleteRoom(currentRoom.roomName);
267
- await Object.values(this.roomHousekeep).every(cleanupRooms);
268
-
277
+ const housekeeping = async () => {
278
+ for (const room of Object.values(this.roomHousekeep)) {
279
+ await cleanupRooms(room);
280
+ }
281
+ };
282
+ await housekeeping();
283
+
269
284
  console.log(` -> housekeeping DONE`);
270
285
  } else {
271
286
  console.log(` -> housekeeping was interrupted`);
@@ -348,6 +363,10 @@ class BusManager {
348
363
  console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | incompatible app version`);
349
364
  accessGrant = false;
350
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.`;
351
370
  } else {
352
371
  accessGrant = true;
353
372
  console.log(` -> peer '${_message.peerName}' joining room '${_message.roomName}'`);
@@ -485,7 +504,8 @@ class BusManager {
485
504
  roomId: roomID,
486
505
  roomUUID: roomUUID,
487
506
  roomPwd: _roomPwd,
488
- appVersion: _appVersion
507
+ appVersion: _appVersion,
508
+ flagRoom4cleanup: false
489
509
  }
490
510
  console.log(`-> generate room: '${_roomName}' with id '${roomID}' and uuid: '${roomID}'`);
491
511
  console.log(` with uuid: '${roomUUID}'`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telemersive-bus",
3
- "version": "0.6.9",
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": {