@reactoo/watchtogether-sdk-js 2.6.12 → 2.6.13
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/watchtogether-sdk.js +223 -323
- package/dist/watchtogether-sdk.min.js +2 -2
- package/package.json +1 -1
- package/src/models/iot.js +10 -4
- package/src/modules/wt-iot.js +11 -1
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -49,10 +49,16 @@ let iot = function () {
|
|
|
49
49
|
__currentTopics.length = 0;
|
|
50
50
|
|
|
51
51
|
this.iot.__promise
|
|
52
|
-
.then(([suggestedTopic, instance]) =>
|
|
53
|
-
|
|
54
|
-
Promise.resolve(instance)
|
|
55
|
-
|
|
52
|
+
.then(([suggestedTopic, instance]) => {
|
|
53
|
+
if(!subscribeToSuggestedTopics) {
|
|
54
|
+
return Promise.resolve(instance)
|
|
55
|
+
}
|
|
56
|
+
const topics = [...suggestedTopic, ...__currentTopicsCopy];
|
|
57
|
+
__currentTopics = topics.filter((c, index) => {
|
|
58
|
+
return topics.indexOf(c) !== index;
|
|
59
|
+
});
|
|
60
|
+
return Promise.all(__currentTopics.map(topic => this.iot.subscribe(topic))).then(() => instance)
|
|
61
|
+
})
|
|
56
62
|
.then((instance) => {
|
|
57
63
|
this.iot.$on('error', this.iot.__reconnect, this);
|
|
58
64
|
this.iot.$on('updateCredentials', this.iot.__updateCredentials, this);
|
package/src/modules/wt-iot.js
CHANGED
|
@@ -42,6 +42,7 @@ class Iot {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
updateWebSocketCredentials(accessKeyId, secretAccessKey, sessionToken, expiration) {
|
|
45
|
+
this.log('iot updateWebSocketCredentials');
|
|
45
46
|
if(this.device) {
|
|
46
47
|
this.device.updateWebSocketCredentials(accessKeyId, secretAccessKey, sessionToken);
|
|
47
48
|
this.startCredentialsExpirationCheck(expiration);
|
|
@@ -49,6 +50,7 @@ class Iot {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration, forceDisconnect = false) {
|
|
53
|
+
this.log('iot connect');
|
|
52
54
|
return this.disconnect(forceDisconnect).then(() => {
|
|
53
55
|
return new Promise((resolve, reject) => {
|
|
54
56
|
this.device = device({
|
|
@@ -59,7 +61,7 @@ class Iot {
|
|
|
59
61
|
accessKeyId: accessKeyId,
|
|
60
62
|
secretKey: secretAccessKey,
|
|
61
63
|
sessionToken: sessionToken,
|
|
62
|
-
keepalive:
|
|
64
|
+
keepalive: 30,
|
|
63
65
|
maximumReconnectTimeMs: 8000,
|
|
64
66
|
enableMetrics: false,
|
|
65
67
|
debug: this.debugFlag,
|
|
@@ -126,33 +128,41 @@ class Iot {
|
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
subscribe(topic) {
|
|
131
|
+
this.log('iot subscribe', topic);
|
|
129
132
|
return this.device && this.device.subscribe(topic);
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
unsubscribe(topic) {
|
|
136
|
+
this.log('iot unsubscribe', topic);
|
|
133
137
|
return this.device && this.device.unsubscribe(topic);
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
send(topic, message) {
|
|
141
|
+
this.log('iot send', topic, message);
|
|
137
142
|
let msg = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
138
143
|
return this.device && this.device.publish(topic, msg);
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
__reconnectCb() {
|
|
147
|
+
this.log('iot reconnect');
|
|
142
148
|
this.emit('reconnect');
|
|
143
149
|
}
|
|
144
150
|
__connectCb() {
|
|
151
|
+
this.log('iot connect');
|
|
145
152
|
this.connectionActive = true;
|
|
146
153
|
this.emit('connect');
|
|
147
154
|
}
|
|
148
155
|
__failureCb(err) {
|
|
156
|
+
this.log('iot failure');
|
|
149
157
|
this.emit('error', err);
|
|
150
158
|
}
|
|
151
159
|
__closeCb(responseObject) {
|
|
160
|
+
this.log('iot close');
|
|
152
161
|
this.connectionActive = false;
|
|
153
162
|
this.emit('close');
|
|
154
163
|
}
|
|
155
164
|
__offlineCb(responseObject) {
|
|
165
|
+
this.log('iot offline');
|
|
156
166
|
this.emit('offline');
|
|
157
167
|
}
|
|
158
168
|
|