@folklore/socket 0.4.19 → 0.4.21

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/dist/cjs.js CHANGED
@@ -336,7 +336,7 @@ class SocketIOSocket extends EventEmitter {
336
336
  }
337
337
 
338
338
  const debug$1 = createDebug('folklore:socket:pusher');
339
- class PusherSocker extends EventEmitter {
339
+ class PusherSocket extends EventEmitter {
340
340
  constructor(opts) {
341
341
  super();
342
342
  this.options = {
@@ -404,7 +404,7 @@ class PusherSocker extends EventEmitter {
404
404
  loadPusher.then(() => this.createPusher()).then(() => this.onReady());
405
405
  }
406
406
  loadPusher() {
407
- debug$1('Load PusherJs');
407
+ debug$1('Load Pusher');
408
408
  return import('pusher-js').then(_ref => {
409
409
  let {
410
410
  default: Pusher
@@ -416,6 +416,7 @@ class PusherSocker extends EventEmitter {
416
416
  if (this.destroyed) {
417
417
  return;
418
418
  }
419
+ debug$1('Create Pusher appKey: %s', this.options.appKey);
419
420
  const {
420
421
  Pusher
421
422
  } = this;
@@ -442,7 +443,7 @@ class PusherSocker extends EventEmitter {
442
443
  debug$1('Skipping start: Already starting.');
443
444
  return;
444
445
  }
445
- if (this.io === null) {
446
+ if (this.pusher === null) {
446
447
  debug$1('Socket.io not ready.');
447
448
  this.shouldStart = true;
448
449
  return;
@@ -506,7 +507,7 @@ class PusherSocker extends EventEmitter {
506
507
  var SocketAdapters = {
507
508
  PubNub: PubNubSocket,
508
509
  SocketIO: SocketIOSocket,
509
- Pusher: PusherSocker
510
+ Pusher: PusherSocket
510
511
  };
511
512
 
512
513
  const normalize = str => str.replace(/[^a-z0-9]+/gi, '').toLowerCase();
@@ -883,7 +884,8 @@ const useSocket = function () {
883
884
  let channelNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
884
885
  let {
885
886
  socket: customSocket = null,
886
- onMessage: customOnMessage = null
887
+ onMessage: customOnMessage = null,
888
+ keepAlive = true
887
889
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
888
890
  const {
889
891
  socket: contextSocket,
@@ -918,11 +920,11 @@ const useSocket = function () {
918
920
  if (channels !== null) {
919
921
  unsubscribe(channels);
920
922
  }
921
- if (!wasStarted) {
923
+ if (socket.isStarted() && !keepAlive) {
922
924
  socket.stop();
923
925
  }
924
926
  };
925
- }, [channelsKey, customSocket]);
927
+ }, [channelsKey, customSocket, keepAlive]);
926
928
  React.useEffect(() => {
927
929
  if (socket === null) {
928
930
  return () => {};
package/dist/es.js CHANGED
@@ -332,7 +332,7 @@ class SocketIOSocket extends EventEmitter {
332
332
  }
333
333
 
334
334
  const debug$1 = createDebug('folklore:socket:pusher');
335
- class PusherSocker extends EventEmitter {
335
+ class PusherSocket extends EventEmitter {
336
336
  constructor(opts) {
337
337
  super();
338
338
  this.options = {
@@ -400,7 +400,7 @@ class PusherSocker extends EventEmitter {
400
400
  loadPusher.then(() => this.createPusher()).then(() => this.onReady());
401
401
  }
402
402
  loadPusher() {
403
- debug$1('Load PusherJs');
403
+ debug$1('Load Pusher');
404
404
  return import('pusher-js').then(_ref => {
405
405
  let {
406
406
  default: Pusher
@@ -412,6 +412,7 @@ class PusherSocker extends EventEmitter {
412
412
  if (this.destroyed) {
413
413
  return;
414
414
  }
415
+ debug$1('Create Pusher appKey: %s', this.options.appKey);
415
416
  const {
416
417
  Pusher
417
418
  } = this;
@@ -438,7 +439,7 @@ class PusherSocker extends EventEmitter {
438
439
  debug$1('Skipping start: Already starting.');
439
440
  return;
440
441
  }
441
- if (this.io === null) {
442
+ if (this.pusher === null) {
442
443
  debug$1('Socket.io not ready.');
443
444
  this.shouldStart = true;
444
445
  return;
@@ -502,7 +503,7 @@ class PusherSocker extends EventEmitter {
502
503
  var SocketAdapters = {
503
504
  PubNub: PubNubSocket,
504
505
  SocketIO: SocketIOSocket,
505
- Pusher: PusherSocker
506
+ Pusher: PusherSocket
506
507
  };
507
508
 
508
509
  const normalize = str => str.replace(/[^a-z0-9]+/gi, '').toLowerCase();
@@ -879,7 +880,8 @@ const useSocket = function () {
879
880
  let channelNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
880
881
  let {
881
882
  socket: customSocket = null,
882
- onMessage: customOnMessage = null
883
+ onMessage: customOnMessage = null,
884
+ keepAlive = true
883
885
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
884
886
  const {
885
887
  socket: contextSocket,
@@ -914,11 +916,11 @@ const useSocket = function () {
914
916
  if (channels !== null) {
915
917
  unsubscribe(channels);
916
918
  }
917
- if (!wasStarted) {
919
+ if (socket.isStarted() && !keepAlive) {
918
920
  socket.stop();
919
921
  }
920
922
  };
921
- }, [channelsKey, customSocket]);
923
+ }, [channelsKey, customSocket, keepAlive]);
922
924
  useEffect(() => {
923
925
  if (socket === null) {
924
926
  return () => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/socket",
3
- "version": "0.4.19",
3
+ "version": "0.4.21",
4
4
  "description": "Socket utilities",
5
5
  "keywords": [
6
6
  "javascript",
@@ -56,5 +56,5 @@
56
56
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
57
57
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
58
58
  },
59
- "gitHead": "1f1b7ab751c4497df25a3dda97cd84f793ff720f"
59
+ "gitHead": "f18d843f3ea8b5a84672addc2fcb50dbf8994b58"
60
60
  }