@reactoo/watchtogether-sdk-js 2.7.35 → 2.7.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.35",
3
+ "version": "2.7.37",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -47,11 +47,11 @@ let asset = function() {
47
47
  .then(client => client.apis.asset.initiateAssetUpload())
48
48
  },
49
49
 
50
- uploadAsset: (file, roomIds, id = null, initiationData = null) => {
50
+ uploadAsset: (file, roomIds, id = null, initiationData = null, assetData = null) => {
51
51
  return this.__privates.auth.__client
52
52
  .then(client => Promise.all([client, initiationData ? Promise.resolve(initiationData) : client.apis.asset.initiateAssetUpload({id: id || generateUUID()})]))
53
53
  .then(([client, response]) => Promise.all([client, client.http({url: response.data.signedUrl, method: response.data.httpMethod, headers: {"Content-Type":file.type}, body:file}), response.data.id]))
54
- .then(([client, response, idn]) => Promise.all([client.apis.asset.publishAsset({id:idn}, {requestBody: {title: file.name, ...(roomIds ? {roomIds} : {})}}), idn]))
54
+ .then(([client, response, idn]) => Promise.all([client.apis.asset.publishAsset({id:idn}, {requestBody: {title: file.name, ...(roomIds ? {roomIds} : {}), ...(assetData ? assetData : {})}}), idn]))
55
55
  ;
56
56
  },
57
57
  downloadAsset: (url, options = {}) => {
package/src/models/iot.js CHANGED
@@ -3,12 +3,16 @@
3
3
  let iot = function () {
4
4
  let __currentTopics = new Set();
5
5
  let visibilityChangeHandler = null;
6
+ let keepAliveIntervalId = null;
7
+ let shouldBeConnected = false;
8
+ let isReconnecting = false;
6
9
 
7
10
  return {
8
11
 
9
12
  __promise: null,
10
13
 
11
14
  __updateCredentials: () => {
15
+ isReconnecting = true;
12
16
  return this.iot.getCredentials()
13
17
  .then(response => this.__privates.iot.updateWebSocketCredentials(
14
18
  response.data.credentials.accessKeyId,
@@ -20,6 +24,9 @@ let iot = function () {
20
24
  this.__privates.iot.log('Failed to update credentials:', error);
21
25
  // Let the error propagate to be handled by the Iot class
22
26
  throw error;
27
+ })
28
+ .finally(() => {
29
+ isReconnecting = false;
23
30
  });
24
31
  },
25
32
 
@@ -34,6 +41,9 @@ let iot = function () {
34
41
  },
35
42
  onClosed: () => {
36
43
  this.__privates.iot.log('MQTT client closed');
44
+ if(shouldBeConnected && !isReconnecting) {
45
+ this.iot.__updateCredentials();
46
+ }
37
47
  },
38
48
  onError: () => {
39
49
  this.__privates.iot.log('MQTT client error');
@@ -78,7 +88,10 @@ let iot = function () {
78
88
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
79
89
  __currentTopics.clear();
80
90
 
91
+ shouldBeConnected = true;
92
+
81
93
  this.iot.setupVisibilityChangeListener();
94
+ //this.iot.setupKeepAliveInterval();
82
95
  this.iot.$on('connect', this.iot.onConnect, this);
83
96
  this.iot.$on('closed', this.iot.onClosed, this);
84
97
  this.iot.$on('error', this.iot.onError, this);
@@ -115,7 +128,10 @@ let iot = function () {
115
128
  return this.__privates.iot.disconnect()
116
129
  .then(() => {
117
130
 
131
+ shouldBeConnected = false;
132
+
118
133
  this.iot.disableVisibilityChangeListener();
134
+ //this.iot.disableKeepAliveInterval();
119
135
  this.iot.$off('connect', this.iot.onConnect, this);
120
136
  this.iot.$off('closed', this.iot.onClosed, this);
121
137
  this.iot.$off('error', this.iot.onError, this);
@@ -177,7 +193,17 @@ let iot = function () {
177
193
  return this.iot.__updateCredentials();
178
194
  });
179
195
  },
180
-
196
+
197
+ setupKeepAliveInterval: () => {
198
+ clearInterval(keepAliveIntervalId);
199
+ keepAliveIntervalId = setInterval(this.iot.checkConnection, 30000);
200
+ },
201
+
202
+ disableKeepAliveInterval: () => {
203
+ clearInterval(keepAliveIntervalId);
204
+ keepAliveIntervalId = null;
205
+ },
206
+
181
207
  setupVisibilityChangeListener: () => {
182
208
  if (visibilityChangeHandler) {
183
209
  // Listener is already set up
@@ -198,7 +198,8 @@ class Iot {
198
198
  event === 'handRaised' ||
199
199
  event === 'handLowered' ||
200
200
  event === 'handsCleared' ||
201
- event === 'volume_set'
201
+ event === 'volume_set' ||
202
+ event === 'asset_created'
202
203
  ) {
203
204
  this.emit('message', {event, ...message, roomId})
204
205
  }
@@ -251,20 +252,21 @@ class Iot {
251
252
  this.log('iot updateWebSocketCredentials');
252
253
  this.lastConnectParams = {...this.lastConnectParams, accessKeyId, secretAccessKey, sessionToken, expiration };
253
254
  const currentTopics = new Set(this.subscribedTopics);
254
- return this.disconnect()
255
- .then(() => this.connect(
256
- this.lastConnectParams.apiMqttUrl,
257
- this.lastConnectParams.apiMqttClientId,
258
- this.lastConnectParams.region,
259
- accessKeyId,
260
- secretAccessKey,
261
- sessionToken,
262
- expiration
263
- ))
264
- .then(() => {
265
- // Resubscribe to topics
266
- currentTopics.forEach(topic => this.subscribe(topic));
267
- this.startCredentialsExpirationCheck(expiration);
255
+
256
+ // disconnect is part of connect process
257
+
258
+ return this.connect(
259
+ this.lastConnectParams.apiMqttUrl,
260
+ this.lastConnectParams.apiMqttClientId,
261
+ this.lastConnectParams.region,
262
+ accessKeyId,
263
+ secretAccessKey,
264
+ sessionToken,
265
+ expiration
266
+ ).then(() => {
267
+ // Resubscribe to topics
268
+ currentTopics.forEach(topic => this.subscribe(topic));
269
+ this.startCredentialsExpirationCheck(expiration);
268
270
  })
269
271
  }
270
272