@reactoo/watchtogether-sdk-js 2.8.47 → 2.8.50
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 +1917 -1814
- 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 +49 -83
- package/src/models/system.js +4 -0
- package/src/modules/wt-auth.js +7 -1
- package/src/modules/wt-iot-worker5.worker.js +203 -187
- package/src/modules/wt-iot2.js +105 -113
- package/src/modules/wt-room-sfu.js +1 -1
- package/src/modules/wt-iot-worker.worker.js +0 -203
- package/src/modules/wt-room.js +0 -3716
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -7,19 +7,12 @@ let iot = function () {
|
|
|
7
7
|
let keepAliveIntervalId = null;
|
|
8
8
|
let shouldBeConnected = false;
|
|
9
9
|
let isConnecting = false;
|
|
10
|
-
let interruptCount = 0;
|
|
11
10
|
let subscriptionFailureCount = 0;
|
|
12
11
|
|
|
13
12
|
return {
|
|
14
13
|
|
|
15
14
|
__promise: null,
|
|
16
15
|
|
|
17
|
-
__createNewWorker: () => {
|
|
18
|
-
this.__privates.iot.log('Creating new worker...');
|
|
19
|
-
this.__privates.iot.terminateWorker();
|
|
20
|
-
this.__privates.iot.initWorker();
|
|
21
|
-
},
|
|
22
|
-
|
|
23
16
|
__updateCredentials: () => {
|
|
24
17
|
|
|
25
18
|
if(isConnecting) {
|
|
@@ -28,7 +21,6 @@ let iot = function () {
|
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
this.__privates.iot.log('Updating Credentials...');
|
|
31
|
-
interruptCount = 0;
|
|
32
24
|
subscriptionFailureCount = 0;
|
|
33
25
|
isConnecting = true;
|
|
34
26
|
|
|
@@ -37,7 +29,8 @@ let iot = function () {
|
|
|
37
29
|
response.data.credentials.accessKeyId,
|
|
38
30
|
response.data.credentials.secretAccessKey,
|
|
39
31
|
response.data.credentials.sessionToken,
|
|
40
|
-
response.data.credentials.expiration
|
|
32
|
+
response.data.credentials.expiration,
|
|
33
|
+
__currentTopics
|
|
41
34
|
))
|
|
42
35
|
.then((r) => {
|
|
43
36
|
isConnecting = false;
|
|
@@ -57,46 +50,39 @@ let iot = function () {
|
|
|
57
50
|
return this.__privates.auth.__client
|
|
58
51
|
.then(client => client.apis.auth.iotSignIn({}, {requestBody: {suggestedTopics:true, domain: location.hostname}}))
|
|
59
52
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.__privates.iot.log('MQTT client connected');
|
|
63
|
-
},
|
|
64
|
-
onClosed: (data, connectionId) => {
|
|
65
|
-
this.__privates.iot.log('MQTT client closed');
|
|
66
|
-
if(shouldBeConnected && !isConnecting) {
|
|
67
|
-
this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
|
|
68
|
-
this.iot.__createNewWorker();
|
|
69
|
-
this.iot.__updateCredentials();
|
|
70
|
-
}
|
|
53
|
+
onStopped: (data, connectionId) => {
|
|
54
|
+
this.__privates.iot.log('MQTT client disconnected');
|
|
71
55
|
},
|
|
72
56
|
onError: (data, connectionId) => {
|
|
73
|
-
|
|
57
|
+
this.__privates.iot.log('MQTT client error');
|
|
58
|
+
if(shouldBeConnected && !isConnecting) {
|
|
59
|
+
this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
|
|
60
|
+
this.iot.__updateCredentials();
|
|
61
|
+
}
|
|
74
62
|
},
|
|
75
63
|
onDisconnect: (data, connectionId) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.iot.__createNewWorker();
|
|
82
|
-
this.iot.__updateCredentials();
|
|
83
|
-
}
|
|
84
|
-
interruptCount++;
|
|
85
|
-
this.__privates.iot.log('MQTT client interrupt');
|
|
86
|
-
},
|
|
87
|
-
onResume: (data, connectionId) => {
|
|
88
|
-
this.__privates.iot.log('MQTT client resume');
|
|
64
|
+
this.__privates.iot.log('MQTT client closed');
|
|
65
|
+
if(shouldBeConnected && !isConnecting) {
|
|
66
|
+
this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
|
|
67
|
+
this.iot.__updateCredentials();
|
|
68
|
+
}
|
|
89
69
|
},
|
|
70
|
+
onAttemptingConnect: (data, connectionId) => {
|
|
71
|
+
this.__privates.iot.log('MQTT client attempting_connect');
|
|
72
|
+
},
|
|
90
73
|
onConnectionSuccess: (data, connectionId) => {
|
|
91
74
|
this.__privates.iot.log('MQTT client connection_success');
|
|
92
75
|
},
|
|
93
76
|
onConnectionFailure: (data, connectionId) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
|
|
78
|
+
// ok this should not work as isConnecting should be true here and will be flipped after first onConnectionFailure
|
|
79
|
+
// but the aws library immediately tries new connection after failure so we get multiple onConnectionFailure calls
|
|
80
|
+
// so the second one will trigger updateCredentials again which is what we want
|
|
81
|
+
|
|
82
|
+
if(shouldBeConnected) {
|
|
83
|
+
this.__privates.iot.log('Retrying connection...');
|
|
97
84
|
this.iot.__updateCredentials();
|
|
98
85
|
}
|
|
99
|
-
interruptCount++;
|
|
100
86
|
this.__privates.iot.log('MQTT client connection_failure');
|
|
101
87
|
},
|
|
102
88
|
|
|
@@ -107,12 +93,18 @@ let iot = function () {
|
|
|
107
93
|
return this.iot.__promise;
|
|
108
94
|
}
|
|
109
95
|
|
|
110
|
-
interruptCount = 0;
|
|
111
96
|
subscriptionFailureCount = 0;
|
|
112
97
|
shouldBeConnected = true;
|
|
113
98
|
isConnecting = true;
|
|
114
99
|
|
|
115
|
-
|
|
100
|
+
this.iot.$on('stopped', this.iot.onStopped, this);
|
|
101
|
+
this.iot.$on('error', this.iot.onError, this);
|
|
102
|
+
this.iot.$on('disconnection', this.iot.onDisconnect, this);
|
|
103
|
+
this.iot.$on('attemptingConnect', this.iot.onAttemptingConnect, this);
|
|
104
|
+
this.iot.$on('connectionSuccess', this.iot.onConnectionSuccess, this);
|
|
105
|
+
this.iot.$on('connectionFailure', this.iot.onConnectionFailure, this);
|
|
106
|
+
this.iot.$on('updateCredentials', this.iot.__updateCredentials, this);
|
|
107
|
+
|
|
116
108
|
this.iot.__promise = new Promise((resolve, reject) => {
|
|
117
109
|
this.iot.getCredentials()
|
|
118
110
|
.then(response => {
|
|
@@ -141,16 +133,6 @@ let iot = function () {
|
|
|
141
133
|
|
|
142
134
|
__currentTopics.clear();
|
|
143
135
|
|
|
144
|
-
this.iot.$on('connect', this.iot.onConnect, this);
|
|
145
|
-
this.iot.$on('closed', this.iot.onClosed, this);
|
|
146
|
-
this.iot.$on('error', this.iot.onError, this);
|
|
147
|
-
this.iot.$on('disconnect', this.iot.onDisconnect, this);
|
|
148
|
-
this.iot.$on('interrupt', this.iot.onInterrupt, this);
|
|
149
|
-
this.iot.$on('resume', this.iot.onResume, this);
|
|
150
|
-
this.iot.$on('connection_success', this.iot.onConnectionSuccess, this);
|
|
151
|
-
this.iot.$on('connection_failure', this.iot.onConnectionFailure, this);
|
|
152
|
-
this.iot.$on('updateCredentials', this.iot.__updateCredentials, this);
|
|
153
|
-
|
|
154
136
|
this.iot.__promise
|
|
155
137
|
.then(([suggestedTopic, instance]) => {
|
|
156
138
|
if(!subscribeToSuggestedTopics) {
|
|
@@ -166,41 +148,39 @@ let iot = function () {
|
|
|
166
148
|
})
|
|
167
149
|
.catch((error) => {
|
|
168
150
|
this.__privates.iot.log('MQTT Login Error:', error);
|
|
169
|
-
throw error;
|
|
170
151
|
});
|
|
171
152
|
|
|
172
|
-
|
|
153
|
+
// we're not returning the promise because on error we will retry connection indefinitely
|
|
154
|
+
return true;
|
|
173
155
|
},
|
|
174
156
|
|
|
175
157
|
iotLogout: (keepCurrentTopics = false) => {
|
|
176
158
|
|
|
177
159
|
if(!keepCurrentTopics) {
|
|
178
160
|
__currentTopics.clear();
|
|
179
|
-
this.__privates.iot.clearTopics();
|
|
180
161
|
}
|
|
181
162
|
|
|
182
|
-
interruptCount = 0;
|
|
183
163
|
subscriptionFailureCount = 0;
|
|
184
164
|
shouldBeConnected = false;
|
|
185
165
|
|
|
186
166
|
this.iot.disableVisibilityChangeListener();
|
|
187
167
|
this.iot.disableKeepAliveInterval();
|
|
188
168
|
|
|
189
|
-
|
|
169
|
+
this.__privates.iot.disconnect()
|
|
190
170
|
.finally(() => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.iot.$off('connection_success', this.iot.onConnectionSuccess, this);
|
|
199
|
-
this.iot.$off('connection_failure', this.iot.onConnectionFailure, this);
|
|
200
|
-
this.iot.$off('updateCredentials', this.iot.__updateCredentials, this);
|
|
171
|
+
this.iot.$off('stopped', this.iot.onStopped, this);
|
|
172
|
+
this.iot.$off('error', this.iot.onError, this);
|
|
173
|
+
this.iot.$off('disconnection', this.iot.onDisconnect, this);
|
|
174
|
+
this.iot.$off('attemptingConnect', this.iot.onAttemptingConnect, this);
|
|
175
|
+
this.iot.$off('connectionSuccess', this.iot.onConnectionSuccess, this);
|
|
176
|
+
this.iot.$off('connectionFailure', this.iot.onConnectionFailure, this);
|
|
177
|
+
this.iot.$off('updateCredentials', this.iot.__updateCredentials, this);
|
|
201
178
|
this.iot.__promise = null;
|
|
202
179
|
return true;
|
|
203
180
|
});
|
|
181
|
+
|
|
182
|
+
// we're not returning the promise because we're not returning anything useful anyway
|
|
183
|
+
return true;
|
|
204
184
|
},
|
|
205
185
|
|
|
206
186
|
isConnected: () => {
|
|
@@ -228,7 +208,6 @@ let iot = function () {
|
|
|
228
208
|
|
|
229
209
|
if(shouldBeConnected && !isConnecting && subscriptionFailureCount > 5) {
|
|
230
210
|
this.__privates.iot.log('Subscription failure exceeded, reconnecting...');
|
|
231
|
-
this.iot.__createNewWorker();
|
|
232
211
|
this.iot.__updateCredentials();
|
|
233
212
|
return Promise.reject('subscription_failed');
|
|
234
213
|
}
|
|
@@ -278,11 +257,11 @@ let iot = function () {
|
|
|
278
257
|
},
|
|
279
258
|
|
|
280
259
|
checkConnection: () => {
|
|
281
|
-
return this.__privates.iot.checkConnection()
|
|
260
|
+
return this.__privates.iot.checkConnection(__currentTopics)
|
|
282
261
|
.catch(error => {
|
|
283
262
|
|
|
284
263
|
if(error?.cause === -1) {
|
|
285
|
-
this.__privates.iot.log("We don't have a topic to check connection with");
|
|
264
|
+
this.__privates.iot.log("We don't have a topic to check connection with or internet is down");
|
|
286
265
|
return;
|
|
287
266
|
}
|
|
288
267
|
|
|
@@ -297,7 +276,7 @@ let iot = function () {
|
|
|
297
276
|
}
|
|
298
277
|
|
|
299
278
|
this.__privates.iot.log('Connection check failed:', error);
|
|
300
|
-
|
|
279
|
+
|
|
301
280
|
return this.iot.__updateCredentials();
|
|
302
281
|
});
|
|
303
282
|
},
|
|
@@ -308,20 +287,7 @@ let iot = function () {
|
|
|
308
287
|
|
|
309
288
|
clearInterval(keepAliveIntervalId);
|
|
310
289
|
keepAliveIntervalId = setInterval(() => {
|
|
311
|
-
|
|
312
|
-
.catch(error => {
|
|
313
|
-
|
|
314
|
-
if(error?.cause === -1) {
|
|
315
|
-
this.__privates.iot.log("We don't have a topic to check connection with or check was aborted");
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if(shouldBeConnected && !isConnecting) {
|
|
320
|
-
this.__privates.iot.log('Keepalive failed:', error);
|
|
321
|
-
this.iot.__createNewWorker();
|
|
322
|
-
this.iot.__updateCredentials();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
290
|
+
this.iot.checkConnection();
|
|
325
291
|
}, 15000);
|
|
326
292
|
},
|
|
327
293
|
|
package/src/models/system.js
CHANGED
|
@@ -75,6 +75,10 @@ let system = function () {
|
|
|
75
75
|
}
|
|
76
76
|
}));
|
|
77
77
|
},
|
|
78
|
+
trackPlayback: ({objectId, eventType, currentTime, duration, quality, pageUrl, data} = {}) => {
|
|
79
|
+
return this.__privates.auth.__client
|
|
80
|
+
.then(client => client.apis.wt.trackPlayback({}, {requestBody: {objectId, eventType, currentTime, duration, quality, pageUrl, data}}));
|
|
81
|
+
},
|
|
78
82
|
getSchemas: () => {
|
|
79
83
|
return this.__privates.auth.__client.then(client => {
|
|
80
84
|
return client.spec?.components?.schemas
|
package/src/modules/wt-auth.js
CHANGED
|
@@ -115,7 +115,8 @@ class Auth {
|
|
|
115
115
|
isLoggedInAsInstanceAdmin: this.isLoggedInAs(this.__parsedJwt, 'instanceAdmin'),
|
|
116
116
|
isDemoAccount: this.isLoggedInAs(this.__parsedJwt, 'demo'),
|
|
117
117
|
isLoggedInAsAdmin: this.isLoggedInAs(this.__parsedJwt, 'admin'),
|
|
118
|
-
domain: this.getDomain(this.__parsedJwt)
|
|
118
|
+
domain: this.getDomain(this.__parsedJwt),
|
|
119
|
+
parentUserId: this.getParentUserId(this.__parsedJwt)
|
|
119
120
|
});
|
|
120
121
|
return client;
|
|
121
122
|
})
|
|
@@ -167,6 +168,11 @@ class Auth {
|
|
|
167
168
|
parsedJwt = parsedJwt || this.__parsedJwt;
|
|
168
169
|
return parsedJwt['custom:domain'];
|
|
169
170
|
}
|
|
171
|
+
|
|
172
|
+
getParentUserId(parsedJwt) {
|
|
173
|
+
parsedJwt = parsedJwt || this.__parsedJwt;
|
|
174
|
+
return parsedJwt ? parsedJwt['custom:parentUserId'] : null;
|
|
175
|
+
}
|
|
170
176
|
|
|
171
177
|
parseJwt(jwt) {
|
|
172
178
|
if (!jwt || typeof jwt !== "string") return false;
|