@soundworks/core 5.3.0 → 5.4.1

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": "@soundworks/core",
3
- "version": "5.3.0",
3
+ "version": "5.4.1",
4
4
  "description": "Open-source creative coding framework for distributed applications based on Web technologies",
5
5
  "collaborators": [
6
6
  "Benjamin Matuszewski",
@@ -230,6 +230,17 @@ class BaseStateManager {
230
230
  this.#status = 'inited';
231
231
  }
232
232
 
233
+ /**
234
+ * Validates the given class description.
235
+ *
236
+ * @throws Throws if the class description is invalid
237
+ * @param {*} classDescription
238
+ * @returns undefined
239
+ */
240
+ validateClassDescription(classDescription) {
241
+ return ParameterBag.validateDescription(classDescription);
242
+ }
243
+
233
244
  /**
234
245
  * Return a class description from a given class name
235
246
  *
@@ -430,6 +430,19 @@ class ParameterBag {
430
430
 
431
431
  return defaults;
432
432
  }
433
+
434
+ // @todo - should cache result
435
+ getParamListByDescriptor(descriptorName, descriptorValue) {
436
+ const result = [];
437
+
438
+ for (let [name, def] of Object.entries(this.#description)) {
439
+ if (def[descriptorName] === descriptorValue) {
440
+ result.push(name);
441
+ }
442
+ }
443
+
444
+ return result;
445
+ }
433
446
  }
434
447
 
435
448
  export default ParameterBag;
@@ -214,11 +214,19 @@ class SharedState {
214
214
  this.#clearTransport();
215
215
 
216
216
  for (let callback of this.#onDetachCallbacks) {
217
- await callback();
217
+ try {
218
+ await callback();
219
+ } catch (err) {
220
+ console.log(err.message);
221
+ }
218
222
  }
219
223
 
220
224
  for (let callback of this.#onDeleteCallbacks) {
221
- await callback();
225
+ try {
226
+ await callback();
227
+ } catch (err) {
228
+ console.log(err.message);
229
+ }
222
230
  }
223
231
 
224
232
  this.#onDetachCallbacks.clear();
@@ -240,7 +248,11 @@ class SharedState {
240
248
  this.#clearTransport();
241
249
 
242
250
  for (let callback of this.#onDetachCallbacks) {
243
- await callback();
251
+ try {
252
+ await callback();
253
+ } catch (err) {
254
+ console.log(err.message);
255
+ }
244
256
  }
245
257
 
246
258
  this.#onDetachCallbacks.clear();
@@ -1,2 +1,2 @@
1
1
  // [WARNING] This file is generated, do not edit
2
- export default '5.3.0';
2
+ export default '5.4.1';
@@ -127,6 +127,9 @@ class SharedStatePrivate {
127
127
  // apply registered hooks
128
128
  const hooks = this.#manager[kServerStateManagerGetUpdateHooks](this.className);
129
129
  const values = this.#parameters.getValues();
130
+ // make sur we don't propagate back to requester param that are marked as `acknowledge=false`
131
+ const acknowledgeFilter = this.#parameters.getParamListByDescriptor('acknowledge', false);
132
+
130
133
  let hookAborted = false;
131
134
 
132
135
  // cf. https://github.com/collective-soundworks/soundworks/issues/45
@@ -145,13 +148,12 @@ class SharedStatePrivate {
145
148
 
146
149
  if (hookAborted === false) {
147
150
  let acknowledgedUpdates = {};
148
- let acknowledgeFilter = [];
149
151
 
150
152
  for (let name in updates) {
151
153
  const [newValue, changed] = this.#parameters.set(name, updates[name]);
152
154
  // if `filterChange` is set to `false` we don't check if the value
153
155
  // has been changed or not, it is always propagated to client states
154
- const { event, filterChange, acknowledge } = this.#parameters.getDescription(name);
156
+ const { event, filterChange } = this.#parameters.getDescription(name);
155
157
 
156
158
  // if event type reset internal value to null
157
159
  if (event) {
@@ -160,10 +162,6 @@ class SharedStatePrivate {
160
162
 
161
163
  if ((filterChange && changed) || !filterChange) {
162
164
  acknowledgedUpdates[name] = newValue;
163
-
164
- if (acknowledge === false) {
165
- acknowledgeFilter.push(name);
166
- }
167
165
  }
168
166
  }
169
167
 
@@ -247,18 +245,27 @@ class SharedStatePrivate {
247
245
  }
248
246
  }
249
247
  } else {
250
- // propagate back to the requester that the update has been aborted, ignore all peers
251
- client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, updates);
248
+ // @note - abort messages are only sent back to requester
249
+ const requesterFilteredUpdates = blackListFilterUpdates(updates, acknowledgeFilter);
250
+
251
+ if (Object.keys(requesterFilteredUpdates).length > 0) {
252
+ // propagate back to the requester that the update has been aborted, ignore all peers
253
+ client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, requesterFilteredUpdates);
254
+ }
252
255
  }
253
256
  } else {
254
- // retrieve values from inner state (also handle immediate appropriately)
255
- const oldValues = {};
257
+ // @note - abort messages are only sent back to requester
258
+ // explicitly aborted by hook (return `null`), send back current values to requester
259
+ const currentValues = {};
256
260
 
257
261
  for (let name in updates) {
258
- oldValues[name] = this.#parameters.get(name);
262
+ currentValues[name] = this.#parameters.get(name);
263
+ }
264
+
265
+ const requesterFilteredUpdates = blackListFilterUpdates(currentValues, acknowledgeFilter);
266
+ if (Object.keys(requesterFilteredUpdates).length > 0) {
267
+ client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, requesterFilteredUpdates);
259
268
  }
260
- // aborted by hook (updates have been overridden to {})
261
- client.transport.emit(`${UPDATE_ABORT}-${this.id}-${instanceId}`, reqId, oldValues);
262
269
  }
263
270
  });
264
271
 
@@ -28,6 +28,14 @@ export type stateManagerDeleteObserveCallback = () => any;
28
28
  */
29
29
  /** @private */
30
30
  declare class BaseStateManager {
31
+ /**
32
+ * Validates the given class description.
33
+ *
34
+ * @throws Throws if the class description is invalid
35
+ * @param {*} classDescription
36
+ * @returns undefined
37
+ */
38
+ validateClassDescription(classDescription: any): void;
31
39
  /**
32
40
  * Return a class description from a given class name
33
41
  *
@@ -138,5 +138,6 @@ declare class ParameterBag {
138
138
  getDescription(name?: any): object;
139
139
  getInitValues(): {};
140
140
  getDefaults(): {};
141
+ getParamListByDescriptor(descriptorName: any, descriptorValue: any): string[];
141
142
  #private;
142
143
  }
@@ -1,2 +1,2 @@
1
- declare const _default: "5.3.0";
1
+ declare const _default: "5.4.1";
2
2
  export default _default;