@reactoo/watchtogether-sdk-js 2.7.58 → 2.7.60
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 +55190 -0
- package/dist/watchtogether-sdk.js.map +1 -0
- package/dist/watchtogether-sdk.min.js +2 -2
- package/package.json +1 -1
- package/src/models/iot.js +6 -0
- package/src/models/room.js +13 -4
- package/src/modules/wt-iot-worker.worker.js +13 -13
- package/src/modules/wt-iot2.js +11 -8
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -235,6 +235,12 @@ let iot = function () {
|
|
|
235
235
|
this.__privates.iot.log('Ignoring connection check failure, not connected');
|
|
236
236
|
return Promise.resolve();
|
|
237
237
|
}
|
|
238
|
+
|
|
239
|
+
if(isReconnecting) {
|
|
240
|
+
this.__privates.iot.log('Connection check failed, but we are already reconnecting...');
|
|
241
|
+
return Promise.resolve();
|
|
242
|
+
}
|
|
243
|
+
|
|
238
244
|
this.__privates.iot.log('Connection check failed:', error);
|
|
239
245
|
return this.iot.__updateCredentials();
|
|
240
246
|
});
|
package/src/models/room.js
CHANGED
|
@@ -87,10 +87,6 @@ let room = function () {
|
|
|
87
87
|
}))
|
|
88
88
|
},
|
|
89
89
|
|
|
90
|
-
updateAttribute: () => {
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
|
|
94
90
|
updateRoom: ({roomId, title, description, isPublic, isRouter, recordings, slug, password, maxParticipants, setInstanceType = false, wtChannelId, isHd, isStudioLayout, hasStudioChat, reduceRoomControls, chatRoomId, linkedRoomId, type, disableSync, defaultRegion, isSimulcast, videoCodec, customAttributes, dotAttribute} = {}) => {
|
|
95
91
|
let _da = dotAttribute
|
|
96
92
|
? (Array.isArray(dotAttribute)
|
|
@@ -154,6 +150,19 @@ let room = function () {
|
|
|
154
150
|
}))
|
|
155
151
|
},
|
|
156
152
|
|
|
153
|
+
updateAttribute: ({roomId, id, operation, attributeName, value}) => {
|
|
154
|
+
return this.__privates.auth.__client
|
|
155
|
+
.then(client => client.apis.wt.updateAttribute({}, {
|
|
156
|
+
requestBody: {
|
|
157
|
+
id,
|
|
158
|
+
roomId,
|
|
159
|
+
operation,
|
|
160
|
+
attributeName,
|
|
161
|
+
value,
|
|
162
|
+
}
|
|
163
|
+
}))
|
|
164
|
+
},
|
|
165
|
+
|
|
157
166
|
getInviteUrl: ({roomId, domain, url, autologin}) => {
|
|
158
167
|
return this.__privates.auth.__client
|
|
159
168
|
.then(client => client.apis.wt.invite({}, {
|
|
@@ -2,7 +2,7 @@ import { mqtt, iot } from 'aws-iot-device-sdk-v2';
|
|
|
2
2
|
console.log('Worker: Starting up');
|
|
3
3
|
|
|
4
4
|
let connection = null;
|
|
5
|
-
let currentConnectionId =
|
|
5
|
+
let currentConnectionId = 1;
|
|
6
6
|
|
|
7
7
|
self.onmessage = function(event) {
|
|
8
8
|
const { type, params, topic, message } = event.data;
|
|
@@ -52,8 +52,8 @@ function connect(params) {
|
|
|
52
52
|
const client = new mqtt.MqttClient();
|
|
53
53
|
|
|
54
54
|
connection = client.new_connection(config);
|
|
55
|
-
//
|
|
56
|
-
currentConnectionId
|
|
55
|
+
// increment connection id
|
|
56
|
+
currentConnectionId++;
|
|
57
57
|
|
|
58
58
|
setupConnectionListeners(currentConnectionId);
|
|
59
59
|
|
|
@@ -74,14 +74,14 @@ function disconnect() {
|
|
|
74
74
|
connection.disconnect()
|
|
75
75
|
.then(() => {
|
|
76
76
|
if(connectionId !== currentConnectionId) {
|
|
77
|
-
console.log('Worker: Connection Id mismatch, ignoring disconnect result');
|
|
77
|
+
console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
self.postMessage({ type: 'disconnect_result', data: {success: true} });
|
|
81
81
|
})
|
|
82
82
|
.catch((error) => {
|
|
83
83
|
if(connectionId !== currentConnectionId) {
|
|
84
|
-
console.log('Worker: Connection Id mismatch, ignoring disconnect result');
|
|
84
|
+
console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
self.postMessage({ type: 'disconnect_result', data: { success: false, error: error.message} });
|
|
@@ -136,7 +136,7 @@ function send(topic, message) {
|
|
|
136
136
|
function setupConnectionListeners(connectionId) {
|
|
137
137
|
connection.on('connect', () => {
|
|
138
138
|
if(connectionId !== currentConnectionId) {
|
|
139
|
-
console.log('Worker: Connection Id mismatch, ignoring connect event');
|
|
139
|
+
console.log('Worker: Connection Id mismatch, ignoring connect event', connectionId, currentConnectionId);
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
self.postMessage({ type: 'connect', connectionId: connectionId});
|
|
@@ -144,7 +144,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
144
144
|
|
|
145
145
|
connection.on('disconnect', () => {
|
|
146
146
|
if(connectionId !== currentConnectionId) {
|
|
147
|
-
console.log('Worker: Connection Id mismatch, ignoring disconnect event');
|
|
147
|
+
console.log('Worker: Connection Id mismatch, ignoring disconnect event', connectionId, currentConnectionId);
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
self.postMessage({ type: 'disconnect', connectionId: connectionId });
|
|
@@ -152,7 +152,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
152
152
|
|
|
153
153
|
connection.on('error', (error) => {
|
|
154
154
|
if(connectionId !== currentConnectionId) {
|
|
155
|
-
console.log('Worker: Connection Id mismatch, ignoring error event');
|
|
155
|
+
console.log('Worker: Connection Id mismatch, ignoring error event', connectionId, currentConnectionId);
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
self.postMessage({ type: 'error', data: error });
|
|
@@ -160,7 +160,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
160
160
|
|
|
161
161
|
connection.on('interrupt', (error) => {
|
|
162
162
|
if(connectionId !== currentConnectionId) {
|
|
163
|
-
console.log('Worker: Connection Id mismatch, ignoring interrupt event');
|
|
163
|
+
console.log('Worker: Connection Id mismatch, ignoring interrupt event', connectionId, currentConnectionId);
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
self.postMessage({ type: 'interrupt', data: error, connectionId: connectionId });
|
|
@@ -168,7 +168,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
168
168
|
|
|
169
169
|
connection.on('resume', (error) => {
|
|
170
170
|
if(connectionId !== currentConnectionId) {
|
|
171
|
-
console.log('Worker: Connection Id mismatch, ignoring resume event');
|
|
171
|
+
console.log('Worker: Connection Id mismatch, ignoring resume event', connectionId, currentConnectionId);
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
self.postMessage({ type: 'resume', data: error, connectionId: connectionId });
|
|
@@ -176,7 +176,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
176
176
|
|
|
177
177
|
connection.on('message', (topic, payload) => {
|
|
178
178
|
if(connectionId !== currentConnectionId) {
|
|
179
|
-
console.log('Worker: Connection Id mismatch, ignoring message event');
|
|
179
|
+
console.log('Worker: Connection Id mismatch, ignoring message event', connectionId, currentConnectionId);
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
182
|
self.postMessage({ type: 'message', data: { topic, payload }, connectionId: connectionId });
|
|
@@ -184,7 +184,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
184
184
|
|
|
185
185
|
connection.on('connection_success', (error) => {
|
|
186
186
|
if(connectionId !== currentConnectionId) {
|
|
187
|
-
console.log('Worker: Connection Id mismatch, ignoring connection_success event');
|
|
187
|
+
console.log('Worker: Connection Id mismatch, ignoring connection_success event', connectionId, currentConnectionId);
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
190
|
self.postMessage({ type: 'connection_success', data: error, connectionId: connectionId });
|
|
@@ -192,7 +192,7 @@ function setupConnectionListeners(connectionId) {
|
|
|
192
192
|
|
|
193
193
|
connection.on('connection_failure', (error) => {
|
|
194
194
|
if(connectionId !== currentConnectionId) {
|
|
195
|
-
console.log('Worker: Connection Id mismatch, ignoring connection_failure event');
|
|
195
|
+
console.log('Worker: Connection Id mismatch, ignoring connection_failure event', connectionId, currentConnectionId);
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
self.postMessage({ type: 'connection_failure', data: error, connectionId: connectionId });
|
package/src/modules/wt-iot2.js
CHANGED
|
@@ -43,10 +43,6 @@ class Iot {
|
|
|
43
43
|
this.lastConnectParams = { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration };
|
|
44
44
|
|
|
45
45
|
return new Promise((resolve, reject) => {
|
|
46
|
-
const timeoutId = setTimeout(() => {
|
|
47
|
-
this.off('worker:connect_result');
|
|
48
|
-
reject(new Error('Connection timeout'));
|
|
49
|
-
}, 5000);
|
|
50
46
|
|
|
51
47
|
const handleConnectResult = (event) => {
|
|
52
48
|
clearTimeout(timeoutId);
|
|
@@ -59,6 +55,11 @@ class Iot {
|
|
|
59
55
|
}
|
|
60
56
|
};
|
|
61
57
|
|
|
58
|
+
const timeoutId = setTimeout(() => {
|
|
59
|
+
this.off('worker:connect_result', handleConnectResult);
|
|
60
|
+
reject(new Error('Connection timeout'));
|
|
61
|
+
}, 10000);
|
|
62
|
+
|
|
62
63
|
this.on('worker:connect_result', handleConnectResult);
|
|
63
64
|
|
|
64
65
|
this.worker.postMessage({
|
|
@@ -73,10 +74,6 @@ class Iot {
|
|
|
73
74
|
this.log('iot disconnect');
|
|
74
75
|
this.stopCredentialsExpirationCheck();
|
|
75
76
|
return new Promise((resolve, reject) => {
|
|
76
|
-
const timeoutId = setTimeout(() => {
|
|
77
|
-
this.off('worker:disconnect_result');
|
|
78
|
-
reject(new Error('Disconnect timeout'));
|
|
79
|
-
}, 5000);
|
|
80
77
|
|
|
81
78
|
const handleDisconnectResult = (event) => {
|
|
82
79
|
clearTimeout(timeoutId);
|
|
@@ -87,6 +84,12 @@ class Iot {
|
|
|
87
84
|
reject(new Error(event.error));
|
|
88
85
|
}
|
|
89
86
|
};
|
|
87
|
+
|
|
88
|
+
const timeoutId = setTimeout(() => {
|
|
89
|
+
this.off('worker:disconnect_result', handleDisconnectResult);
|
|
90
|
+
reject(new Error('Disconnect timeout'));
|
|
91
|
+
}, 5000);
|
|
92
|
+
|
|
90
93
|
this.on('worker:disconnect_result', handleDisconnectResult);
|
|
91
94
|
this.worker.postMessage({ type: 'disconnect' });
|
|
92
95
|
});
|