@reactoo/watchtogether-sdk-js 2.7.61 → 2.7.62

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.61",
3
+ "version": "2.7.62",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -5,15 +5,15 @@ let connection = null;
5
5
  let currentConnectionId = 1;
6
6
 
7
7
  self.onmessage = function(event) {
8
- const { type, params, topic, message } = event.data;
8
+ const { type, params, topic, message, stamp } = event.data;
9
9
  console.log(`Worker: Received message of type: ${type}`);
10
10
 
11
11
  switch (type) {
12
12
  case 'connect':
13
- connect(params);
13
+ connect(params, stamp);
14
14
  break;
15
15
  case 'disconnect':
16
- disconnect();
16
+ disconnect(stamp);
17
17
  break;
18
18
  case 'is_connected':
19
19
  isConnected();
@@ -33,7 +33,7 @@ self.onmessage = function(event) {
33
33
  }
34
34
  };
35
35
 
36
- function connect(params) {
36
+ function connect(params, stamp) {
37
37
  console.log('Worker: Attempting to connect');
38
38
  const { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken } = params;
39
39
 
@@ -60,15 +60,15 @@ function connect(params) {
60
60
  connection.connect()
61
61
  .then(() => {
62
62
  console.log('Worker: Connection successful');
63
- self.postMessage({ type: 'connect_result', data: {success: true, connectionId: currentConnectionId} });
63
+ self.postMessage({ type: 'connect_result', data: {success: true, connectionId: currentConnectionId, stamp} });
64
64
  })
65
65
  .catch((error) => {
66
66
  console.error('Worker: Connection failed', error);
67
- self.postMessage({ type: 'connect_result', data: {success: false, error: error.message} });
67
+ self.postMessage({ type: 'connect_result', data: {success: false, error: error.message, stamp} });
68
68
  });
69
69
  }
70
70
 
71
- function disconnect() {
71
+ function disconnect(stamp) {
72
72
  if (connection) {
73
73
  const connectionId = currentConnectionId;
74
74
  connection.disconnect()
@@ -77,18 +77,18 @@ function disconnect() {
77
77
  console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
78
78
  return;
79
79
  }
80
- self.postMessage({ type: 'disconnect_result', data: {success: true} });
80
+ self.postMessage({ type: 'disconnect_result', data: {success: true, stamp} });
81
81
  })
82
82
  .catch((error) => {
83
83
  if(connectionId !== currentConnectionId) {
84
84
  console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
85
85
  return;
86
86
  }
87
- self.postMessage({ type: 'disconnect_result', data: { success: false, error: error.message} });
87
+ self.postMessage({ type: 'disconnect_result', data: { success: false, error: error.message, stamp} });
88
88
  });
89
89
  connection = null;
90
90
  } else {
91
- self.postMessage({ type: 'disconnect_result', data: {success: true} });
91
+ self.postMessage({ type: 'disconnect_result', data: {success: true, stamp} });
92
92
  }
93
93
  }
94
94
 
@@ -44,7 +44,15 @@ class Iot {
44
44
 
45
45
  return new Promise((resolve, reject) => {
46
46
 
47
+ const stamp = new Date().getTime();
48
+
47
49
  const handleConnectResult = (event) => {
50
+
51
+ if(event.stamp !== stamp) {
52
+ this.log('connect event stamp mismatch', event.stamp, stamp);
53
+ return;
54
+ }
55
+
48
56
  clearTimeout(timeoutId);
49
57
  this.off('worker:connect_result', handleConnectResult);
50
58
  if (event.success) {
@@ -64,7 +72,8 @@ class Iot {
64
72
 
65
73
  this.worker.postMessage({
66
74
  type: 'connect',
67
- params: this.lastConnectParams
75
+ params: this.lastConnectParams,
76
+ stamp: stamp
68
77
  });
69
78
  });
70
79
  });
@@ -75,7 +84,15 @@ class Iot {
75
84
  this.stopCredentialsExpirationCheck();
76
85
  return new Promise((resolve, reject) => {
77
86
 
87
+ const stamp = new Date().getTime();
88
+
78
89
  const handleDisconnectResult = (event) => {
90
+
91
+ if(event.stamp !== stamp) {
92
+ this.log('disconnect event stamp mismatch', event.stamp, stamp);
93
+ return;
94
+ }
95
+
79
96
  clearTimeout(timeoutId);
80
97
  this.off('worker:disconnect_result', handleDisconnectResult);
81
98
  if (event.success) {
@@ -91,7 +108,7 @@ class Iot {
91
108
  }, 5000);
92
109
 
93
110
  this.on('worker:disconnect_result', handleDisconnectResult);
94
- this.worker.postMessage({ type: 'disconnect' });
111
+ this.worker.postMessage({ type: 'disconnect', stamp: stamp });
95
112
  });
96
113
  }
97
114