telemersive-bus 0.6.3 → 0.6.4

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/BusClient.js CHANGED
@@ -65,9 +65,9 @@ class BusClient {
65
65
  this.connectTimeout = setTimeout(this.connectionTimeout,1000);
66
66
  await this.communicator.connect();
67
67
  // if connection was successful, subscribe to room info topic
68
- await this.communicator.subscribe(new BusMsgSub(this.busTopics.baseRoomInfo('+').build(), this.onRooms, RoomInfo, 0));
68
+ await this.communicator.subscribe(new BusMsgSub(this.busTopics.baseRoomInfo('+').build(), this.onRooms, RoomInfo, 2));
69
69
  // if connection was successful, subscribe to room delete topic
70
- await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomDelete().build(), this.onRoomDelete, RoomInfo, 0));
70
+ await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomDelete().build(), this.onRoomDelete, RoomInfo, 2));
71
71
  //console.log(`...subscribe to. ${this.busTopics.basePeerRoomAccess(this.peerId).build()}`);
72
72
  this.bubbleUpCallback('bus', [ 'broker', 'connected', 1]);
73
73
  console.log("...successfully connected.");
@@ -135,7 +135,7 @@ class BusClient {
135
135
  await this.communicator.reconnect(null);
136
136
 
137
137
  // if connection was successful, subscribe to roomAccess topic
138
- await this.communicator.subscribe(new BusMsgSub(this.busTopics.basePeerRoomAccess(this.peer.getClientId()).build(), this.onRoomJoined, RoomAccess, 0));
138
+ await this.communicator.subscribe(new BusMsgSub(this.busTopics.basePeerRoomAccess(this.peer.getClientId()).build(), this.onRoomJoined, RoomAccess, 2));
139
139
 
140
140
  // now we start the timeout thread
141
141
  this.joinTimeout = setTimeout(this.joinedTimeout,5000);
package/lib/BusManager.js CHANGED
@@ -186,7 +186,10 @@ class BusManager {
186
186
  * return messages from peers on room ping requests
187
187
  */
188
188
  onRoomAlive = async (_topic, _message, _packet) => {
189
- console.log(` -> room '${_message.roomName}' alive with peer '${_message.peerName}'`);
189
+ let accessGrant;
190
+ let reason = "unknown";
191
+ console.log(` -> room '${_message.roomName}' alive ping from peer '${_message.peerName}'`);
192
+
190
193
  // if we receive this message, it means this peer is alive and we can remove it
191
194
  // from our housekeeping lists
192
195
  if (_message.peerId in this.peerHousekeep) {
@@ -200,39 +203,36 @@ class BusManager {
200
203
  // now we resend the access message
201
204
  // we need to do this in case the manager has crashed and restarted...
202
205
  // send access message
203
- await this.publishRoomAccess(
204
- true,
205
- _message.peerId,
206
- _message.clientId,
207
- _message.peerName,
208
- _message.roomName,
209
- this.rooms[_message.roomName].roomId,
210
- this.rooms[_message.roomName].roomUUID,
211
- _message.roomPwd,
212
- "confirmation");
206
+ accessGrant = true;
207
+ reason = "confirmation";
208
+ delete this.peerHousekeep[_message.peerId];
209
+
210
+ // if even one joined peer replies to the room ping,
211
+ // the room can be removed from this list
212
+ if (this.roomHousekeep[_message.roomName] !== null) {
213
+ delete this.roomHousekeep[_message.roomName];
214
+ }
213
215
  }
214
- delete this.peerHousekeep[_message.peerId];
215
216
  } else {
216
217
  // this peer seems to be still alive and thinks it is joined.
217
218
  // we need to relieve it from its misery and allow it to leave
218
219
  // gracefully..
220
+ accessGrant = false;
221
+ reason = "not joined anymore";
219
222
  console.log(` -> peer '${_message.peerName}' not joined anymore - reject from room`);
220
- await this.publishRoomAccess(
221
- false,
222
- _message.peerId,
223
- _message.clientId,
224
- _message.peerName,
225
- _message.roomName,
226
- this.rooms[_message.roomName].roomId,
227
- this.rooms[_message.roomName].roomUUID,
228
- _message.roomPwd,
229
- "not joined anymore");
230
- }
231
- // if even one peer replies to the room ping,
232
- // the room can be removed from this list
233
- if (this.roomHousekeep[_message.roomName] !== null) {
234
- delete this.roomHousekeep[_message.roomName];
235
223
  }
224
+
225
+ await this.publishRoomAccess(
226
+ accessGrant,
227
+ _message.peerId,
228
+ _message.clientId,
229
+ _message.peerName,
230
+ _message.roomName,
231
+ this.rooms[_message.roomName].roomId,
232
+ this.rooms[_message.roomName].roomUUID,
233
+ _message.roomPwd,
234
+ reason);
235
+
236
236
  };
237
237
 
238
238
  /**
@@ -286,21 +286,18 @@ class BusManager {
286
286
  onPeerLeaving = async (_topic, _message, _packet) => {
287
287
  console.log(` <- peer '${_message.peerName}' leaving`);
288
288
  let shaPassword = sha1(_message.roomPwd).substr(0, 10)
289
- if (this.rooms.hasOwnProperty(_message.roomName)){
290
- if (this.rooms[_message.roomName].roomPwd === shaPassword){
291
- // the actual message of this peer leaving the room is generated by the
292
- // housekeeping routine 'cleanOut':
293
- // we wait a moment to start with housekeeping, though.
294
- // it could be, that this message was called due to a short disconnect by the
295
- // peer to the broker - issuing a lastWill message by the broker.
296
- // by giving it some time the housekeeping process will verify if the peer
297
- // is still online or if it is really gone..
298
- setTimeout(this.startHousekeeping, houseKeepingTimeOut_onPeerLeft);
299
- } else {
300
- console.log(`!!! >BAD PLAYER<: somebody tried to remove peer without proper credentials!!!`);
301
- }
289
+ if (this.rooms[_message.roomName].roomPwd === shaPassword){
290
+ // the actual message of this peer leaving the room is generated by the
291
+ // housekeeping routine 'cleanOut':
292
+ // we wait a moment to start with housekeeping, though.
293
+ // it could be, that this message was called due to a short disconnect by the
294
+ // peer to the broker - issuing a lastWill message by the broker.
295
+ // by giving it some time the housekeeping process will verify if the peer
296
+ // is still online or if it is really gone..
297
+ setTimeout(this.startHousekeeping, houseKeepingTimeOut_onPeerLeft);
298
+ } else {
299
+ console.log(`!!! >BAD PLAYER<: somebody tried to remove peer without proper credentials!!!`);
302
300
  }
303
-
304
301
  };
305
302
 
306
303
  /*********************************************************************
@@ -334,7 +331,10 @@ class BusManager {
334
331
  console.log(` -> peer '${_message.peerName}' creating new room '${_message.roomName}' for app version: '${_message.appVersion}'`);
335
332
  reason = "no room of this name exists";
336
333
  await this.publishNewRoom(_message.roomName, shaPassword, _message.appVersion);
334
+ // and we wait a moment to start with housekeeping again
335
+ setTimeout(this.startHousekeeping, houseKeepingTimeOut_onPeerJoined);
337
336
  } else {
337
+ //room exists: checked if the doubled hashed roomPwd is equal
338
338
  if (this.rooms[_message.roomName].roomPwd !== shaPassword) {
339
339
  console.log(` -> peer '${_message.peerName}' declined access to room: ${_message.roomName} | invalid password`);
340
340
  accessGrant = false;
@@ -344,7 +344,6 @@ class BusManager {
344
344
  accessGrant = false;
345
345
  reason = `app version incompatible: required version is '${this.rooms[_message.roomName].appVersion}', yours is '${_message.appVersion}'`;
346
346
  } else {
347
- //room exists: checked if the doubled hashed roomPwd is equal
348
347
  accessGrant = true;
349
348
  console.log(` -> peer '${_message.peerName}' joining room '${_message.roomName}'`);
350
349
  // if there is a housekeeping process in progress,
package/lib/utils/Peer.js CHANGED
@@ -193,10 +193,10 @@ class Peer {
193
193
 
194
194
  // it is important to start the subscription after a successfull joining.
195
195
  // subscribe to all peer joined messages
196
- await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomPeerJoin(this.roomName, '+').build(), this.onPeerJoined, PeerInfo, 0));
196
+ await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomPeerJoin(this.roomName, '+').build(), this.onPeerJoined, PeerInfo, 2));
197
197
 
198
198
  // subscribe to peer left messages
199
- await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomPeerLeft(this.roomName, '+').build(), this.onPeerLeft, PeerInfo, 0));
199
+ await this.communicator.subscribe(new BusMsgSub(this.busTopics.roomPeerLeft(this.roomName, '+').build(), this.onPeerLeft, PeerInfo, 2));
200
200
 
201
201
  // subscribe to my room ping messages
202
202
  await this.communicator.subscribe(new BusMsgSub(this.busTopics.baseRoomAlive(this.roomName).build(), this.onRoomPing, RoomInfo, 0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telemersive-bus",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
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": {