@soundworks/core 5.0.3 → 5.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v5.1.1 - 2025-04-28
2
+
3
+ - Hotfix: run behind https proxy
4
+
5
+ ## v5.1.0 - 2025-02-19
6
+
7
+ - Feat: add SharedStateCollection reduce
8
+
1
9
  ## v5.0.3 - 2025-02-13
2
10
 
3
11
  - Fix: unexpected error when getting description of shared state class with required parameter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "5.0.3",
3
+ "version": "5.1.1",
4
4
  "description": "Open-source creative coding framework for distributed applications based on Web technologies",
5
5
  "collaborators": [
6
6
  "Benjamin Matuszewski",
@@ -61,13 +61,21 @@ class ClientSocket {
61
61
  path = `${this.#config.env.baseUrl}/${path}`;
62
62
  }
63
63
 
64
- const protocol = this.#config.env.useHttps ? 'wss:' : 'ws:';
65
64
  const port = this.#config.env.port;
65
+ let protocol = this.#config.env.useHttps ? 'wss:' : 'ws:';
66
66
  let serverAddress;
67
67
  let webSocketOptions;
68
68
 
69
69
  if (isBrowser()) {
70
70
  const hostname = window.location.hostname;
71
+ // ## Hotfix - 20250428
72
+ // when running behind an https proxy (e.g. nginx) `useHttps` can be false
73
+ // but we need to open the socket in secure protocol
74
+ // This tends to confirm that we need more granularity with this config
75
+ // stuff, there are too much weird edge cases to handle
76
+ if (this.#config.env.useHttps === false && window.location.protocol === 'https:') {
77
+ protocol = 'wss:';
78
+ }
71
79
 
72
80
  if (this.#config.env.serverAddress === '') {
73
81
  serverAddress = hostname;
@@ -471,6 +471,30 @@ class SharedStateCollection {
471
471
  return this.#states.find(func);
472
472
  }
473
473
 
474
+ /**
475
+ * Execute a user-supplied "reducer" callback function on each element of the collection,
476
+ * in order, passing in the return value from the calculation on the preceding element.
477
+ * The final result of running the reducer across all elements of the array is a single value.
478
+ *
479
+ * @template T
480
+ * @param {Function} func - A function to execute for each element in the array.
481
+ * Its return value becomes the value of the accumulator parameter on the next
482
+ * invocation of callbackFn. For the last invocation, the return value becomes
483
+ * the return value of reduce(). The function is called with the following arguments:
484
+ * @param {T} initialValue - A value to which accumulator is initialized the first
485
+ * time the callback is called. If initialValue is specified, callbackFn starts
486
+ * executing with the first value in the array as currentValue.
487
+ * @return {T}
488
+ */
489
+ reduce(func, initialValue) {
490
+ // compared to the native Array.reduce method, initial Value is mandatory
491
+ if (arguments.length < 0) {
492
+ throw new Error(`Cannot execute 'reduce' on 'SharedStateCollection: argument 2 is not defined`);
493
+ }
494
+
495
+ return this.#states.reduce(func, initialValue);
496
+ }
497
+
474
498
  /**
475
499
  * Iterable API, e.g. for use in `for .. of` loops
476
500
  */
@@ -1,2 +1,2 @@
1
1
  // [WARNING] This file is generated, do not edit
2
- export default '5.0.3';
2
+ export default '5.1.1';
@@ -296,6 +296,22 @@ declare class SharedStateCollection {
296
296
  * @return {}
297
297
  */
298
298
  find(func: Function): any;
299
+ /**
300
+ * Execute a user-supplied "reducer" callback function on each element of the collection,
301
+ * in order, passing in the return value from the calculation on the preceding element.
302
+ * The final result of running the reducer across all elements of the array is a single value.
303
+ *
304
+ * @template T
305
+ * @param {Function} func - A function to execute for each element in the array.
306
+ * Its return value becomes the value of the accumulator parameter on the next
307
+ * invocation of callbackFn. For the last invocation, the return value becomes
308
+ * the return value of reduce(). The function is called with the following arguments:
309
+ * @param {T} initialValue - A value to which accumulator is initialized the first
310
+ * time the callback is called. If initialValue is specified, callbackFn starts
311
+ * executing with the first value in the array as currentValue.
312
+ * @return {T}
313
+ */
314
+ reduce<T>(func: Function, initialValue: T, ...args: any[]): T;
299
315
  /** @private */
300
316
  private [kSharedStateCollectionInit];
301
317
  /**
@@ -1,2 +1,2 @@
1
- declare const _default: "5.0.3";
1
+ declare const _default: "5.1.1";
2
2
  export default _default;