telemersive-bus 0.6.1 → 0.6.3
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 +24 -20
- package/package.json +1 -1
package/lib/BusManager.js
CHANGED
|
@@ -121,6 +121,7 @@ class BusManager {
|
|
|
121
121
|
startHousekeeping = async () => {
|
|
122
122
|
// we dont want to start another housekeeping process until the previous one has finished
|
|
123
123
|
if(!this.houseKeepingInProgress){
|
|
124
|
+
this.houseKeepingInProgress = true;
|
|
124
125
|
console.log(` -> starting housekeeping -> gather all peers ...`);
|
|
125
126
|
this.peerHousekeep = {};
|
|
126
127
|
this.roomHousekeep = Object.assign({}, this.rooms); // clone the current room list
|
|
@@ -130,7 +131,6 @@ class BusManager {
|
|
|
130
131
|
|
|
131
132
|
// now we have to wait a moment
|
|
132
133
|
setTimeout(this.pingAllPeersAlive, houseKeepingTimeOut);
|
|
133
|
-
this.houseKeepingInProgress = true;
|
|
134
134
|
} else {
|
|
135
135
|
// if there is already a housekeeping going on,
|
|
136
136
|
// we wait for some time to finish it and try again.
|
|
@@ -214,7 +214,7 @@ class BusManager {
|
|
|
214
214
|
delete this.peerHousekeep[_message.peerId];
|
|
215
215
|
} else {
|
|
216
216
|
// this peer seems to be still alive and thinks it is joined.
|
|
217
|
-
// we need to
|
|
217
|
+
// we need to relieve it from its misery and allow it to leave
|
|
218
218
|
// gracefully..
|
|
219
219
|
console.log(` -> peer '${_message.peerName}' not joined anymore - reject from room`);
|
|
220
220
|
await this.publishRoomAccess(
|
|
@@ -228,6 +228,8 @@ class BusManager {
|
|
|
228
228
|
_message.roomPwd,
|
|
229
229
|
"not joined anymore");
|
|
230
230
|
}
|
|
231
|
+
// if even one peer replies to the room ping,
|
|
232
|
+
// the room can be removed from this list
|
|
231
233
|
if (this.roomHousekeep[_message.roomName] !== null) {
|
|
232
234
|
delete this.roomHousekeep[_message.roomName];
|
|
233
235
|
}
|
|
@@ -238,13 +240,14 @@ class BusManager {
|
|
|
238
240
|
*/
|
|
239
241
|
cleanOut = async () => {
|
|
240
242
|
if(this.houseKeepingInProgress) {
|
|
243
|
+
this.houseKeepingInProgress = false;
|
|
241
244
|
console.log(` -> housekeeping -> cleaning out ...`);
|
|
242
|
-
|
|
243
|
-
// all the peer joined addresses that have not replied:
|
|
244
|
-
const clearRetain = async (currentPeer) => {
|
|
245
|
+
const cleanupAndLeave = async (currentPeer) => {
|
|
245
246
|
console.log(` <- remove peer '${currentPeer.peerName}' from room '${currentPeer.roomName}' `);
|
|
247
|
+
// first we send clear retain message to peer joined addresses that have not replied:
|
|
246
248
|
await this.communicator.clearRetain(this.busTopics.roomPeerJoin(currentPeer.roomName, currentPeer.peerId).build());
|
|
247
|
-
|
|
249
|
+
|
|
250
|
+
// create the payload for the leave message
|
|
248
251
|
const infoPayload = {
|
|
249
252
|
timestamp: Math.round(new Date().getTime() / 1000),
|
|
250
253
|
peerId: currentPeer.peerId,
|
|
@@ -256,9 +259,9 @@ class BusManager {
|
|
|
256
259
|
await this.communicator.publish(
|
|
257
260
|
new BusMsgPub(
|
|
258
261
|
this.busTopics.roomPeerLeft(currentPeer.roomName, currentPeer.peerId).build(),
|
|
259
|
-
PeerInfo, 2,
|
|
262
|
+
PeerInfo, 2, true).encode(infoPayload));
|
|
260
263
|
}
|
|
261
|
-
await Object.values(this.peerHousekeep).every(
|
|
264
|
+
await Object.values(this.peerHousekeep).every(cleanupAndLeave);
|
|
262
265
|
|
|
263
266
|
// and now we can delete the rooms
|
|
264
267
|
const cleanupRooms = async (currentRoom) => await this.deleteRoom(currentRoom.roomName);
|
|
@@ -275,8 +278,6 @@ class BusManager {
|
|
|
275
278
|
await this.communicator.unsubscribe(this.busTopics.baseRoomAlivePing("+").build());
|
|
276
279
|
// cleanup the communicator
|
|
277
280
|
this.communicator.clearAutoGeneratedSubscriptions();
|
|
278
|
-
// and just to be sure
|
|
279
|
-
this.houseKeepingInProgress = false;
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
/**
|
|
@@ -345,15 +346,16 @@ class BusManager {
|
|
|
345
346
|
} else {
|
|
346
347
|
//room exists: checked if the doubled hashed roomPwd is equal
|
|
347
348
|
accessGrant = true;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
349
|
+
console.log(` -> peer '${_message.peerName}' joining room '${_message.roomName}'`);
|
|
350
|
+
// if there is a housekeeping process in progress,
|
|
351
|
+
// we need it to stop it right here, otherwise the newly joined peer could be
|
|
352
|
+
// kicked out right away.
|
|
353
|
+
if (this.houseKeepingInProgress) {
|
|
354
|
+
console.log(` -> peer '${_message.peerName}' joining interrupts housekeeping.. `);
|
|
352
355
|
this.houseKeepingInProgress = false;
|
|
353
|
-
// and we wait a moment to start with housekeeping again
|
|
354
|
-
setTimeout(this.startHousekeeping, houseKeepingTimeOut_onPeerJoined);
|
|
355
356
|
}
|
|
356
|
-
|
|
357
|
+
// and we wait a moment to start with housekeeping again
|
|
358
|
+
setTimeout(this.startHousekeeping, houseKeepingTimeOut_onPeerJoined);
|
|
357
359
|
}
|
|
358
360
|
}
|
|
359
361
|
} else {
|
|
@@ -362,8 +364,7 @@ class BusManager {
|
|
|
362
364
|
reason = `incompatible protocol version '${_message.protocolVersion}': room manager is running on tBus version '${this.protocolVersion}'` ;
|
|
363
365
|
}
|
|
364
366
|
|
|
365
|
-
//
|
|
366
|
-
// send access message
|
|
367
|
+
// send access message to peer only
|
|
367
368
|
await this.publishRoomAccess(
|
|
368
369
|
accessGrant,
|
|
369
370
|
_message.peerId,
|
|
@@ -376,7 +377,9 @@ class BusManager {
|
|
|
376
377
|
reason)
|
|
377
378
|
|
|
378
379
|
if(accessGrant){
|
|
379
|
-
//
|
|
380
|
+
// This sends a message to all peers joined to the room
|
|
381
|
+
// first clear potentially retained leave message
|
|
382
|
+
await this.communicator.clearRetain(this.busTopics.roomPeerLeft(_message.roomName, _message.peerId).build());
|
|
380
383
|
// send peer joined message to all the peers in the room
|
|
381
384
|
await this.communicator.publish(
|
|
382
385
|
new BusMsgPub(
|
|
@@ -392,6 +395,7 @@ class BusManager {
|
|
|
392
395
|
}
|
|
393
396
|
};
|
|
394
397
|
|
|
398
|
+
// This generates a message to the requesting peer only
|
|
395
399
|
publishRoomAccess = async (_accessGranted, _peerId, _clientId, _peerName, _roomName, _roomId, _roomUuid, _roomPwd, _reason) => {
|
|
396
400
|
await this.communicator.publish(
|
|
397
401
|
new BusMsgPub(this.busTopics.basePeerRoomAccess(_clientId).build(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telemersive-bus",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
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": {
|