homey-api 3.1.0 → 3.2.0

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.
@@ -638,7 +638,17 @@ class HomeyAPIV3 extends HomeyAPI {
638
638
  };
639
639
  }
640
640
 
641
- async connect() {
641
+ async connect({
642
+ onDisconnect = () => {},
643
+ onError = () => {},
644
+ onReconnect = () => {},
645
+ onReconnectAttempt = () => {},
646
+ onReconnecting = () => {},
647
+ onReconnectError = () => {},
648
+ onConnect = () => {},
649
+ onConnectError = () => {},
650
+ reconnect = true
651
+ } = {}) {
642
652
  if (!this.__connectPromise) {
643
653
  this.__connectPromise = Promise.resolve().then(async () => {
644
654
  // Ensure Base URL
@@ -657,40 +667,48 @@ class HomeyAPIV3 extends HomeyAPI {
657
667
  pingTimeout: 8000,
658
668
  pingInterval: 5000,
659
669
  },
660
- reconnection: true,
670
+ reconnection: reconnect,
661
671
  });
662
672
 
663
673
  this.__socket.on('disconnect', reason => {
664
674
  this.__debug('SocketIOClient.onDisconnect', reason);
675
+ onDisconnect(reason);
665
676
  });
666
677
 
667
678
  this.__socket.on('error', err => {
668
679
  this.__debug('SocketIOClient.onError', err.message);
680
+ onError(err);
669
681
  });
670
682
 
671
683
  this.__socket.on('reconnect', () => {
672
684
  this.__debug('SocketIOClient.onReconnect');
685
+ onReconnect();
673
686
  });
674
687
 
675
688
  this.__socket.on('reconnect_attempt', () => {
676
689
  this.__debug(`SocketIOClient.onReconnectAttempt`);
690
+ onReconnectAttempt();
677
691
  });
678
692
 
679
693
  this.__socket.on('reconnecting', attempt => {
680
694
  this.__debug(`SocketIOClient.onReconnecting (Attempt #${attempt})`);
695
+ onReconnecting(attempt);
681
696
  });
682
697
 
683
698
  this.__socket.on('reconnect_error', err => {
684
- this.__debug('SocketIOClient.onReconnectError', err.message);
699
+ this.__debug('SocketIOClient.onReconnectError', err.message, err);
700
+ onReconnectError(err);
685
701
  });
686
702
 
687
703
  this.__socket.on('connect_error', err => {
688
704
  this.__debug('SocketIOClient.onConnectError', err.message);
705
+ onConnectError(err);
689
706
  reject(err);
690
707
  });
691
708
 
692
709
  this.__socket.on('connect', () => {
693
710
  this.__debug('SocketIOClient.onConnect');
711
+ onConnect();
694
712
  this.__handshakeClient()
695
713
  .then(() => {
696
714
  this.__debug('SocketIOClient.onConnect.onHandshakeClientSuccess');
@@ -722,8 +740,12 @@ class HomeyAPIV3 extends HomeyAPI {
722
740
 
723
741
  if (this.__socket) {
724
742
  await new Promise(resolve => {
725
- this.__socket.once('disconnect', () => resolve());
726
- this.__socket.disconnect();
743
+ if (this.__socket.connected) {
744
+ this.__socket.once('disconnect', () => resolve());
745
+ this.__socket.disconnect();
746
+ } else {
747
+ resolve();
748
+ }
727
749
  this.__socket.removeAllListeners();
728
750
  this.__socket = null;
729
751
  });
package/lib/Util.js CHANGED
@@ -93,6 +93,7 @@ class Util {
93
93
  * @returns {boolean}
94
94
  */
95
95
  static isHTTPUnsecureSupported() {
96
+ if (this.isReactNative()) return true;
96
97
  if (typeof window === 'undefined') return true;
97
98
  if (typeof window.location === 'undefined') return false;
98
99
  return window.location.protocol === 'http:';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [