@reactoo/watchtogether-sdk-js 2.7.35 → 2.7.36

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.36",
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,6 +3,8 @@
3
3
  let iot = function () {
4
4
  let __currentTopics = new Set();
5
5
  let visibilityChangeHandler = null;
6
+ let keepAliveIntervalId = null;
7
+ let shouldBeConnected = false;
6
8
 
7
9
  return {
8
10
 
@@ -34,6 +36,9 @@ let iot = function () {
34
36
  },
35
37
  onClosed: () => {
36
38
  this.__privates.iot.log('MQTT client closed');
39
+ if(shouldBeConnected) {
40
+ this.iot.__updateCredentials();
41
+ }
37
42
  },
38
43
  onError: () => {
39
44
  this.__privates.iot.log('MQTT client error');
@@ -78,7 +83,10 @@ let iot = function () {
78
83
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
79
84
  __currentTopics.clear();
80
85
 
86
+ shouldBeConnected = true;
87
+
81
88
  this.iot.setupVisibilityChangeListener();
89
+ //this.iot.setupKeepAliveInterval();
82
90
  this.iot.$on('connect', this.iot.onConnect, this);
83
91
  this.iot.$on('closed', this.iot.onClosed, this);
84
92
  this.iot.$on('error', this.iot.onError, this);
@@ -115,7 +123,10 @@ let iot = function () {
115
123
  return this.__privates.iot.disconnect()
116
124
  .then(() => {
117
125
 
126
+ shouldBeConnected = false;
127
+
118
128
  this.iot.disableVisibilityChangeListener();
129
+ //this.iot.disableKeepAliveInterval();
119
130
  this.iot.$off('connect', this.iot.onConnect, this);
120
131
  this.iot.$off('closed', this.iot.onClosed, this);
121
132
  this.iot.$off('error', this.iot.onError, this);
@@ -177,7 +188,17 @@ let iot = function () {
177
188
  return this.iot.__updateCredentials();
178
189
  });
179
190
  },
180
-
191
+
192
+ setupKeepAliveInterval: () => {
193
+ clearInterval(keepAliveIntervalId);
194
+ keepAliveIntervalId = setInterval(this.iot.checkConnection, 30000);
195
+ },
196
+
197
+ disableKeepAliveInterval: () => {
198
+ clearInterval(keepAliveIntervalId);
199
+ keepAliveIntervalId = null;
200
+ },
201
+
181
202
  setupVisibilityChangeListener: () => {
182
203
  if (visibilityChangeHandler) {
183
204
  // 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
  }