@reactoo/watchtogether-sdk-js 2.7.32 → 2.7.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.32",
3
+ "version": "2.7.34",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
package/src/models/iot.js CHANGED
@@ -28,6 +28,33 @@ let iot = function () {
28
28
  .then(client => client.apis.auth.iotSignIn({}, {requestBody: {suggestedTopics:true, domain: location.hostname}}))
29
29
 
30
30
  },
31
+
32
+ onConnect: () => {
33
+ this.__privates.iot.log('MQTT client connected');
34
+ this.iot.setupVisibilityChangeListener();
35
+ },
36
+ onClosed: () => {
37
+ this.__privates.iot.log('MQTT client closed');
38
+ this.iot.disableVisibilityChangeListener();
39
+ },
40
+ onError: () => {
41
+ this.__privates.iot.log('MQTT client error');
42
+ },
43
+ onDisconnect: () => {
44
+ this.__privates.iot.log('MQTT client disconnect');
45
+ },
46
+ onInterrupt: () => {
47
+ this.__privates.iot.log('MQTT client interrupt');
48
+ },
49
+ onResume: () => {
50
+ this.__privates.iot.log('MQTT client resume');
51
+ },
52
+ onConnectionSuccess: () => {
53
+ this.__privates.iot.log('MQTT client connection_success');
54
+ },
55
+ onConnectionFailure: () => {
56
+ this.__privates.iot.log('MQTT client connection_failure');
57
+ },
31
58
 
32
59
  iotLogin: (subscribeToSuggestedTopics = true) => {
33
60
  this.iot.__promise = new Promise((resolve, reject) => {
@@ -53,39 +80,14 @@ let iot = function () {
53
80
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
54
81
  __currentTopics.clear();
55
82
 
56
- this.iot.$on('connect', () => {
57
- this.__privates.iot.log('MQTT client connected');
58
- this.iot.setupVisibilityChangeListener();
59
- });
60
-
61
- this.iot.$on('closed', () => {
62
- this.__privates.iot.log('MQTT client closed');
63
- this.iot.disableVisibilityChangeListener();
64
- });
65
-
66
- this.iot.$on('error', () => {
67
- this.__privates.iot.log('MQTT client error');
68
- });
69
-
70
- this.iot.$on('disconnect', () => {
71
- this.__privates.iot.log('MQTT client disconnect');
72
- });
73
-
74
- this.iot.$on('interrupt', () => {
75
- this.__privates.iot.log('MQTT client interrupt');
76
- });
77
-
78
- this.iot.$on('resume', () => {
79
- this.__privates.iot.log('MQTT client resume');
80
- });
81
-
82
- this.iot.$on('connection_success', () => {
83
- this.__privates.iot.log('MQTT client connection_success');
84
- });
85
-
86
- this.iot.$on('connection_failure', () => {
87
- this.__privates.iot.log('MQTT client connection_failure');
88
- });
83
+ this.iot.$on('connect', this.iot.onConnect, this);
84
+ this.iot.$on('closed', this.iot.onClosed, this);
85
+ this.iot.$on('error', this.iot.onError, this);
86
+ this.iot.$on('disconnect', this.iot.onDisconnect, this);
87
+ this.iot.$on('interrupt', this.iot.onInterrupt, this);
88
+ this.iot.$on('resume', this.iot.onResume, this);
89
+ this.iot.$on('connection_success', this.iot.onConnectionSuccess, this);
90
+ this.iot.$on('connection_failure', this.iot.onConnectionFailure, this);
89
91
 
90
92
  this.iot.__promise
91
93
  .then(([suggestedTopic, instance]) => {
@@ -113,8 +115,17 @@ let iot = function () {
113
115
  }
114
116
  return this.__privates.iot.disconnect()
115
117
  .then(() => {
118
+
119
+ this.iot.$off('connect', this.iot.onConnect, this);
120
+ this.iot.$off('closed', this.iot.onClosed, this);
121
+ this.iot.$off('error', this.iot.onError, this);
122
+ this.iot.$off('disconnect', this.iot.onDisconnect, this);
123
+ this.iot.$off('interrupt', this.iot.onInterrupt, this);
124
+ this.iot.$off('resume', this.iot.onResume, this);
125
+ this.iot.$off('connection_success', this.iot.onConnectionSuccess, this);
126
+ this.iot.$off('connection_failure', this.iot.onConnectionFailure, this);
127
+
116
128
  this.iot.__promise = null;
117
- this.iot.$clear();
118
129
  return true;
119
130
  });
120
131
  },
@@ -54,6 +54,11 @@ class Iot {
54
54
  this.emit('connect');
55
55
  });
56
56
 
57
+ this.connection.on('closed', (error) => {
58
+ this.connectionActive = false;
59
+ this.emit('closed', error);
60
+ });
61
+
57
62
  this.connection.on('disconnect', () => {
58
63
  this.connectionActive = false;
59
64
  this.emit('disconnect');
@@ -88,11 +93,6 @@ class Iot {
88
93
  this.emit('connection_failure', error);
89
94
  });
90
95
 
91
- this.connection.on('closed', (error) => {
92
- this.connectionActive = false;
93
- this.emit('closed', error);
94
- });
95
-
96
96
  return this.connection.connect()
97
97
  .then(() => {
98
98
  this.startCredentialsExpirationCheck(expiration);