@reactoo/watchtogether-sdk-js 2.7.43 → 2.7.44-beta.1
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 +52 -20
- package/dist/watchtogether-sdk.js.map +1 -1
- package/dist/watchtogether-sdk.min.js +2 -2
- package/package.json +1 -1
- package/src/models/iot.js +24 -11
- package/src/modules/wt-iot.js +14 -6
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -107,12 +107,9 @@ let iot = function () {
|
|
|
107
107
|
.then(resolve)
|
|
108
108
|
.catch(reject)
|
|
109
109
|
});
|
|
110
|
-
|
|
111
|
-
let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
|
|
110
|
+
|
|
112
111
|
__currentTopics.clear();
|
|
113
112
|
|
|
114
|
-
this.iot.setupVisibilityChangeListener();
|
|
115
|
-
this.iot.setupKeepAliveInterval();
|
|
116
113
|
this.iot.$on('connect', this.iot.onConnect, this);
|
|
117
114
|
this.iot.$on('closed', this.iot.onClosed, this);
|
|
118
115
|
this.iot.$on('error', this.iot.onError, this);
|
|
@@ -128,9 +125,14 @@ let iot = function () {
|
|
|
128
125
|
if(!subscribeToSuggestedTopics) {
|
|
129
126
|
return Promise.resolve(instance)
|
|
130
127
|
}
|
|
131
|
-
let topics = new Set([...suggestedTopic
|
|
128
|
+
let topics = new Set([...suggestedTopic]); // Filter out any undefined or null topics
|
|
132
129
|
return Promise.all(Array.from(topics).map(topic => this.iot.subscribe(topic))).then(() => instance)
|
|
133
130
|
})
|
|
131
|
+
.then((instance) => {
|
|
132
|
+
this.iot.setupVisibilityChangeListener();
|
|
133
|
+
this.iot.setupKeepAliveInterval();
|
|
134
|
+
return instance;
|
|
135
|
+
})
|
|
134
136
|
.catch((error) => {
|
|
135
137
|
this.__privates.iot.log('MQTT Login Error:', error);
|
|
136
138
|
throw error;
|
|
@@ -148,10 +150,11 @@ let iot = function () {
|
|
|
148
150
|
interruptCount = 0;
|
|
149
151
|
shouldBeConnected = false;
|
|
150
152
|
|
|
153
|
+
this.iot.disableVisibilityChangeListener();
|
|
154
|
+
this.iot.disableKeepAliveInterval();
|
|
155
|
+
|
|
151
156
|
return this.__privates.iot.disconnect()
|
|
152
157
|
.then(() => {
|
|
153
|
-
this.iot.disableVisibilityChangeListener();
|
|
154
|
-
this.iot.disableKeepAliveInterval();
|
|
155
158
|
this.iot.$off('connect', this.iot.onConnect, this);
|
|
156
159
|
this.iot.$off('closed', this.iot.onClosed, this);
|
|
157
160
|
this.iot.$off('error', this.iot.onError, this);
|
|
@@ -174,17 +177,27 @@ let iot = function () {
|
|
|
174
177
|
subscribe: (topic) => {
|
|
175
178
|
if(!__currentTopics.has(topic)) {
|
|
176
179
|
__currentTopics.add(topic);
|
|
177
|
-
if(!this.iot.__promise) return Promise.
|
|
180
|
+
if(!this.iot.__promise) return Promise.reject('not_connected');
|
|
178
181
|
// if subscription fails, remove the topic from the current topics
|
|
179
|
-
return this.iot.__promise
|
|
182
|
+
return this.iot.__promise
|
|
183
|
+
.then(() => this.__privates.iot.subscribe(topic))
|
|
184
|
+
.catch(() => {
|
|
185
|
+
__currentTopics.delete(topic);
|
|
186
|
+
return Promise.reject('subscription_failed');
|
|
187
|
+
});
|
|
180
188
|
}
|
|
181
189
|
},
|
|
182
190
|
|
|
183
191
|
unsubscribe: (topic) => {
|
|
184
192
|
__currentTopics.delete(topic);
|
|
185
|
-
if(!this.iot.__promise) return Promise.
|
|
193
|
+
if(!this.iot.__promise) return Promise.reject('not_connected');
|
|
186
194
|
// if unsubscription fails add the topic back to the current topics
|
|
187
|
-
return this.iot.__promise
|
|
195
|
+
return this.iot.__promise
|
|
196
|
+
.then(() => this.__privates.iot.unsubscribe(topic))
|
|
197
|
+
.catch(() => {
|
|
198
|
+
__currentTopics.add(topic);
|
|
199
|
+
return Promise.reject('unsubscription_failed');
|
|
200
|
+
});
|
|
188
201
|
},
|
|
189
202
|
|
|
190
203
|
send: (topic, message) => {
|
package/src/modules/wt-iot.js
CHANGED
|
@@ -104,24 +104,32 @@ class Iot {
|
|
|
104
104
|
subscribe(topic) {
|
|
105
105
|
this.log('iot subscribe', topic);
|
|
106
106
|
if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
|
|
107
|
-
this.connection.subscribe(topic, mqtt.QoS.AtLeastOnce);
|
|
108
107
|
this.subscribedTopics.add(topic);
|
|
109
|
-
return
|
|
108
|
+
return this.connection.subscribe(topic, mqtt.QoS.AtLeastOnce)
|
|
109
|
+
.catch(err => {
|
|
110
|
+
this.log('Error subscribing to topic:', err);
|
|
111
|
+
this.subscribedTopics.delete(topic);
|
|
112
|
+
return Promise.reject(err);
|
|
113
|
+
});
|
|
110
114
|
} else {
|
|
111
115
|
this.log('Invalid topic or not connected:', topic);
|
|
112
|
-
return
|
|
116
|
+
return Promise.reject(new Error('Invalid topic or not connected'));
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
unsubscribe(topic) {
|
|
117
121
|
this.log('iot unsubscribe', topic);
|
|
118
122
|
if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
|
|
119
|
-
this.connection.unsubscribe(topic);
|
|
120
123
|
this.subscribedTopics.delete(topic);
|
|
121
|
-
return
|
|
124
|
+
return this.connection.unsubscribe(topic)
|
|
125
|
+
.catch(err => {
|
|
126
|
+
this.log('Error unsubscribing from topic:', err);
|
|
127
|
+
this.subscribedTopics.add(topic);
|
|
128
|
+
return Promise.reject(err);
|
|
129
|
+
});
|
|
122
130
|
} else {
|
|
123
131
|
this.log('Invalid topic or not connected:', topic);
|
|
124
|
-
return
|
|
132
|
+
return Promise.reject(new Error('Invalid topic or not connected'));
|
|
125
133
|
}
|
|
126
134
|
}
|
|
127
135
|
|