@reactoo/watchtogether-sdk-js 2.7.96 → 2.7.97

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.
@@ -529,14 +529,10 @@
529
529
  }
530
530
 
531
531
  window.asset = function () {
532
- const test = Instance.asset.getAssetList({ ids: ['6304b890-321a-494b-b0e6-b0cee48026cd'], instanceType: 'reactooBackup', type:'ids'})
532
+ Instance.asset.getAssetList({ ids: ['6304b890-321a-494b-b0e6-b0cee48026cd'], instanceType: 'reactooBackup', type:'ids'})
533
533
  .then(r => {
534
534
  console.log(r);
535
- return r;
536
535
  })
537
- test.then(r => {
538
- console.log(r);
539
- })
540
536
  }
541
537
 
542
538
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.96",
3
+ "version": "2.7.97",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -66,8 +66,7 @@ let asset = function() {
66
66
  if (onProgress && xhr.upload) {
67
67
  xhr.upload.onprogress = (event) => {
68
68
  if (event.lengthComputable) {
69
- const percentComplete = (event.loaded / event.total) * 100;
70
- onProgress(percentComplete, event.loaded, event.total);
69
+ onProgress(event.loaded, event.total);
71
70
  }
72
71
  };
73
72
  }
@@ -106,6 +105,11 @@ let asset = function() {
106
105
  downloadAsset: (url, options = {}) => {
107
106
  return this.__privates.auth.__client
108
107
  .then(client => client.http({url, method: 'GET', ...options}))
108
+ },
109
+
110
+ createStreamAsset: (id, streamType, title, regionalPreference, ingestType, source, profile) => {
111
+ return this.__privates.auth.__client
112
+ .then(client => client.apis.asset.publishAsset({id}, {requestBody: {assetType: 'stream', streamType, title, regionalPreference, ingestType, source, profile}}));
109
113
  }
110
114
  }
111
115
  };
@@ -1,7 +1,7 @@
1
1
  import { mqtt5, iot } from 'aws-iot-device-sdk-v2';
2
2
  console.log('Worker: Starting up');
3
3
 
4
- let connection = null;
4
+ let client = null;
5
5
  let currentConnectionId = 1;
6
6
 
7
7
  self.onmessage = function(event) {
@@ -37,29 +37,29 @@ function connect(params, stamp) {
37
37
  console.log('Worker: Attempting to connect');
38
38
  const { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken } = params;
39
39
 
40
- const configBuilder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets();
40
+ const configBuilder = iot.AwsIotMqtt5ClientConfigBuilder.new_with_websockets();
41
41
 
42
42
  configBuilder.with_clean_session(true);
43
43
  configBuilder.with_client_id(apiMqttClientId);
44
44
  configBuilder.with_endpoint(apiMqttUrl);
45
45
  configBuilder.with_credentials(region, accessKeyId, secretAccessKey, sessionToken);
46
- configBuilder.with_keep_alive_seconds(30);
47
46
  configBuilder.with_ping_timeout_ms(3000);
48
- configBuilder.with_reconnect_max_sec(5);
49
- configBuilder.with_reconnect_min_sec(1);
47
+ configBuilder.with_connect_properties({
48
+ keepAliveIntervalSeconds: 30,
49
+ sessionExpiryIntervalSeconds: 300
50
+ });
50
51
 
51
52
  const config = configBuilder.build();
52
- const client = new mqtt5.MqttClient(); // Use MQTT 5.0 client
53
53
 
54
- connection = client.new_connection(config);
54
+ // MQTT5 uses a single client instance
55
+ client = new mqtt5.Mqtt5Client(config);
55
56
  currentConnectionId++;
56
57
 
57
58
  setupConnectionListeners(currentConnectionId);
58
59
 
59
- connection.connect()
60
+ client.start()
60
61
  .then(() => {
61
62
  console.log('Worker: Connection successful');
62
- connection.start(); // Start the client to maintain connectivity
63
63
  self.postMessage({ type: 'connect_result', data: {success: true, connectionId: currentConnectionId, stamp} });
64
64
  })
65
65
  .catch((error) => {
@@ -69,38 +69,42 @@ function connect(params, stamp) {
69
69
  }
70
70
 
71
71
  function disconnect(stamp) {
72
- if (connection) {
72
+ if (client) {
73
73
  const connectionId = currentConnectionId;
74
- connection.stop(); // Stop the client before disconnecting
75
- connection.disconnect()
74
+ client.stop()
76
75
  .then(() => {
77
- if (connectionId !== currentConnectionId) {
76
+ if(connectionId !== currentConnectionId) {
78
77
  console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
79
78
  return;
80
79
  }
81
80
  self.postMessage({ type: 'disconnect_result', data: {success: true, stamp} });
82
81
  })
83
82
  .catch((error) => {
84
- if (connectionId !== currentConnectionId) {
83
+ if(connectionId !== currentConnectionId) {
85
84
  console.log('Worker: Connection Id mismatch, ignoring disconnect result', connectionId, currentConnectionId);
86
85
  return;
87
86
  }
88
87
  self.postMessage({ type: 'disconnect_result', data: { success: false, error: error.message, stamp} });
89
88
  });
90
- connection = null;
89
+ client = null;
91
90
  } else {
92
91
  self.postMessage({ type: 'disconnect_result', data: {success: true, stamp} });
93
92
  }
94
93
  }
95
94
 
96
95
  function isConnected() {
97
- const connected = connection && connection.currentState === 0 && connection.desiredState === 0;
96
+ const connected = client && client.getIsConnected();
98
97
  self.postMessage({ type: 'is_connected_result', data:{connected} });
99
98
  }
100
99
 
101
100
  function subscribe(topic, stamp) {
102
- if (connection && connection.currentState === 0 && connection.desiredState === 0) {
103
- connection.subscribe(topic, mqtt5.QoS.AtLeastOnce)
101
+ if (client && client.getIsConnected()) {
102
+ const subscription = {
103
+ qos: mqtt5.QoS.AtLeastOnce,
104
+ topicFilter: topic
105
+ };
106
+
107
+ client.subscribe(subscription)
104
108
  .then(() => {
105
109
  self.postMessage({ type: 'subscribe_result', data: {success: true, stamp} });
106
110
  })
@@ -113,8 +117,8 @@ function subscribe(topic, stamp) {
113
117
  }
114
118
 
115
119
  function unsubscribe(topic, stamp) {
116
- if (connection && connection.currentState === 0 && connection.desiredState === 0) {
117
- connection.unsubscribe(topic)
120
+ if (client && client.getIsConnected()) {
121
+ client.unsubscribe({ topicFilter: topic })
118
122
  .then(() => {
119
123
  self.postMessage({ type: 'unsubscribe_result', data: {success: true, stamp} });
120
124
  })
@@ -127,65 +131,80 @@ function unsubscribe(topic, stamp) {
127
131
  }
128
132
 
129
133
  function send(topic, message) {
130
- if (connection && connection.currentState === 0 && connection.desiredState === 0) {
131
- connection.publish(topic, message, mqtt5.QoS.AtLeastOnce, false, {
132
- // Example of adding user properties
133
- userProperties: {
134
- // Add your properties here
135
- }
136
- });
134
+ if (client && client.getIsConnected()) {
135
+ const publish = {
136
+ qos: mqtt5.QoS.AtLeastOnce,
137
+ topicName: topic,
138
+ payload: message,
139
+ retain: false
140
+ };
141
+ client.publish(publish);
137
142
  } else {
138
143
  console.error('Cannot send message: Not connected');
139
144
  }
140
145
  }
141
146
 
142
147
  function setupConnectionListeners(connectionId) {
143
- connection.on(mqtt5.Mqtt5Client.ATTEMPTING_CONNECT, () => {
144
- console.log('Worker: Attempting to connect');
145
- });
146
-
147
- connection.on(mqtt5.Mqtt5Client.CONNECTION_SUCCESS, (event) => {
148
- if (connectionId !== currentConnectionId) {
149
- console.log('Worker: Connection Id mismatch, ignoring connection success event', connectionId, currentConnectionId);
148
+ client.on('connectionSuccess', (eventData) => {
149
+ if(connectionId !== currentConnectionId) {
150
+ console.log('Worker: Connection Id mismatch, ignoring connectionSuccess event', connectionId, currentConnectionId);
150
151
  return;
151
152
  }
152
- self.postMessage({ type: 'connect', connectionId: connectionId, settings: event.settings });
153
+ self.postMessage({
154
+ type: 'connection_success',
155
+ data: {
156
+ sessionPresent: eventData.sessionPresent,
157
+ negotiatedSettings: eventData.negotiatedSettings
158
+ },
159
+ connectionId: connectionId
160
+ });
153
161
  });
154
162
 
155
- connection.on(mqtt5.Mqtt5Client.CONNECTION_FAILURE, (event) => {
156
- if (connectionId !== currentConnectionId) {
157
- console.log('Worker: Connection Id mismatch, ignoring connection failure event', connectionId, currentConnectionId);
163
+ client.on('connectionFailure', (error) => {
164
+ if(connectionId !== currentConnectionId) {
165
+ console.log('Worker: Connection Id mismatch, ignoring connectionFailure event', connectionId, currentConnectionId);
158
166
  return;
159
167
  }
160
- self.postMessage({ type: 'connection_failure', error: event.error });
168
+ self.postMessage({ type: 'connection_failure', data: error, connectionId: connectionId });
161
169
  });
162
170
 
163
- connection.on(mqtt5.Mqtt5Client.DISCONNECTION, (event) => {
164
- if (connectionId !== currentConnectionId) {
165
- console.log('Worker: Connection Id mismatch, ignoring disconnection event', connectionId, currentConnectionId);
171
+ client.on('disconnection', (eventData) => {
172
+ if(connectionId !== currentConnectionId) {
173
+ console.log('Worker: Connection Id mismatch, ignoring disconnect event', connectionId, currentConnectionId);
166
174
  return;
167
175
  }
168
- self.postMessage({ type: 'disconnect', error: event.error });
176
+ self.postMessage({
177
+ type: 'disconnect',
178
+ data: { reason: eventData.errorCode },
179
+ connectionId: connectionId
180
+ });
169
181
  });
170
182
 
171
- connection.on(mqtt5.Mqtt5Client.MESSAGE_RECEIVED, (event) => {
172
- if (connectionId !== currentConnectionId) {
183
+ client.on('messageReceived', (eventData) => {
184
+ if(connectionId !== currentConnectionId) {
173
185
  console.log('Worker: Connection Id mismatch, ignoring message event', connectionId, currentConnectionId);
174
186
  return;
175
187
  }
176
- self.postMessage({ type: 'message', data: event.message });
188
+ self.postMessage({
189
+ type: 'message',
190
+ data: {
191
+ topic: eventData.message.topicName,
192
+ payload: eventData.message.payload,
193
+ qos: eventData.message.qos,
194
+ retain: eventData.message.retain,
195
+ properties: eventData.message.properties
196
+ },
197
+ connectionId: connectionId
198
+ });
177
199
  });
178
200
 
179
- // Additional events can be added as needed
180
- }
181
-
182
- // Ensure to call close when the worker is terminated or no longer needed
183
- function cleanup() {
184
- if (connection) {
185
- connection.close(); // Clean up resources
186
- connection = null;
187
- }
201
+ client.on('error', (error) => {
202
+ if(connectionId !== currentConnectionId) {
203
+ console.log('Worker: Connection Id mismatch, ignoring error event', connectionId, currentConnectionId);
204
+ return;
205
+ }
206
+ self.postMessage({ type: 'error', data: error });
207
+ });
188
208
  }
189
209
 
190
- // Add this at the end of the file
191
210
  console.log('Worker: Setup complete');