@reactoo/watchtogether-sdk-js 2.7.34 → 2.7.35
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
package/src/models/iot.js
CHANGED
|
@@ -31,11 +31,9 @@ let iot = function () {
|
|
|
31
31
|
|
|
32
32
|
onConnect: () => {
|
|
33
33
|
this.__privates.iot.log('MQTT client connected');
|
|
34
|
-
this.iot.setupVisibilityChangeListener();
|
|
35
34
|
},
|
|
36
35
|
onClosed: () => {
|
|
37
36
|
this.__privates.iot.log('MQTT client closed');
|
|
38
|
-
this.iot.disableVisibilityChangeListener();
|
|
39
37
|
},
|
|
40
38
|
onError: () => {
|
|
41
39
|
this.__privates.iot.log('MQTT client error');
|
|
@@ -80,6 +78,7 @@ let iot = function () {
|
|
|
80
78
|
let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
|
|
81
79
|
__currentTopics.clear();
|
|
82
80
|
|
|
81
|
+
this.iot.setupVisibilityChangeListener();
|
|
83
82
|
this.iot.$on('connect', this.iot.onConnect, this);
|
|
84
83
|
this.iot.$on('closed', this.iot.onClosed, this);
|
|
85
84
|
this.iot.$on('error', this.iot.onError, this);
|
|
@@ -116,6 +115,7 @@ let iot = function () {
|
|
|
116
115
|
return this.__privates.iot.disconnect()
|
|
117
116
|
.then(() => {
|
|
118
117
|
|
|
118
|
+
this.iot.disableVisibilityChangeListener();
|
|
119
119
|
this.iot.$off('connect', this.iot.onConnect, this);
|
|
120
120
|
this.iot.$off('closed', this.iot.onClosed, this);
|
|
121
121
|
this.iot.$off('error', this.iot.onError, this);
|
package/src/modules/wt-iot.js
CHANGED
|
@@ -6,7 +6,6 @@ class Iot {
|
|
|
6
6
|
constructor(enableDebugFlag) {
|
|
7
7
|
Object.assign(this, emitter());
|
|
8
8
|
this.decoder = new TextDecoder('utf-8');
|
|
9
|
-
this.connectionActive = false;
|
|
10
9
|
this.log = Iot.noop;
|
|
11
10
|
// Remove: this.debugFlag = enableDebugFlag;
|
|
12
11
|
this.credentialsExpirationCheckIntervalId = null;
|
|
@@ -50,32 +49,26 @@ class Iot {
|
|
|
50
49
|
this.connection = client.new_connection(config);
|
|
51
50
|
|
|
52
51
|
this.connection.on('connect', () => {
|
|
53
|
-
this.connectionActive = true;
|
|
54
52
|
this.emit('connect');
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
this.connection.on('closed', (error) => {
|
|
58
|
-
this.connectionActive = false;
|
|
59
56
|
this.emit('closed', error);
|
|
60
57
|
});
|
|
61
58
|
|
|
62
59
|
this.connection.on('disconnect', () => {
|
|
63
|
-
this.connectionActive = false;
|
|
64
60
|
this.emit('disconnect');
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
this.connection.on('error', (error) => {
|
|
68
|
-
this.connectionActive = false;
|
|
69
64
|
this.emit('error', error);
|
|
70
65
|
});
|
|
71
66
|
|
|
72
67
|
this.connection.on('interrupt', (error) => {
|
|
73
|
-
this.connectionActive = false;
|
|
74
68
|
this.emit('interrupt', error);
|
|
75
69
|
});
|
|
76
70
|
|
|
77
71
|
this.connection.on('resume', (error) => {
|
|
78
|
-
this.connectionActive = true;
|
|
79
72
|
this.emit('resume', error);
|
|
80
73
|
});
|
|
81
74
|
|
|
@@ -84,12 +77,10 @@ class Iot {
|
|
|
84
77
|
});
|
|
85
78
|
|
|
86
79
|
this.connection.on('connection_success', (error) => {
|
|
87
|
-
this.connectionActive = true;
|
|
88
80
|
this.emit('connection_success', error);
|
|
89
81
|
});
|
|
90
82
|
|
|
91
83
|
this.connection.on('connection_failure', (error) => {
|
|
92
|
-
this.connectionActive = false;
|
|
93
84
|
this.emit('connection_failure', error);
|
|
94
85
|
});
|
|
95
86
|
|
|
@@ -106,13 +97,12 @@ class Iot {
|
|
|
106
97
|
this.log('iot disconnect');
|
|
107
98
|
this.stopCredentialsExpirationCheck();
|
|
108
99
|
if (this.connection) {
|
|
109
|
-
this.connectionActive = false;
|
|
110
100
|
return this.connection.disconnect();
|
|
111
101
|
} else return Promise.resolve();
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
isConnected() {
|
|
115
|
-
return this.
|
|
105
|
+
return this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0;
|
|
116
106
|
}
|
|
117
107
|
|
|
118
108
|
subscribe(topic) {
|
|
@@ -245,7 +235,8 @@ class Iot {
|
|
|
245
235
|
this.currentCredentialsExpirationStamp = new Date(expiration).getTime();
|
|
246
236
|
this.credentialsExpirationCheckIntervalId = setInterval(() => {
|
|
247
237
|
const currentTimeStamp = new Date().getTime();
|
|
248
|
-
|
|
238
|
+
// update 15 minutes before expiration
|
|
239
|
+
if(this.currentCredentialsExpirationStamp - currentTimeStamp <= 900000) {
|
|
249
240
|
this.emit('updateCredentials');
|
|
250
241
|
}
|
|
251
242
|
}, 5000);
|
|
@@ -279,7 +270,7 @@ class Iot {
|
|
|
279
270
|
|
|
280
271
|
checkConnection() {
|
|
281
272
|
return new Promise((resolve, reject) => {
|
|
282
|
-
if (!this.connection || !this.
|
|
273
|
+
if (!this.connection || !(this.connection.currentState === 0 && this.connection.desiredState === 0)) {
|
|
283
274
|
reject(new Error('Not connected'));
|
|
284
275
|
return;
|
|
285
276
|
}
|