@reactoo/watchtogether-sdk-js 2.7.38-beta.2 → 2.7.38
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @reactoo/watchtogether-sdk-js
|
|
3
|
-
* @version 2.7.
|
|
3
|
+
* @version 2.7.38-beta.3
|
|
4
4
|
*/
|
|
5
5
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
6
6
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -16711,11 +16711,14 @@ let iot = function () {
|
|
|
16711
16711
|
let keepAliveIntervalId = null;
|
|
16712
16712
|
let shouldBeConnected = false;
|
|
16713
16713
|
let isReconnecting = false;
|
|
16714
|
+
let interruptCount = 0;
|
|
16714
16715
|
return {
|
|
16715
16716
|
__promise: null,
|
|
16716
16717
|
__updateCredentials: () => {
|
|
16718
|
+
interruptCount = 0;
|
|
16717
16719
|
isReconnecting = true;
|
|
16718
16720
|
return this.iot.getCredentials().then(response => this.__privates.iot.updateWebSocketCredentials(response.data.credentials.accessKeyId, response.data.credentials.secretAccessKey, response.data.credentials.sessionToken, response.data.credentials.expiration)).catch(error => {
|
|
16721
|
+
console.log('Failed to update credentials:', error);
|
|
16719
16722
|
this.__privates.iot.log('Failed to update credentials:', error);
|
|
16720
16723
|
// Let the error propagate to be handled by the Iot class
|
|
16721
16724
|
throw error;
|
|
@@ -16747,6 +16750,10 @@ let iot = function () {
|
|
|
16747
16750
|
this.__privates.iot.log('MQTT client disconnect');
|
|
16748
16751
|
},
|
|
16749
16752
|
onInterrupt: () => {
|
|
16753
|
+
if (shouldBeConnected && !isReconnecting && !document.hidden && interruptCount > 10) {
|
|
16754
|
+
this.iot.__updateCredentials();
|
|
16755
|
+
}
|
|
16756
|
+
interruptCount++;
|
|
16750
16757
|
this.__privates.iot.log('MQTT client interrupt');
|
|
16751
16758
|
},
|
|
16752
16759
|
onResume: () => {
|
|
@@ -16760,6 +16767,8 @@ let iot = function () {
|
|
|
16760
16767
|
},
|
|
16761
16768
|
iotLogin: function () {
|
|
16762
16769
|
let subscribeToSuggestedTopics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
16770
|
+
interruptCount = 0;
|
|
16771
|
+
shouldBeConnected = true;
|
|
16763
16772
|
_this.iot.__promise = new Promise((resolve, reject) => {
|
|
16764
16773
|
_this.iot.getCredentials().then(response => {
|
|
16765
16774
|
return Promise.all([response.data.suggestedTopics, _this.__privates.iot.connect(response.data.endpoint, response.data.clientId, response.data.region, response.data.credentials.accessKeyId, response.data.credentials.secretAccessKey, response.data.credentials.sessionToken, response.data.credentials.expiration)]);
|
|
@@ -16767,9 +16776,8 @@ let iot = function () {
|
|
|
16767
16776
|
});
|
|
16768
16777
|
let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
|
|
16769
16778
|
__currentTopics.clear();
|
|
16770
|
-
shouldBeConnected = true;
|
|
16771
16779
|
_this.iot.setupVisibilityChangeListener();
|
|
16772
|
-
|
|
16780
|
+
_this.iot.setupKeepAliveInterval();
|
|
16773
16781
|
_this.iot.$on('connect', _this.iot.onConnect, _this);
|
|
16774
16782
|
_this.iot.$on('closed', _this.iot.onClosed, _this);
|
|
16775
16783
|
_this.iot.$on('error', _this.iot.onError, _this);
|
|
@@ -16799,10 +16807,11 @@ let iot = function () {
|
|
|
16799
16807
|
if (!keepCurrentTopics) {
|
|
16800
16808
|
__currentTopics.clear();
|
|
16801
16809
|
}
|
|
16810
|
+
interruptCount = 0;
|
|
16811
|
+
shouldBeConnected = false;
|
|
16802
16812
|
return _this.__privates.iot.disconnect().then(() => {
|
|
16803
|
-
shouldBeConnected = false;
|
|
16804
16813
|
_this.iot.disableVisibilityChangeListener();
|
|
16805
|
-
|
|
16814
|
+
_this.iot.disableKeepAliveInterval();
|
|
16806
16815
|
_this.iot.$off('connect', _this.iot.onConnect, _this);
|
|
16807
16816
|
_this.iot.$off('closed', _this.iot.onClosed, _this);
|
|
16808
16817
|
_this.iot.$off('error', _this.iot.onError, _this);
|
|
@@ -16855,7 +16864,9 @@ let iot = function () {
|
|
|
16855
16864
|
},
|
|
16856
16865
|
setupKeepAliveInterval: () => {
|
|
16857
16866
|
clearInterval(keepAliveIntervalId);
|
|
16858
|
-
keepAliveIntervalId = setInterval(
|
|
16867
|
+
keepAliveIntervalId = setInterval(() => {
|
|
16868
|
+
this.__privates.iot.keepAliveMessage();
|
|
16869
|
+
}, 30000);
|
|
16859
16870
|
},
|
|
16860
16871
|
disableKeepAliveInterval: () => {
|
|
16861
16872
|
clearInterval(keepAliveIntervalId);
|
|
@@ -25237,7 +25248,6 @@ class Iot {
|
|
|
25237
25248
|
Object.assign(this, (0,_wt_emitter__WEBPACK_IMPORTED_MODULE_0__["default"])());
|
|
25238
25249
|
this.decoder = new TextDecoder('utf-8');
|
|
25239
25250
|
this.log = Iot.noop;
|
|
25240
|
-
// Remove: this.debugFlag = enableDebugFlag;
|
|
25241
25251
|
this.credentialsExpirationCheckIntervalId = null;
|
|
25242
25252
|
this.currentCredentialsExpirationStamp = null;
|
|
25243
25253
|
this.lastConnectParams = null;
|
|
@@ -25465,9 +25475,7 @@ class Iot {
|
|
|
25465
25475
|
expiration
|
|
25466
25476
|
};
|
|
25467
25477
|
const currentTopics = new Set(this.subscribedTopics);
|
|
25468
|
-
|
|
25469
25478
|
// disconnect is part of connect process
|
|
25470
|
-
|
|
25471
25479
|
return this.connect(this.lastConnectParams.apiMqttUrl, this.lastConnectParams.apiMqttClientId, this.lastConnectParams.region, accessKeyId, secretAccessKey, sessionToken, expiration).then(() => {
|
|
25472
25480
|
// Resubscribe to topics
|
|
25473
25481
|
currentTopics.forEach(topic => this.subscribe(topic));
|
|
@@ -25517,6 +25525,27 @@ class Iot {
|
|
|
25517
25525
|
}
|
|
25518
25526
|
});
|
|
25519
25527
|
}
|
|
25528
|
+
keepAliveMessage() {
|
|
25529
|
+
if (this.subscribedTopics.size === 0) {
|
|
25530
|
+
this.log('No subscribed topics available for keep alive message');
|
|
25531
|
+
return;
|
|
25532
|
+
}
|
|
25533
|
+
// Find a suitable topic for the connection check
|
|
25534
|
+
const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
|
|
25535
|
+
if (!suitableTopic) {
|
|
25536
|
+
this.log('No suitable topic found for keep alive message');
|
|
25537
|
+
return;
|
|
25538
|
+
}
|
|
25539
|
+
const testMessage = {
|
|
25540
|
+
type: 'keep_alive',
|
|
25541
|
+
timestamp: Date.now()
|
|
25542
|
+
};
|
|
25543
|
+
try {
|
|
25544
|
+
this.send(suitableTopic, testMessage);
|
|
25545
|
+
} catch (error) {
|
|
25546
|
+
this.log(`Keep-alive error: ${error.message}`);
|
|
25547
|
+
}
|
|
25548
|
+
}
|
|
25520
25549
|
}
|
|
25521
25550
|
/* harmony default export */ __webpack_exports__["default"] = (Iot);
|
|
25522
25551
|
|