@reactoo/watchtogether-sdk-js 2.7.26 → 2.7.31
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 +73851 -53892
- package/dist/watchtogether-sdk.js.map +1 -1
- package/dist/watchtogether-sdk.min.js +2 -2
- package/example/index.html +12 -0
- package/package.json +1 -1
- package/src/models/iot.js +5 -2
- package/src/modules/wt-iot.js +7 -3
package/example/index.html
CHANGED
|
@@ -185,6 +185,18 @@
|
|
|
185
185
|
Instance.room.getSessionByConstructId(constructId).setRestrictSubscribeToUserIds(userIds)
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
function iotLogout() {
|
|
189
|
+
return Instance.iot.iotLogout()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function itoLogin() {
|
|
193
|
+
return Instance.iot.iotLogin()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function iotSubscribe(topic) {
|
|
197
|
+
return Instance.iot.subscribe(topic)
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
let Instance = WatchTogetherSDK({debug:true})({instanceType:'reactooDemo'});
|
|
189
201
|
|
|
190
202
|
Instance.auth.$on('login', (r) => {
|
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -114,6 +114,7 @@ let iot = function () {
|
|
|
114
114
|
return this.__privates.iot.disconnect()
|
|
115
115
|
.then(() => {
|
|
116
116
|
this.iot.__promise = null;
|
|
117
|
+
this.iot.$clear();
|
|
117
118
|
return true;
|
|
118
119
|
});
|
|
119
120
|
},
|
|
@@ -126,14 +127,16 @@ let iot = function () {
|
|
|
126
127
|
if(!__currentTopics.has(topic)) {
|
|
127
128
|
__currentTopics.add(topic);
|
|
128
129
|
if(!this.iot.__promise) return Promise.resolve('not_connected');
|
|
129
|
-
|
|
130
|
+
// if subscription fails, remove the topic from the current topics
|
|
131
|
+
return this.iot.__promise.then(() => !this.__privates.iot.subscribe(topic) && __currentTopics.delete(topic));
|
|
130
132
|
}
|
|
131
133
|
},
|
|
132
134
|
|
|
133
135
|
unsubscribe: (topic) => {
|
|
134
136
|
__currentTopics.delete(topic);
|
|
135
137
|
if(!this.iot.__promise) return Promise.resolve('not_connected');
|
|
136
|
-
|
|
138
|
+
// if unsubscription fails add the topic back to the current topics
|
|
139
|
+
return this.iot.__promise.then(() => !this.__privates.iot.unsubscribe(topic) && __currentTopics.add(topic));
|
|
137
140
|
},
|
|
138
141
|
|
|
139
142
|
send: (topic, message) => {
|
package/src/modules/wt-iot.js
CHANGED
|
@@ -117,21 +117,25 @@ class Iot {
|
|
|
117
117
|
|
|
118
118
|
subscribe(topic) {
|
|
119
119
|
this.log('iot subscribe', topic);
|
|
120
|
-
if (this.connection && typeof topic === 'string' && topic.trim() !== '') {
|
|
120
|
+
if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
|
|
121
121
|
this.connection.subscribe(topic, mqtt.QoS.AtLeastOnce);
|
|
122
122
|
this.subscribedTopics.add(topic);
|
|
123
|
+
return true;
|
|
123
124
|
} else {
|
|
124
125
|
this.log('Invalid topic or not connected:', topic);
|
|
126
|
+
return false;
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
unsubscribe(topic) {
|
|
129
131
|
this.log('iot unsubscribe', topic);
|
|
130
|
-
if (this.connection && typeof topic === 'string' && topic.trim() !== '') {
|
|
132
|
+
if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
|
|
131
133
|
this.connection.unsubscribe(topic);
|
|
132
134
|
this.subscribedTopics.delete(topic);
|
|
135
|
+
return true;
|
|
133
136
|
} else {
|
|
134
137
|
this.log('Invalid topic or not connected:', topic);
|
|
138
|
+
return false;
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
|
|
@@ -284,7 +288,7 @@ class Iot {
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
// Find a suitable topic for the connection check
|
|
287
|
-
const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user')
|
|
291
|
+
const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
|
|
288
292
|
|
|
289
293
|
if (!suitableTopic) {
|
|
290
294
|
reject(new Error('No suitable topic found for connection check'));
|