@lat-murmeldjur/weeb_3 0.0.352001 → 0.0.353001

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/README.md CHANGED
@@ -33,6 +33,8 @@ The higher-level `Weeb3No103` interface provides the main methods used by the em
33
33
  - `uploadWithRedundancy(file, encryption, redundancy_level, index_string, add_to_feed, feed_topic)`
34
34
  - `postUploadBytesWithRedundancy(bytes, mime, filename, encryption, redundancy_level, add_to_feed, feed_topic)`
35
35
  - `attachStream(media, owner, topic, start)`
36
+ - `streamQuality(media)` and `setStreamQuality(media, level)`
37
+ - `connectionCount()`
36
38
  - `renderInterface(container)`
37
39
  - `resetStamp()`
38
40
  - `postPushChunk(data, soc, chunk_address, stamp)`
@@ -95,6 +97,25 @@ await node.attachStream(video, owner, topic, "live");
95
97
 
96
98
  Public HLS feeds use mainnet. The embedding page must be below the `/weeb-3/` scope and serve the packaged worker at `/weeb-3/service.js`, or already be controlled by a worker implementing the same forwarding protocol.
97
99
 
100
+ `streamQuality(video)` returns the available `levels` (`level`, `width`, `height`, and `bitrate`), the requested `selectedLevel`, and the playing `currentLevel`. Levels become available after the master playlist loads. A selected level of `-1` means Auto; a current level of `-1` means no rendition is playing yet. The highest available resolution is the initial selection. Quality controls require an attached hls.js stream; native HLS is unsupported, and switching during a history seek is temporarily unavailable.
101
+
102
+ For example, your application's periodic monitor can lower resolution when too few peers are connected:
103
+
104
+ ```js
105
+ async function reduceResolutionBelow(minimumConnections) {
106
+ if (await node.connectionCount() >= minimumConnections) return;
107
+ const { levels, selectedLevel, currentLevel } = node.streamQuality(video);
108
+ if (selectedLevel >= 0 && selectedLevel !== currentLevel) return;
109
+ const current = levels.find(({ level }) => level === currentLevel);
110
+ if (!current) return;
111
+ const lower = levels.filter(({ height }) => height > 0 && height < current.height)
112
+ .sort((a, b) => b.height - a.height || b.bitrate - a.bitrate)[0];
113
+ if (lower) node.setStreamQuality(video, lower.level);
114
+ }
115
+ ```
116
+
117
+ The host chooses the threshold and monitoring interval; the library adds no poller. `setStreamQuality` accepts a request synchronously through the built-in selector's switching path; `currentLevel` reports when the switch takes effect. Pass `-1` to restore Auto. `connectionCount()` reads the shared worker's connected peer count without requesting logs or progress; worker communication failures reject its promise.
118
+
98
119
  ## Example corresponding to `example.html`
99
120
 
100
121
  This is a compact npm-import form of the same usage pattern shown in the project's `example.html`:
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@lat-murmeldjur/weeb_3",
3
3
  "type": "module",
4
4
  "description": "A Swarm client for browsers",
5
- "version": "0.0.352001",
5
+ "version": "0.0.353001",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/service.js CHANGED
@@ -621,9 +621,9 @@ function createRustRangeStream(
621
621
  };
622
622
 
623
623
  const drainScheduledRanges = () => {
624
- return Promise.allSettled(Array.from(scheduled.values())).then(() => {
625
- scheduled.clear();
626
- });
624
+ const pending = Array.from(scheduled.values(), request => request.then(() => {}));
625
+ scheduled.clear();
626
+ return Promise.allSettled(pending);
627
627
  };
628
628
 
629
629
  const failStream = async (controller, error) => {
package/weeb_3.d.ts CHANGED
@@ -4,6 +4,11 @@
4
4
  /** Bee-compatible erasure-coding level used for uploads. */
5
5
  export type UploadRedundancyLevel = 0 | 1 | 2 | 3 | 4;
6
6
  export type HlsStart = "beginning" | "live";
7
+ export interface StreamQuality {
8
+ levels: { level: number; width: number; height: number; bitrate: number }[];
9
+ selectedLevel: number;
10
+ currentLevel: number;
11
+ }
7
12
 
8
13
 
9
14
 
@@ -25,6 +30,7 @@ export class Weeb3No103 {
25
30
  attachStream(media: HTMLMediaElement, owner: string, topic: string, start: HlsStart): Promise<void>;
26
31
  batchState(depth: number, validity_days: number): Promise<object>;
27
32
  buyBatch(depth: number, validity_days: number): Promise<object>;
33
+ connectionCount(): Promise<number>;
28
34
  deployChequebook(): Promise<object>;
29
35
  depositChequebook(amount: string): Promise<object>;
30
36
  logs(): Promise<Array<any>>;
@@ -48,7 +54,9 @@ export class Weeb3No103 {
48
54
  retrieve(address: string): Promise<Array<any>>;
49
55
  retrieveBytes(address: string): Promise<Uint8Array>;
50
56
  retrieveChunk(address: string): Promise<Uint8Array>;
57
+ setStreamQuality(media: HTMLMediaElement, level: number): void;
51
58
  start(options?: any | null): void;
59
+ streamQuality(media: HTMLMediaElement): StreamQuality;
52
60
  switchNetwork(mode: string): Promise<object>;
53
61
  upload(file: File, encryption: boolean, index_string: string, add_to_feed: boolean, feed_topic: string): Promise<object>;
54
62
  uploadWithRedundancy(file: File, encryption: boolean, redundancy_level: UploadRedundancyLevel, index_string: string, add_to_feed: boolean, feed_topic: string, wallet_owner?: string | null): Promise<object>;
@@ -75,6 +83,7 @@ export interface InitOutput {
75
83
  readonly weeb3no103_attachStream: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
76
84
  readonly weeb3no103_batchState: (a: number, b: number, c: number) => any;
77
85
  readonly weeb3no103_buyBatch: (a: number, b: number, c: number) => any;
86
+ readonly weeb3no103_connectionCount: (a: number) => any;
78
87
  readonly weeb3no103_deployChequebook: (a: number) => any;
79
88
  readonly weeb3no103_depositChequebook: (a: number, b: number, c: number) => any;
80
89
  readonly weeb3no103_logs: (a: number) => any;
@@ -92,7 +101,9 @@ export interface InitOutput {
92
101
  readonly weeb3no103_retrieve: (a: number, b: number, c: number) => any;
93
102
  readonly weeb3no103_retrieveBytes: (a: number, b: number, c: number) => any;
94
103
  readonly weeb3no103_retrieveChunk: (a: number, b: number, c: number) => any;
104
+ readonly weeb3no103_setStreamQuality: (a: number, b: any, c: number) => [number, number];
95
105
  readonly weeb3no103_start: (a: number, b: number) => void;
106
+ readonly weeb3no103_streamQuality: (a: number, b: any) => [number, number, number];
96
107
  readonly weeb3no103_switchNetwork: (a: number, b: number, c: number) => any;
97
108
  readonly weeb3no103_upload: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
98
109
  readonly weeb3no103_uploadWithRedundancy: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => any;
package/weeb_3.js CHANGED
@@ -104,6 +104,13 @@ export class Weeb3No103 {
104
104
  const ret = wasm.weeb3no103_buyBatch(this.__wbg_ptr, depth, validity_days);
105
105
  return ret;
106
106
  }
107
+ /**
108
+ * @returns {Promise<number>}
109
+ */
110
+ connectionCount() {
111
+ const ret = wasm.weeb3no103_connectionCount(this.__wbg_ptr);
112
+ return ret;
113
+ }
107
114
  /**
108
115
  * @returns {Promise<object>}
109
116
  */
@@ -290,12 +297,33 @@ export class Weeb3No103 {
290
297
  const ret = wasm.weeb3no103_retrieveChunk(this.__wbg_ptr, ptr0, len0);
291
298
  return ret;
292
299
  }
300
+ /**
301
+ * @param {HTMLMediaElement} media
302
+ * @param {number} level
303
+ */
304
+ setStreamQuality(media, level) {
305
+ const ret = wasm.weeb3no103_setStreamQuality(this.__wbg_ptr, media, level);
306
+ if (ret[1]) {
307
+ throw takeFromExternrefTable0(ret[0]);
308
+ }
309
+ }
293
310
  /**
294
311
  * @param {any | null} [options]
295
312
  */
296
313
  start(options) {
297
314
  wasm.weeb3no103_start(this.__wbg_ptr, isLikeNone(options) ? 0 : addToExternrefTable0(options));
298
315
  }
316
+ /**
317
+ * @param {HTMLMediaElement} media
318
+ * @returns {StreamQuality}
319
+ */
320
+ streamQuality(media) {
321
+ const ret = wasm.weeb3no103_streamQuality(this.__wbg_ptr, media);
322
+ if (ret[2]) {
323
+ throw takeFromExternrefTable0(ret[1]);
324
+ }
325
+ return takeFromExternrefTable0(ret[0]);
326
+ }
299
327
  /**
300
328
  * @param {string} mode
301
329
  * @returns {Promise<object>}
@@ -523,7 +551,7 @@ function __wbg_get_imports() {
523
551
  const ret = Object.assign(arg0, arg1);
524
552
  return ret;
525
553
  },
526
- __wbg_attachMedia_82d779df2fa8e98f: function() { return handleError(function (arg0, arg1) {
554
+ __wbg_attachMedia_ff18e7736d1de028: function() { return handleError(function (arg0, arg1) {
527
555
  arg0.attachMedia(arg1);
528
556
  }, arguments); },
529
557
  __wbg_autoplay_f8612a2035bfaa92: function(arg0) {
@@ -663,6 +691,10 @@ function __wbg_get_imports() {
663
691
  __wbg_detachMedia_2925e924ea346816: function() { return handleError(function (arg0) {
664
692
  arg0.detachMedia();
665
693
  }, arguments); },
694
+ __wbg_disabled_462f1ecf16417bb3: function(arg0) {
695
+ const ret = arg0.disabled;
696
+ return ret;
697
+ },
666
698
  __wbg_document_ee35a3d3ae34ef6c: function(arg0) {
667
699
  const ret = arg0.document;
668
700
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
@@ -1713,6 +1745,10 @@ function __wbg_get_imports() {
1713
1745
  const ret = arg0.transaction;
1714
1746
  return ret;
1715
1747
  },
1748
+ __wbg_transferMedia_1de6dcda4eba6934: function() { return handleError(function (arg0) {
1749
+ const ret = arg0.transferMedia();
1750
+ return ret;
1751
+ }, arguments); },
1716
1752
  __wbg_type_4edffca24c42b74d: function(arg0, arg1) {
1717
1753
  const ret = arg1.type;
1718
1754
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -1757,37 +1793,37 @@ function __wbg_get_imports() {
1757
1793
  console.warn(arg0);
1758
1794
  },
1759
1795
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1760
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [Externref, Externref], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1796
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 2, function: Function { arguments: [Externref, Externref], shim_idx: 3, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1761
1797
  const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__Fn__wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue___Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue_____);
1762
1798
  return ret;
1763
1799
  },
1764
1800
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1765
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [Externref, String], shim_idx: 34, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: false }) -> Externref`.
1801
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 2, function: Function { arguments: [Externref, String], shim_idx: 34, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: false }) -> Externref`.
1766
1802
  const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__Fn__wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue___Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_2fc1ddd1063c2c6b___JsValue__);
1767
1803
  return ret;
1768
1804
  },
1769
1805
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1770
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 38, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1806
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 2, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 38, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1771
1807
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__Fn__wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue___Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___web_sys_672975c58fd3dbc7___features__gen_IdbVersionChangeEvent__IdbVersionChangeEvent__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_2fc1ddd1063c2c6b___JsValue__);
1772
1808
  return ret;
1773
1809
  },
1774
1810
  __wbindgen_cast_0000000000000004: function(arg0, arg1) {
1775
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 36, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1811
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 2, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 36, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1776
1812
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__Fn__wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue___Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___web_sys_672975c58fd3dbc7___features__gen_MessageEvent__MessageEvent_____);
1777
1813
  return ret;
1778
1814
  },
1779
1815
  __wbindgen_cast_0000000000000005: function(arg0, arg1) {
1780
- // Cast intrinsic for `Closure(Closure { dtor_idx: 6, function: Function { arguments: [Externref], shim_idx: 7, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1816
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 5, function: Function { arguments: [Externref], shim_idx: 6, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1781
1817
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__FnMut__wasm_bindgen_2fc1ddd1063c2c6b___JsValue____Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue_____);
1782
1818
  return ret;
1783
1819
  },
1784
1820
  __wbindgen_cast_0000000000000006: function(arg0, arg1) {
1785
- // Cast intrinsic for `Closure(Closure { dtor_idx: 6, function: Function { arguments: [NamedExternref("Event")], shim_idx: 7, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1821
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 5, function: Function { arguments: [NamedExternref("Event")], shim_idx: 6, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1786
1822
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__FnMut__wasm_bindgen_2fc1ddd1063c2c6b___JsValue____Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue_____);
1787
1823
  return ret;
1788
1824
  },
1789
1825
  __wbindgen_cast_0000000000000007: function(arg0, arg1) {
1790
- // Cast intrinsic for `Closure(Closure { dtor_idx: 6, function: Function { arguments: [], shim_idx: 97, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1826
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 5, function: Function { arguments: [], shim_idx: 97, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1791
1827
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__FnMut__wasm_bindgen_2fc1ddd1063c2c6b___JsValue____Output_______, wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke______);
1792
1828
  return ret;
1793
1829
  },
package/weeb_3_bg.wasm CHANGED
Binary file
@@ -8,6 +8,7 @@ export const weeb3no103_acquireFeedBytes: (a: number, b: number, c: number, d: n
8
8
  export const weeb3no103_attachStream: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
9
9
  export const weeb3no103_batchState: (a: number, b: number, c: number) => any;
10
10
  export const weeb3no103_buyBatch: (a: number, b: number, c: number) => any;
11
+ export const weeb3no103_connectionCount: (a: number) => any;
11
12
  export const weeb3no103_deployChequebook: (a: number) => any;
12
13
  export const weeb3no103_depositChequebook: (a: number, b: number, c: number) => any;
13
14
  export const weeb3no103_logs: (a: number) => any;
@@ -25,7 +26,9 @@ export const weeb3no103_resetStamp: (a: number) => any;
25
26
  export const weeb3no103_retrieve: (a: number, b: number, c: number) => any;
26
27
  export const weeb3no103_retrieveBytes: (a: number, b: number, c: number) => any;
27
28
  export const weeb3no103_retrieveChunk: (a: number, b: number, c: number) => any;
29
+ export const weeb3no103_setStreamQuality: (a: number, b: any, c: number) => [number, number];
28
30
  export const weeb3no103_start: (a: number, b: number) => void;
31
+ export const weeb3no103_streamQuality: (a: number, b: any) => [number, number, number];
29
32
  export const weeb3no103_switchNetwork: (a: number, b: number, c: number) => any;
30
33
  export const weeb3no103_upload: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
31
34
  export const weeb3no103_uploadWithRedundancy: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => any;