@moq/net 0.1.9 → 0.2.0

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.
Files changed (252) hide show
  1. package/announced.d.ts +40 -24
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js +74 -40
  4. package/announced.js.map +1 -1
  5. package/announced.test.d.ts +2 -0
  6. package/announced.test.d.ts.map +1 -0
  7. package/announced.test.js +37 -0
  8. package/announced.test.js.map +1 -0
  9. package/broadcast.d.ts +80 -25
  10. package/broadcast.d.ts.map +1 -1
  11. package/broadcast.js +266 -49
  12. package/broadcast.js.map +1 -1
  13. package/broadcast.test.d.ts +2 -0
  14. package/broadcast.test.d.ts.map +1 -0
  15. package/broadcast.test.js +219 -0
  16. package/broadcast.test.js.map +1 -0
  17. package/connection/accept.d.ts +6 -0
  18. package/connection/accept.d.ts.map +1 -1
  19. package/connection/accept.js +30 -10
  20. package/connection/accept.js.map +1 -1
  21. package/connection/browser.d.ts +5 -0
  22. package/connection/browser.d.ts.map +1 -0
  23. package/connection/browser.js +25 -0
  24. package/connection/browser.js.map +1 -0
  25. package/connection/browser.test.d.ts +2 -0
  26. package/connection/browser.test.d.ts.map +1 -0
  27. package/connection/browser.test.js +29 -0
  28. package/connection/browser.test.js.map +1 -0
  29. package/connection/connect.d.ts +43 -1
  30. package/connection/connect.d.ts.map +1 -1
  31. package/connection/connect.js +96 -107
  32. package/connection/connect.js.map +1 -1
  33. package/connection/connect.test.d.ts +2 -0
  34. package/connection/connect.test.d.ts.map +1 -0
  35. package/connection/connect.test.js +118 -0
  36. package/connection/connect.test.js.map +1 -0
  37. package/connection/established.d.ts +29 -15
  38. package/connection/established.d.ts.map +1 -1
  39. package/connection/established.js.map +1 -1
  40. package/connection/index.d.ts +8 -0
  41. package/connection/index.d.ts.map +1 -1
  42. package/connection/index.js +6 -0
  43. package/connection/index.js.map +1 -1
  44. package/connection/reload.d.ts +43 -7
  45. package/connection/reload.d.ts.map +1 -1
  46. package/connection/reload.js +159 -62
  47. package/connection/reload.js.map +1 -1
  48. package/connection/reload.test.js +65 -0
  49. package/connection/reload.test.js.map +1 -1
  50. package/connection/stats.d.ts +92 -0
  51. package/connection/stats.d.ts.map +1 -0
  52. package/connection/stats.js +35 -0
  53. package/connection/stats.js.map +1 -0
  54. package/connection/stats.test.d.ts +2 -0
  55. package/connection/stats.test.d.ts.map +1 -0
  56. package/connection/stats.test.js +120 -0
  57. package/connection/stats.test.js.map +1 -0
  58. package/connection/transport.d.ts +10 -0
  59. package/connection/transport.d.ts.map +1 -0
  60. package/connection/transport.js +12 -0
  61. package/connection/transport.js.map +1 -0
  62. package/consume.d.ts +26 -0
  63. package/consume.d.ts.map +1 -0
  64. package/consume.js +40 -0
  65. package/consume.js.map +1 -0
  66. package/datagram.d.ts +23 -0
  67. package/datagram.d.ts.map +1 -0
  68. package/datagram.js +3 -0
  69. package/datagram.js.map +1 -0
  70. package/group.d.ts +125 -36
  71. package/group.d.ts.map +1 -1
  72. package/group.js +244 -67
  73. package/group.js.map +1 -1
  74. package/group.test.js +121 -35
  75. package/group.test.js.map +1 -1
  76. package/ietf/adapter.d.ts +2 -2
  77. package/ietf/adapter.d.ts.map +1 -1
  78. package/ietf/adapter.js +15 -5
  79. package/ietf/adapter.js.map +1 -1
  80. package/ietf/connection.d.ts +19 -6
  81. package/ietf/connection.d.ts.map +1 -1
  82. package/ietf/connection.js +23 -8
  83. package/ietf/connection.js.map +1 -1
  84. package/ietf/ietf.test.js +58 -1
  85. package/ietf/ietf.test.js.map +1 -1
  86. package/ietf/object.d.ts +12 -4
  87. package/ietf/object.d.ts.map +1 -1
  88. package/ietf/object.js +92 -9
  89. package/ietf/object.js.map +1 -1
  90. package/ietf/publisher.d.ts +2 -2
  91. package/ietf/publisher.d.ts.map +1 -1
  92. package/ietf/publisher.js +12 -12
  93. package/ietf/publisher.js.map +1 -1
  94. package/ietf/subscribe_namespace.d.ts +0 -4
  95. package/ietf/subscribe_namespace.d.ts.map +1 -1
  96. package/ietf/subscribe_namespace.js +0 -5
  97. package/ietf/subscribe_namespace.js.map +1 -1
  98. package/ietf/subscriber.d.ts +8 -4
  99. package/ietf/subscriber.d.ts.map +1 -1
  100. package/ietf/subscriber.js +171 -93
  101. package/ietf/subscriber.js.map +1 -1
  102. package/index.d.ts +8 -5
  103. package/index.d.ts.map +1 -1
  104. package/index.js +8 -5
  105. package/index.js.map +1 -1
  106. package/integration.test.js +598 -12
  107. package/integration.test.js.map +1 -1
  108. package/internal.d.ts +14 -0
  109. package/internal.d.ts.map +1 -0
  110. package/internal.js +8 -0
  111. package/internal.js.map +1 -0
  112. package/lite/announce.d.ts +55 -13
  113. package/lite/announce.d.ts.map +1 -1
  114. package/lite/announce.js +221 -68
  115. package/lite/announce.js.map +1 -1
  116. package/lite/announce.test.d.ts +2 -0
  117. package/lite/announce.test.d.ts.map +1 -0
  118. package/lite/announce.test.js +71 -0
  119. package/lite/announce.test.js.map +1 -0
  120. package/lite/connection.d.ts +45 -19
  121. package/lite/connection.d.ts.map +1 -1
  122. package/lite/connection.js +85 -80
  123. package/lite/connection.js.map +1 -1
  124. package/lite/datagram.d.ts +23 -0
  125. package/lite/datagram.d.ts.map +1 -0
  126. package/lite/datagram.js +57 -0
  127. package/lite/datagram.js.map +1 -0
  128. package/lite/datagram.test.d.ts +2 -0
  129. package/lite/datagram.test.d.ts.map +1 -0
  130. package/lite/datagram.test.js +26 -0
  131. package/lite/datagram.test.js.map +1 -0
  132. package/lite/datagram_stream.d.ts +8 -0
  133. package/lite/datagram_stream.d.ts.map +1 -0
  134. package/lite/datagram_stream.js +44 -0
  135. package/lite/datagram_stream.js.map +1 -0
  136. package/lite/datagram_stream.test.d.ts +2 -0
  137. package/lite/datagram_stream.test.d.ts.map +1 -0
  138. package/lite/datagram_stream.test.js +15 -0
  139. package/lite/datagram_stream.test.js.map +1 -0
  140. package/lite/fetch.d.ts.map +1 -1
  141. package/lite/fetch.js +2 -2
  142. package/lite/fetch.js.map +1 -1
  143. package/lite/fetch.test.d.ts +2 -0
  144. package/lite/fetch.test.d.ts.map +1 -0
  145. package/lite/fetch.test.js +41 -0
  146. package/lite/fetch.test.js.map +1 -0
  147. package/lite/index.d.ts +3 -0
  148. package/lite/index.d.ts.map +1 -1
  149. package/lite/index.js +3 -0
  150. package/lite/index.js.map +1 -1
  151. package/lite/publisher.d.ts +13 -6
  152. package/lite/publisher.d.ts.map +1 -1
  153. package/lite/publisher.js +274 -64
  154. package/lite/publisher.js.map +1 -1
  155. package/lite/publisher.test.d.ts +2 -0
  156. package/lite/publisher.test.d.ts.map +1 -0
  157. package/lite/publisher.test.js +65 -0
  158. package/lite/publisher.test.js.map +1 -0
  159. package/lite/setup.d.ts +72 -6
  160. package/lite/setup.d.ts.map +1 -1
  161. package/lite/setup.js +184 -31
  162. package/lite/setup.js.map +1 -1
  163. package/lite/setup.test.d.ts +2 -0
  164. package/lite/setup.test.d.ts.map +1 -0
  165. package/lite/setup.test.js +122 -0
  166. package/lite/setup.test.js.map +1 -0
  167. package/lite/stream.d.ts +12 -3
  168. package/lite/stream.d.ts.map +1 -1
  169. package/lite/stream.js +7 -4
  170. package/lite/stream.js.map +1 -1
  171. package/lite/subscribe.d.ts +37 -23
  172. package/lite/subscribe.d.ts.map +1 -1
  173. package/lite/subscribe.js +70 -55
  174. package/lite/subscribe.js.map +1 -1
  175. package/lite/subscribe.test.d.ts +2 -0
  176. package/lite/subscribe.test.d.ts.map +1 -0
  177. package/lite/subscribe.test.js +68 -0
  178. package/lite/subscribe.test.js.map +1 -0
  179. package/lite/subscriber.d.ts +24 -17
  180. package/lite/subscriber.d.ts.map +1 -1
  181. package/lite/subscriber.js +515 -90
  182. package/lite/subscriber.js.map +1 -1
  183. package/lite/subscriber.test.js +2 -2
  184. package/lite/subscriber.test.js.map +1 -1
  185. package/lite/track.d.ts +25 -13
  186. package/lite/track.d.ts.map +1 -1
  187. package/lite/track.js +60 -35
  188. package/lite/track.js.map +1 -1
  189. package/lite/track.test.js +12 -10
  190. package/lite/track.test.js.map +1 -1
  191. package/lite/version.d.ts +17 -4
  192. package/lite/version.d.ts.map +1 -1
  193. package/lite/version.js +88 -17
  194. package/lite/version.js.map +1 -1
  195. package/mock.d.ts +42 -3
  196. package/mock.d.ts.map +1 -1
  197. package/mock.js +88 -17
  198. package/mock.js.map +1 -1
  199. package/package.json +3 -3
  200. package/path.d.ts +30 -0
  201. package/path.d.ts.map +1 -1
  202. package/path.js +49 -0
  203. package/path.js.map +1 -1
  204. package/path.test.js +41 -0
  205. package/path.test.js.map +1 -1
  206. package/stream.test.js +10 -0
  207. package/stream.test.js.map +1 -1
  208. package/time.d.ts +109 -86
  209. package/time.d.ts.map +1 -1
  210. package/time.js +80 -30
  211. package/time.js.map +1 -1
  212. package/time.test.d.ts +2 -0
  213. package/time.test.d.ts.map +1 -0
  214. package/time.test.js +12 -0
  215. package/time.test.js.map +1 -0
  216. package/track.d.ts +225 -45
  217. package/track.d.ts.map +1 -1
  218. package/track.js +505 -93
  219. package/track.js.map +1 -1
  220. package/track.test.js +138 -29
  221. package/track.test.js.map +1 -1
  222. package/util/error.d.ts +9 -0
  223. package/util/error.d.ts.map +1 -1
  224. package/util/error.js +21 -0
  225. package/util/error.js.map +1 -1
  226. package/util/error.test.d.ts +2 -0
  227. package/util/error.test.d.ts.map +1 -0
  228. package/util/error.test.js +45 -0
  229. package/util/error.test.js.map +1 -0
  230. package/util/index.d.ts +1 -0
  231. package/util/index.d.ts.map +1 -1
  232. package/util/index.js +1 -0
  233. package/util/index.js.map +1 -1
  234. package/util/timeout.d.ts +5 -0
  235. package/util/timeout.d.ts.map +1 -0
  236. package/util/timeout.js +18 -0
  237. package/util/timeout.js.map +1 -0
  238. package/util/timeout.test.d.ts +2 -0
  239. package/util/timeout.test.d.ts.map +1 -0
  240. package/util/timeout.test.js +18 -0
  241. package/util/timeout.test.js.map +1 -0
  242. package/varint.d.ts +6 -0
  243. package/varint.d.ts.map +1 -1
  244. package/varint.js +6 -2
  245. package/varint.js.map +1 -1
  246. package/zod.d.ts +4 -4
  247. package/zod.d.ts.map +1 -1
  248. package/zod.js.map +1 -1
  249. package/bandwidth.d.ts +0 -11
  250. package/bandwidth.d.ts.map +0 -1
  251. package/bandwidth.js +0 -7
  252. package/bandwidth.js.map +0 -1
package/time.js CHANGED
@@ -1,12 +1,14 @@
1
1
  /* @ts-self-types="./time.d.ts" */
2
2
  /**
3
- * Constructors, conversions, and arithmetic for {@link Nano} values.
3
+ * Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions,
4
+ * plus {@link Timescale} and {@link Timestamp} for presentation timing.
4
5
  *
5
- * Calling `Nano(x)` brands a raw number as nanoseconds. The unit is the caller's
6
- * assertion: no conversion happens, so reach for `fromMicro`/`fromMilli`/`fromSecond`
7
- * when the source has a unit.
6
+ * @module
8
7
  */
9
- export const Nano = {
8
+ /** Constructors, conversions, and arithmetic for {@link Nano} values. */
9
+ // Calling `Nano(x)` brands a raw number as nanoseconds. The unit is the caller's assertion: no
10
+ // conversion happens, so reach for `fromMicro`/`fromMilli`/`fromSecond` when the source has a unit.
11
+ export const Nano = Object.assign((value) => value, {
10
12
  zero: 0,
11
13
  fromMicro: (us) => (us * 1_000),
12
14
  fromMilli: (ms) => (ms * 1_000_000),
@@ -21,15 +23,11 @@ export const Nano = {
21
23
  div: (a, b) => (a / b),
22
24
  max: (a, b) => Math.max(a, b),
23
25
  min: (a, b) => Math.min(a, b),
24
- };
25
- /**
26
- * Constructors, conversions, and arithmetic for {@link Micro} values.
27
- *
28
- * Calling `Micro(x)` brands a raw number as microseconds. This asserts the unit
29
- * rather than converting, so use `fromNano`/`fromMilli`/`fromSecond` to convert
30
- * from another unit.
31
- */
32
- export const Micro = {
26
+ });
27
+ /** Constructors, conversions, and arithmetic for {@link Micro} values. */
28
+ // Calling `Micro(x)` brands a raw number as microseconds. See the `Nano` note: this asserts the unit
29
+ // rather than converting, so use `fromNano`/`fromMilli`/`fromSecond` to convert from another unit.
30
+ export const Micro = Object.assign((value) => value, {
33
31
  zero: 0,
34
32
  fromNano: (ns) => (ns / 1_000),
35
33
  fromMilli: (ms) => (ms * 1_000),
@@ -44,15 +42,11 @@ export const Micro = {
44
42
  div: (a, b) => (a / b),
45
43
  max: (a, b) => Math.max(a, b),
46
44
  min: (a, b) => Math.min(a, b),
47
- };
48
- /**
49
- * Constructors, conversions, and arithmetic for {@link Milli} values.
50
- *
51
- * Calling `Milli(x)` brands a raw number as milliseconds. This asserts the unit
52
- * rather than converting, so use `fromNano`/`fromMicro`/`fromSecond` to convert
53
- * from another unit.
54
- */
55
- export const Milli = {
45
+ });
46
+ /** Constructors, conversions, and arithmetic for {@link Milli} values. */
47
+ // Calling `Milli(x)` brands a raw number as milliseconds. See the `Nano` note: this asserts the unit
48
+ // rather than converting, so use `fromNano`/`fromMicro`/`fromSecond` to convert from another unit.
49
+ export const Milli = Object.assign((value) => value, {
56
50
  zero: 0,
57
51
  fromNano: (ns) => (ns / 1_000_000),
58
52
  fromMicro: (us) => (us / 1_000),
@@ -67,15 +61,71 @@ export const Milli = {
67
61
  div: (a, b) => (a / b),
68
62
  max: (a, b) => Math.max(a, b),
69
63
  min: (a, b) => Math.min(a, b),
70
- };
64
+ });
65
+ /** Named timescales and a checked constructor (rejects non-positive / non-integer values). */
66
+ export const Timescale = Object.assign((unitsPerSecond) => {
67
+ if (!Number.isInteger(unitsPerSecond) || unitsPerSecond <= 0) {
68
+ throw new Error(`invalid timescale: ${unitsPerSecond}`);
69
+ }
70
+ return unitsPerSecond;
71
+ }, {
72
+ /** One unit per second. */
73
+ SECOND: 1,
74
+ /** 1,000 units per second. */
75
+ MILLI: 1_000,
76
+ /** 1,000,000 units per second. */
77
+ MICRO: 1_000_000,
78
+ /** 1,000,000,000 units per second. */
79
+ NANO: 1_000_000_000,
80
+ });
71
81
  /**
72
- * Constructors, conversions, and arithmetic for {@link Second} values.
82
+ * A presentation timestamp: a raw value in a given {@link Timescale}.
73
83
  *
74
- * Calling `Second(x)` brands a raw number as seconds. This asserts the unit
75
- * rather than converting, so use `fromNano`/`fromMicro`/`fromMilli` to convert
76
- * from another unit.
84
+ * Mirrors the Rust `Timestamp`. Unlike the bare `Milli`/`Micro` aliases it carries its
85
+ * own scale, so a track can pick its units and conversions can't silently mix them up.
77
86
  */
78
- export const Second = {
87
+ export class Timestamp {
88
+ /** The raw value, in `scale` units. */
89
+ value;
90
+ /** Units per second the {@link value} is measured in. */
91
+ scale;
92
+ /** Build a timestamp of `value` units at `scale`. */
93
+ constructor(value, scale) {
94
+ if (!Number.isFinite(value) || value < 0) {
95
+ throw new Error(`invalid timestamp: ${value}`);
96
+ }
97
+ this.value = value;
98
+ this.scale = scale;
99
+ }
100
+ /** Monotonic now (`performance.now()`, milliseconds since page load), not wall-clock time. */
101
+ static now() {
102
+ return new Timestamp(performance.now(), Timescale.MILLI);
103
+ }
104
+ /** A timestamp of `ms` milliseconds. */
105
+ static fromMillis(ms) {
106
+ return new Timestamp(ms, Timescale.MILLI);
107
+ }
108
+ /** A timestamp of `us` microseconds. */
109
+ static fromMicros(us) {
110
+ return new Timestamp(us, Timescale.MICRO);
111
+ }
112
+ /** This timestamp's value re-expressed at `scale` (a raw number, not a new Timestamp). */
113
+ as(scale) {
114
+ return scale === this.scale ? this.value : (this.value * scale) / this.scale;
115
+ }
116
+ /** The value in milliseconds. */
117
+ asMillis() {
118
+ return this.as(Timescale.MILLI);
119
+ }
120
+ /** The value in microseconds. */
121
+ asMicros() {
122
+ return this.as(Timescale.MICRO);
123
+ }
124
+ }
125
+ /** Constructors, conversions, and arithmetic for {@link Second} values. */
126
+ // Calling `Second(x)` brands a raw number as seconds. See the `Nano` note: this asserts the unit
127
+ // rather than converting, so use `fromNano`/`fromMicro`/`fromMilli` to convert from another unit.
128
+ export const Second = Object.assign((value) => value, {
79
129
  zero: 0,
80
130
  fromNano: (ns) => (ns / 1_000_000_000),
81
131
  fromMicro: (us) => (us / 1_000_000),
@@ -90,5 +140,5 @@ export const Second = {
90
140
  div: (a, b) => (a / b),
91
141
  max: (a, b) => Math.max(a, b),
92
142
  min: (a, b) => Math.min(a, b),
93
- };
143
+ });
94
144
  //# sourceMappingURL=time.js.map
package/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IACnB,IAAI,EAAE,CAAS;IACf,SAAS,EAAE,CAAC,EAAS,EAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAS;IACpD,SAAS,EAAE,CAAC,EAAS,EAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,CAAS;IACxD,UAAU,EAAE,CAAC,CAAS,EAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,aAAa,CAAS;IAC5D,OAAO,EAAE,CAAC,EAAQ,EAAS,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAU;IACnD,OAAO,EAAE,CAAC,EAAQ,EAAS,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,CAAU;IACvD,QAAQ,EAAE,CAAC,EAAQ,EAAU,EAAE,CAAC,CAAC,EAAE,GAAG,aAAa,CAAW;IAC9D,GAAG,EAAE,GAAS,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAS;IACxD,GAAG,EAAE,CAAC,CAAO,EAAE,CAAO,EAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAS;IAChD,GAAG,EAAE,CAAC,CAAO,EAAE,CAAO,EAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAS;IAChD,GAAG,EAAE,CAAC,CAAO,EAAE,CAAS,EAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAS;IAClD,GAAG,EAAE,CAAC,CAAO,EAAE,CAAS,EAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAS;IAClD,GAAG,EAAE,CAAC,CAAO,EAAE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U,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAW;IAC/D,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAW;CACtD,CAAC","sourcesContent":["/** A duration in nanoseconds, branded so it can't be mixed with other units. */\nexport type Nano = number & { readonly _brand: \"nano\" };\n\n/**\n * Constructors, conversions, and arithmetic for {@link Nano} values.\n *\n * Calling `Nano(x)` brands a raw number as nanoseconds. The unit is the caller's\n * assertion: no conversion happens, so reach for `fromMicro`/`fromMilli`/`fromSecond`\n * when the source has a unit.\n */\nexport const Nano = {\n\tzero: 0 as Nano,\n\tfromMicro: (us: Micro): Nano => (us * 1_000) as Nano,\n\tfromMilli: (ms: Milli): Nano => (ms * 1_000_000) as Nano,\n\tfromSecond: (s: Second): Nano => (s * 1_000_000_000) as Nano,\n\ttoMicro: (ns: Nano): Micro => (ns / 1_000) as Micro,\n\ttoMilli: (ns: Nano): Milli => (ns / 1_000_000) as Milli,\n\ttoSecond: (ns: Nano): Second => (ns / 1_000_000_000) as Second,\n\tnow: (): Nano => (performance.now() * 1_000_000) as Nano,\n\tadd: (a: Nano, b: Nano): Nano => (a + b) as Nano,\n\tsub: (a: Nano, b: Nano): Nano => (a - b) as Nano,\n\tmul: (a: Nano, b: number): Nano => (a * b) as Nano,\n\tdiv: (a: Nano, b: number): Nano => (a / b) as Nano,\n\tmax: (a: Nano, b: Nano): Nano => Math.max(a, b) as Nano,\n\tmin: (a: Nano, b: Nano): Nano => Math.min(a, b) as Nano,\n} as const;\n\n/** A duration in microseconds, branded so it can't be mixed with other units. */\nexport type Micro = number & { readonly _brand: \"micro\" };\n\n/**\n * Constructors, conversions, and arithmetic for {@link Micro} values.\n *\n * Calling `Micro(x)` brands a raw number as microseconds. This asserts the unit\n * rather than converting, so use `fromNano`/`fromMilli`/`fromSecond` to convert\n * from another unit.\n */\nexport const Micro = {\n\tzero: 0 as Micro,\n\tfromNano: (ns: Nano): Micro => (ns / 1_000) as Micro,\n\tfromMilli: (ms: Milli): Micro => (ms * 1_000) as Micro,\n\tfromSecond: (s: Second): Micro => (s * 1_000_000) as Micro,\n\ttoNano: (us: Micro): Nano => (us * 1_000) as Nano,\n\ttoMilli: (us: Micro): Milli => (us / 1_000) as Milli,\n\ttoSecond: (us: Micro): Second => (us / 1_000_000) as Second,\n\tnow: (): Micro => (performance.now() * 1_000) as Micro,\n\tadd: (a: Micro, b: Micro): Micro => (a + b) as Micro,\n\tsub: (a: Micro, b: Micro): Micro => (a - b) as Micro,\n\tmul: (a: Micro, b: number): Micro => (a * b) as Micro,\n\tdiv: (a: Micro, b: number): Micro => (a / b) as Micro,\n\tmax: (a: Micro, b: Micro): Micro => Math.max(a, b) as Micro,\n\tmin: (a: Micro, b: Micro): Micro => Math.min(a, b) as Micro,\n} as const;\n\n/** A duration in milliseconds, branded so it can't be mixed with other units. */\nexport type Milli = number & { readonly _brand: \"milli\" };\n\n/**\n * Constructors, conversions, and arithmetic for {@link Milli} values.\n *\n * Calling `Milli(x)` brands a raw number as milliseconds. This asserts the unit\n * rather than converting, so use `fromNano`/`fromMicro`/`fromSecond` to convert\n * from another unit.\n */\nexport const Milli = {\n\tzero: 0 as Milli,\n\tfromNano: (ns: Nano): Milli => (ns / 1_000_000) as Milli,\n\tfromMicro: (us: Micro): Milli => (us / 1_000) as Milli,\n\tfromSecond: (s: Second): Milli => (s * 1_000) as Milli,\n\ttoNano: (ms: Milli): Nano => (ms * 1_000_000) as Nano,\n\ttoMicro: (ms: Milli): Micro => (ms * 1_000) as Micro,\n\ttoSecond: (ms: Milli): Second => (ms / 1_000) as Second,\n\tnow: (): Milli => performance.now() as Milli,\n\tadd: (a: Milli, b: Milli): Milli => (a + b) as Milli,\n\tsub: (a: Milli, b: Milli): Milli => (a - b) as Milli,\n\tmul: (a: Milli, b: number): Milli => (a * b) as Milli,\n\tdiv: (a: Milli, b: number): Milli => (a / b) as Milli,\n\tmax: (a: Milli, b: Milli): Milli => Math.max(a, b) as Milli,\n\tmin: (a: Milli, b: Milli): Milli => Math.min(a, b) as Milli,\n} as const;\n\n/** A duration in seconds, branded so it can't be mixed with other units. */\nexport type Second = number & { readonly _brand: \"second\" };\n\n/**\n * Constructors, conversions, and arithmetic for {@link Second} values.\n *\n * Calling `Second(x)` brands a raw number as seconds. This asserts the unit\n * rather than converting, so use `fromNano`/`fromMicro`/`fromMilli` to convert\n * from another unit.\n */\nexport const Second = {\n\tzero: 0 as Second,\n\tfromNano: (ns: Nano): Second => (ns / 1_000_000_000) as Second,\n\tfromMicro: (us: Micro): Second => (us / 1_000_000) as Second,\n\tfromMilli: (ms: Milli): Second => (ms / 1_000) as Second,\n\ttoNano: (s: Second): Nano => (s * 1_000_000_000) as Nano,\n\ttoMicro: (s: Second): Micro => (s * 1_000_000) as Micro,\n\ttoMilli: (s: Second): Milli => (s * 1_000) as Milli,\n\tnow: (): Second => (performance.now() / 1_000) as Second,\n\tadd: (a: Second, b: Second): Second => (a + b) as Second,\n\tsub: (a: Second, b: Second): Second => (a - b) as Second,\n\tmul: (a: Second, b: number): Second => (a * b) as Second,\n\tdiv: (a: Second, b: number): Second => (a / b) as Second,\n\tmax: (a: Second, b: Second): Second => Math.max(a, b) as Second,\n\tmin: (a: Second, b: Second): Second => Math.min(a, b) as Second,\n} as const;\n"]}
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,yEAAyE;AACzE,+FAA+F;AAC/F,oGAAoG;AACpG,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAa,EAAQ,EAAE,CAAC,KAAa,EAAE;IACzE,IAAI,EAAE,CAAS;IACf,SAAS,EAAE,CAAC,EAAS,EAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAS;IACpD,SAAS,EAAE,CAAC,EAAS,EAAQ,EAAE,CA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E,GAAG,KAAK,CAAW;IACxD,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW;IACxD,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW;IACxD,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW;IACxD,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW;IACxD,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAW;IAC/D,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAW;CAC/D,CAAC,CAAC","sourcesContent":["/**\n * Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions,\n * plus {@link Timescale} and {@link Timestamp} for presentation timing.\n *\n * @module\n */\n\n/** A duration in nanoseconds, branded so it can't be mixed with other units. */\nexport type Nano = number & { readonly _brand: \"nano\" };\n\n/** Constructors, conversions, and arithmetic for {@link Nano} values. */\n// Calling `Nano(x)` brands a raw number as nanoseconds. The unit is the caller's assertion: no\n// conversion happens, so reach for `fromMicro`/`fromMilli`/`fromSecond` when the source has a unit.\nexport const Nano = Object.assign((value: number): Nano => value as Nano, {\n\tzero: 0 as Nano,\n\tfromMicro: (us: Micro): Nano => (us * 1_000) as Nano,\n\tfromMilli: (ms: Milli): Nano => (ms * 1_000_000) as Nano,\n\tfromSecond: (s: Second): Nano => (s * 1_000_000_000) as Nano,\n\ttoMicro: (ns: Nano): Micro => (ns / 1_000) as Micro,\n\ttoMilli: (ns: Nano): Milli => (ns / 1_000_000) as Milli,\n\ttoSecond: (ns: Nano): Second => (ns / 1_000_000_000) as Second,\n\tnow: (): Nano => (performance.now() * 1_000_000) as Nano,\n\tadd: (a: Nano, b: Nano): Nano => (a + b) as Nano,\n\tsub: (a: Nano, b: Nano): Nano => (a - b) as Nano,\n\tmul: (a: Nano, b: number): Nano => (a * b) as Nano,\n\tdiv: (a: Nano, b: number): Nano => (a / b) as Nano,\n\tmax: (a: Nano, b: Nano): Nano => Math.max(a, b) as Nano,\n\tmin: (a: Nano, b: Nano): Nano => Math.min(a, b) as Nano,\n});\n\n/** A duration in microseconds, branded so it can't be mixed with other units. */\nexport type Micro = number & { readonly _brand: \"micro\" };\n\n/** Constructors, conversions, and arithmetic for {@link Micro} values. */\n// Calling `Micro(x)` brands a raw number as microseconds. See the `Nano` note: this asserts the unit\n// rather than converting, so use `fromNano`/`fromMilli`/`fromSecond` to convert from another unit.\nexport const Micro = Object.assign((value: number): Micro => value as Micro, {\n\tzero: 0 as Micro,\n\tfromNano: (ns: Nano): Micro => (ns / 1_000) as Micro,\n\tfromMilli: (ms: Milli): Micro => (ms * 1_000) as Micro,\n\tfromSecond: (s: Second): Micro => (s * 1_000_000) as Micro,\n\ttoNano: (us: Micro): Nano => (us * 1_000) as Nano,\n\ttoMilli: (us: Micro): Milli => (us / 1_000) as Milli,\n\ttoSecond: (us: Micro): Second => (us / 1_000_000) as Second,\n\tnow: (): Micro => (performance.now() * 1_000) as Micro,\n\tadd: (a: Micro, b: Micro): Micro => (a + b) as Micro,\n\tsub: (a: Micro, b: Micro): Micro => (a - b) as Micro,\n\tmul: (a: Micro, b: number): Micro => (a * b) as Micro,\n\tdiv: (a: Micro, b: number): Micro => (a / b) as Micro,\n\tmax: (a: Micro, b: Micro): Micro => Math.max(a, b) as Micro,\n\tmin: (a: Micro, b: Micro): Micro => Math.min(a, b) as Micro,\n});\n\n/** A duration in milliseconds, branded so it can't be mixed with other units. */\nexport type Milli = number & { readonly _brand: \"milli\" };\n\n/** Constructors, conversions, and arithmetic for {@link Milli} values. */\n// Calling `Milli(x)` brands a raw number as milliseconds. See the `Nano` note: this asserts the unit\n// rather than converting, so use `fromNano`/`fromMicro`/`fromSecond` to convert from another unit.\nexport const Milli = Object.assign((value: number): Milli => value as Milli, {\n\tzero: 0 as Milli,\n\tfromNano: (ns: Nano): Milli => (ns / 1_000_000) as Milli,\n\tfromMicro: (us: Micro): Milli => (us / 1_000) as Milli,\n\tfromSecond: (s: Second): Milli => (s * 1_000) as Milli,\n\ttoNano: (ms: Milli): Nano => (ms * 1_000_000) as Nano,\n\ttoMicro: (ms: Milli): Micro => (ms * 1_000) as Micro,\n\ttoSecond: (ms: Milli): Second => (ms / 1_000) as Second,\n\tnow: (): Milli => performance.now() as Milli,\n\tadd: (a: Milli, b: Milli): Milli => (a + b) as Milli,\n\tsub: (a: Milli, b: Milli): Milli => (a - b) as Milli,\n\tmul: (a: Milli, b: number): Milli => (a * b) as Milli,\n\tdiv: (a: Milli, b: number): Milli => (a / b) as Milli,\n\tmax: (a: Milli, b: Milli): Milli => Math.max(a, b) as Milli,\n\tmin: (a: Milli, b: Milli): Milli => Math.min(a, b) as Milli,\n});\n\n/** Units per second for a {@link Timestamp}'s value, e.g. `1000` for milliseconds. */\nexport type Timescale = number & { readonly _brand: \"timescale\" };\n\n/** Named timescales and a checked constructor (rejects non-positive / non-integer values). */\nexport const Timescale = Object.assign(\n\t(unitsPerSecond: number): Timescale => {\n\t\tif (!Number.isInteger(unitsPerSecond) || unitsPerSecond <= 0) {\n\t\t\tthrow new Error(`invalid timescale: ${unitsPerSecond}`);\n\t\t}\n\t\treturn unitsPerSecond as Timescale;\n\t},\n\t{\n\t\t/** One unit per second. */\n\t\tSECOND: 1 as Timescale,\n\t\t/** 1,000 units per second. */\n\t\tMILLI: 1_000 as Timescale,\n\t\t/** 1,000,000 units per second. */\n\t\tMICRO: 1_000_000 as Timescale,\n\t\t/** 1,000,000,000 units per second. */\n\t\tNANO: 1_000_000_000 as Timescale,\n\t},\n);\n\n/**\n * A presentation timestamp: a raw value in a given {@link Timescale}.\n *\n * Mirrors the Rust `Timestamp`. Unlike the bare `Milli`/`Micro` aliases it carries its\n * own scale, so a track can pick its units and conversions can't silently mix them up.\n */\nexport class Timestamp {\n\t/** The raw value, in `scale` units. */\n\treadonly value: number;\n\t/** Units per second the {@link value} is measured in. */\n\treadonly scale: Timescale;\n\n\t/** Build a timestamp of `value` units at `scale`. */\n\tconstructor(value: number, scale: Timescale) {\n\t\tif (!Number.isFinite(value) || value < 0) {\n\t\t\tthrow new Error(`invalid timestamp: ${value}`);\n\t\t}\n\t\tthis.value = value;\n\t\tthis.scale = scale;\n\t}\n\n\t/** Monotonic now (`performance.now()`, milliseconds since page load), not wall-clock time. */\n\tstatic now(): Timestamp {\n\t\treturn new Timestamp(performance.now(), Timescale.MILLI);\n\t}\n\n\t/** A timestamp of `ms` milliseconds. */\n\tstatic fromMillis(ms: number): Timestamp {\n\t\treturn new Timestamp(ms, Timescale.MILLI);\n\t}\n\n\t/** A timestamp of `us` microseconds. */\n\tstatic fromMicros(us: number): Timestamp {\n\t\treturn new Timestamp(us, Timescale.MICRO);\n\t}\n\n\t/** This timestamp's value re-expressed at `scale` (a raw number, not a new Timestamp). */\n\tas(scale: Timescale): number {\n\t\treturn scale === this.scale ? this.value : (this.value * scale) / this.scale;\n\t}\n\n\t/** The value in milliseconds. */\n\tasMillis(): number {\n\t\treturn this.as(Timescale.MILLI);\n\t}\n\n\t/** The value in microseconds. */\n\tasMicros(): number {\n\t\treturn this.as(Timescale.MICRO);\n\t}\n}\n\n/** A duration in seconds, branded so it can't be mixed with other units. */\nexport type Second = number & { readonly _brand: \"second\" };\n\n/** Constructors, conversions, and arithmetic for {@link Second} values. */\n// Calling `Second(x)` brands a raw number as seconds. See the `Nano` note: this asserts the unit\n// rather than converting, so use `fromNano`/`fromMicro`/`fromMilli` to convert from another unit.\nexport const Second = Object.assign((value: number): Second => value as Second, {\n\tzero: 0 as Second,\n\tfromNano: (ns: Nano): Second => (ns / 1_000_000_000) as Second,\n\tfromMicro: (us: Micro): Second => (us / 1_000_000) as Second,\n\tfromMilli: (ms: Milli): Second => (ms / 1_000) as Second,\n\ttoNano: (s: Second): Nano => (s * 1_000_000_000) as Nano,\n\ttoMicro: (s: Second): Micro => (s * 1_000_000) as Micro,\n\ttoMilli: (s: Second): Milli => (s * 1_000) as Milli,\n\tnow: (): Second => (performance.now() / 1_000) as Second,\n\tadd: (a: Second, b: Second): Second => (a + b) as Second,\n\tsub: (a: Second, b: Second): Second => (a - b) as Second,\n\tmul: (a: Second, b: number): Second => (a * b) as Second,\n\tdiv: (a: Second, b: number): Second => (a / b) as Second,\n\tmax: (a: Second, b: Second): Second => Math.max(a, b) as Second,\n\tmin: (a: Second, b: Second): Second => Math.min(a, b) as Second,\n});\n"]}
package/time.test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=time.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.test.d.ts","sourceRoot":"","sources":["../src/time.test.ts"],"names":[],"mappings":""}
package/time.test.js ADDED
@@ -0,0 +1,12 @@
1
+ /* @ts-self-types="./time.test.d.ts" */
2
+ import { expect, test } from "bun:test";
3
+ import { Timescale, Timestamp } from "./time.js";
4
+ test("Timestamp rejects negative values", () => {
5
+ expect(() => new Timestamp(-1, Timescale.MILLI)).toThrow();
6
+ expect(() => Timestamp.fromMicros(-1)).toThrow();
7
+ });
8
+ test("Timestamp rejects non-finite values", () => {
9
+ expect(() => new Timestamp(Number.NaN, Timescale.MILLI)).toThrow();
10
+ expect(() => Timestamp.fromMillis(Number.POSITIVE_INFINITY)).toThrow();
11
+ });
12
+ //# sourceMappingURL=time.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.test.js","sourceRoot":"","sources":["../src/time.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjD,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3D,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qCAAqC,EAAE,GAAG,EAAE;IAChD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACnE,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACxE,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Timescale, Timestamp } from \"./time.ts\";\n\ntest(\"Timestamp rejects negative values\", () => {\n\texpect(() => new Timestamp(-1, Timescale.MILLI)).toThrow();\n\texpect(() => Timestamp.fromMicros(-1)).toThrow();\n});\n\ntest(\"Timestamp rejects non-finite values\", () => {\n\texpect(() => new Timestamp(Number.NaN, Timescale.MILLI)).toThrow();\n\texpect(() => Timestamp.fromMillis(Number.POSITIVE_INFINITY)).toThrow();\n});\n"]}
package/track.d.ts CHANGED
@@ -1,71 +1,255 @@
1
- import { Signal } from "@moq/signals";
2
- import { Group } from "./group";
3
- /** Reactive backing state for a {@link Track}: buffered groups, a closed flag, and the subscription priority. */
4
- export declare class TrackState {
5
- groups: Signal<Group[]>;
6
- closed: Signal<boolean | Error>;
7
- priority: Signal<number | undefined>;
1
+ /**
2
+ * Track role handles: a live stream of groups (and best-effort datagrams) within a broadcast.
3
+ *
4
+ * @module
5
+ */
6
+ import { type GetPromise, type Getter } from "@moq/signals";
7
+ import type { Datagram } from "./datagram";
8
+ import { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer } from "./group";
9
+ import { Timescale, type Timestamp } from "./time";
10
+ export type { Datagram } from "./datagram";
11
+ /** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */
12
+ export declare const DEFAULT_LATENCY_MAX_MS = 5000;
13
+ /**
14
+ * A track's immutable publisher properties, fixed for the lifetime of the track.
15
+ *
16
+ * A producer declares these once (via {@link Request.accept} or
17
+ * {@link Producer.accept}); a consumer awaits them via {@link Subscriber.info}
18
+ * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO.
19
+ */
20
+ export interface Info {
21
+ /**
22
+ * Units per second for this track's frame timestamps (reported in TRACK_INFO on
23
+ * Lite05+). Defaults to milliseconds; set it finer (e.g. {@link Timescale.MICRO})
24
+ * for media that needs sub-millisecond timing.
25
+ */
26
+ timescale: Timescale;
27
+ /**
28
+ * Publisher Max Latency: the maximum age (milliseconds) of a non-latest group before
29
+ * the publisher evicts it. Reported in TRACK_INFO (Lite05+) so relays re-serve with the
30
+ * same bound. The publisher-side half of the budget a subscriber sets for itself.
31
+ */
32
+ latencyMax: number;
33
+ /** Tie-break priority between subscriptions of equal subscriber priority. */
34
+ priority: number;
35
+ /**
36
+ * Whether groups are prioritized in sequence order. Groups may always arrive
37
+ * out-of-order (or not at all) over the network. Defaults to `false` (newest-first).
38
+ */
39
+ ordered: boolean;
40
+ }
41
+ /** Fill in any unset {@link Info} fields with their defaults. */
42
+ export declare function infoDefaults(info?: Partial<Info>): Info;
43
+ /**
44
+ * Per-subscription options, requested when a subscription opens and adjustable later via
45
+ * {@link Subscriber.update}. Mirrors the Rust `Subscription`.
46
+ */
47
+ export interface Subscription {
48
+ /** Delivery priority relative to this session's other subscriptions. Defaults to `0`. */
49
+ priority?: number;
50
+ }
51
+ /**
52
+ * A request for a track the peer wants, yielded by `Broadcast.Producer.requested`.
53
+ *
54
+ * Created internally by the broadcast when a subscription (or info lookup) needs a track
55
+ * served; answer it with {@link accept} or {@link reject}.
56
+ *
57
+ * @public
58
+ */
59
+ export declare class Request {
60
+ #private;
61
+ /** The requested track name. */
62
+ readonly name: string;
63
+ /** The subscriber's priority for this track. */
64
+ readonly priority: number;
65
+ private constructor();
66
+ /** Accept the request, committing the track's immutable {@link Info}. */
67
+ accept(info?: Partial<Info>): Producer;
68
+ /** Reject the request, closing the track optionally with an error. */
69
+ reject(err?: Error): void;
8
70
  }
9
- /** A live stream of groups within a broadcast, identified by name. */
10
- export declare class Track {
71
+ /** Options for {@link Consumer.fetchGroup}. */
72
+ export interface FetchGroupOptions {
73
+ /** Delivery priority for the fetch stream. Defaults to `0`. */
74
+ priority?: number;
75
+ }
76
+ /**
77
+ * The per-track operations a lazy {@link Consumer} delegates to the broadcast it came from.
78
+ *
79
+ * Implemented by `broadcast.Producer` / `broadcast.Consumer` (and the wire-layer subclasses
80
+ * that resolve them over the network), so a track handle holds a reference to its broadcast
81
+ * and calls methods on it rather than capturing a bag of callbacks.
82
+ */
83
+ export interface Broadcast {
84
+ /** Open a live subscription to the named track. */
85
+ subscribe(name: string, options?: Subscription): Subscriber;
86
+ /** Resolve the named track's immutable info. */
87
+ resolveTrackInfo(name: string): Promise<Info>;
88
+ /** Fetch a single group of the named track by sequence. */
89
+ fetchGroup(name: string, sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;
90
+ }
91
+ /**
92
+ * A lazy handle to a track on a consumed broadcast.
93
+ *
94
+ * @public
95
+ */
96
+ export declare class Consumer {
97
+ #private;
98
+ /** The track name. */
99
+ readonly name: string;
100
+ constructor(name: string, broadcast: Broadcast);
101
+ /** Open a live subscription to the track. */
102
+ subscribe(options?: Subscription): Subscriber;
103
+ /** Fetch the track's immutable publisher properties without subscribing. */
104
+ info(): Promise<Info>;
105
+ /** Fetch a single group by sequence without holding a live subscription. */
106
+ fetchGroup(sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;
107
+ }
108
+ /**
109
+ * The write side of a track, mirroring the Rust `Producer`.
110
+ *
111
+ * A producer is a fan-out source: every {@link subscribe} (including each wire
112
+ * subscription the publisher serves from it) gets an independent
113
+ * {@link Subscriber} that receives a full copy of the groups, each with its own
114
+ * read cursor. Groups are mirrored into every live subscriber and retained for the
115
+ * track's `latencyMax` window so a late subscriber replays the recent groups.
116
+ *
117
+ * Obtained from {@link Request.accept} (the wire asks the application for a track to
118
+ * serve) or constructed directly for an in-process track.
119
+ */
120
+ export declare class Producer {
11
121
  #private;
12
- /** Name of this track within its broadcast. */
122
+ /** The track name. */
13
123
  readonly name: string;
14
- /** Reactive backing state. */
15
- state: TrackState;
16
- /** Resolves with the abort error (or undefined) once closed. */
17
- readonly closed: Promise<Error | undefined>;
18
124
  constructor(name: string);
19
125
  /**
20
- * Appends a new group to the track.
21
- * @returns A GroupProducer for the new group
126
+ * Resolve this track's immutable publisher properties, committed at accept time.
127
+ * Rejects if the track is closed before the properties are known.
128
+ */
129
+ info(): Promise<Info>;
130
+ /**
131
+ * Settles once the track closes: `null` on a clean close, or the abort {@link Error}.
132
+ * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
133
+ */
134
+ get closed(): GetPromise<Error | null>;
135
+ /**
136
+ * The current subscription, or `undefined` until a subscriber first calls
137
+ * {@link Subscriber.update}. The wire layer watches this to emit SUBSCRIBE_UPDATE.
138
+ */
139
+ get subscription(): Getter<Subscription | undefined>;
140
+ /** Commit the immutable publisher properties, resolving {@link info}. Returns `this`. */
141
+ accept(info?: Partial<Info>): this;
142
+ /** An independent {@link Subscriber} receiving a full copy of this track's groups. */
143
+ subscribe(): Subscriber;
144
+ /**
145
+ * Whether the track currently has any subscribers.
146
+ *
147
+ * Watch it (`effect.get` / `.peek()`) to drive on-demand work: a publisher can start and stop
148
+ * capture with demand, and the consumer wire watches it to tear an idle upstream subscription
149
+ * down instead of downloading to nobody. Pairs with {@link unused}. Mirrors the Rust `Demand`.
22
150
  */
23
- appendGroup(): Group;
151
+ get used(): Getter<boolean>;
152
+ /** Resolves once the track has no subscribers (or has closed). Await it to react to demand ending. */
153
+ unused(): Promise<void>;
154
+ /** Append a new group with the next sequence number. */
155
+ appendGroup(): GroupProducer;
156
+ /** Insert an existing group into the track. */
157
+ writeGroup(group: GroupProducer): void;
24
158
  /**
25
- * Inserts an existing group into the track.
26
- * @param group - The group to insert
159
+ * Append a datagram with the next sequence number, returning the assigned sequence.
160
+ *
161
+ * A datagram is delivered best-effort over a single QUIC datagram, parallel to the track's
162
+ * groups but drawing from the same sequence namespace (interleaving with {@link appendGroup}
163
+ * never reuses a number). The payload must fit the negotiated transport datagram size minus
164
+ * a small header; an oversize payload is dropped at each hop (there is no group fallback), so
165
+ * keep datagram payloads small (e.g. a single audio frame). Datagrams are never delivered
166
+ * over IETF moq-transport or stream-only transports (the WebSocket fallback). A payload over
167
+ * 65535 bytes (the QUIC datagram frame ceiling) throws. An origin publisher uses this; a
168
+ * relay preserving upstream numbering uses {@link writeDatagram}.
27
169
  */
28
- writeGroup(group: Group): void;
170
+ appendDatagram(timestamp: Timestamp, payload: Uint8Array): number;
29
171
  /**
30
- * Appends a frame to the track in its own group.
172
+ * Write a datagram with an explicit sequence number.
31
173
  *
32
- * @param frame - The frame to append
174
+ * Preserves the supplied sequence (advancing the shared counter if needed) so a relay can
175
+ * forward a datagram without renumbering it. The size limits of {@link appendDatagram}
176
+ * apply. Most origin publishers want {@link appendDatagram} instead.
33
177
  */
34
- writeFrame(frame: Uint8Array): void;
178
+ writeDatagram(datagram: Datagram): void;
179
+ /** Close the track and every subscriber, mirroring the abort to their groups. Idempotent. */
180
+ close(abort?: Error): void;
181
+ /** Append a frame as its own single-frame group. */
182
+ writeFrame(frame: Frame): void;
35
183
  /** Appends a string to the track as its own single-frame group. */
36
184
  writeString(str: string): void;
37
185
  /** Appends a JSON value to the track as its own single-frame group. */
38
186
  writeJson(json: unknown): void;
39
187
  /** Appends a boolean to the track as its own single-frame group. */
40
188
  writeBool(bool: boolean): void;
189
+ }
190
+ /**
191
+ * The read side of a live track subscription, mirroring the Rust `Subscriber`.
192
+ *
193
+ * Obtained from `Broadcast.Consumer.subscribe` / `Track.Consumer.subscribe`, or from
194
+ * {@link Producer.subscribe} for an in-process track. Reads the groups a
195
+ * {@link Producer} on the same underlying state writes.
196
+ */
197
+ export declare class Subscriber {
198
+ #private;
199
+ /** The track name. */
200
+ readonly name: string;
201
+ private constructor();
202
+ /**
203
+ * Resolve this track's immutable publisher properties.
204
+ *
205
+ * Resolves once the wire layer commits the TRACK_INFO it received (lite-05+) or
206
+ * defaults (older drafts), so awaiting it never yields a placeholder. Rejects if
207
+ * the track is closed before the properties are known (e.g. a rejected subscription).
208
+ */
209
+ info(): Promise<Info>;
210
+ /** Settles once the track closes; see {@link Producer.closed}. */
211
+ get closed(): GetPromise<Error | null>;
212
+ /** The last {@link update} requested on this subscriber, or `undefined` if none yet. */
213
+ get subscription(): Getter<Subscription | undefined>;
214
+ /** Close the track (optionally with an error), closing any pending groups. Idempotent. */
215
+ close(abort?: Error): void;
41
216
  /**
42
217
  * Receive the next group available on this track, in arrival order.
43
218
  *
44
219
  * Groups may arrive out of order or with gaps due to network conditions.
45
- * Use {@link nextGroupOrdered} if you need groups in sequence order,
46
- * skipping those that arrive too late.
220
+ * Use {@link nextGroup} for sequence order, skipping those that arrive too late.
47
221
  */
48
- recvGroup(): Promise<Group | undefined>;
222
+ recvGroup(): Promise<GroupConsumer | undefined>;
49
223
  /**
50
- * @deprecated Use {@link recvGroup} for arrival order, or {@link nextGroupOrdered} for sequence order.
224
+ * Receive the next datagram in arrival order.
225
+ *
226
+ * Datagrams are a separate best-effort channel from groups (see
227
+ * {@link Producer.appendDatagram}); they share only the sequence namespace. A consumer
228
+ * that falls too far behind silently loses the oldest datagrams. Read this alongside
229
+ * {@link recvGroup} (e.g. in a separate loop) to receive both channels concurrently. Returning
230
+ * a datagram advances {@link nextGroup} past that sequence.
51
231
  */
52
- nextGroup(): Promise<Group | undefined>;
232
+ recvDatagram(): Promise<Datagram | undefined>;
53
233
  /**
54
234
  * Return the next group with a strictly-greater sequence number than the last returned.
55
235
  *
56
- * Late arrivals (with a sequence number at or below the last one returned) are silently skipped.
57
- *
58
- * NOTE: This will be renamed to `nextGroup` in the next major version.
236
+ * Late arrivals (sequence at or below the last returned) are silently skipped.
237
+ * Use {@link recvGroup} to see every group in arrival order instead.
238
+ */
239
+ nextGroup(): Promise<GroupConsumer | undefined>;
240
+ /**
241
+ * Reads the next frame across all groups, discarding older groups.
242
+ * Treat the returned frame bytes as read-only; they are shared with other consumers.
59
243
  */
60
- nextGroupOrdered(): Promise<Group | undefined>;
61
- /** Reads the next frame across all groups, discarding older groups. */
62
- readFrame(): Promise<Uint8Array | undefined>;
63
- /** Reads the next frame along with its group and frame sequence numbers. */
64
- readFrameSequence(): Promise<{
244
+ readFrame(): Promise<Frame | undefined>;
245
+ /**
246
+ * Reads the next frame along with its group and frame sequence numbers.
247
+ * Treat the returned frame bytes as read-only; they are shared with other consumers.
248
+ */
249
+ readFrameSequence(): Promise<({
65
250
  group: number;
66
251
  frame: number;
67
- data: Uint8Array;
68
- } | undefined>;
252
+ } & Frame) | undefined>;
69
253
  /** Reads the next frame and decodes it as a UTF-8 string. */
70
254
  readString(): Promise<string | undefined>;
71
255
  /** Reads the next frame and parses it as JSON. */
@@ -73,13 +257,9 @@ export declare class Track {
73
257
  /** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */
74
258
  readBool(): Promise<boolean | undefined>;
75
259
  /**
76
- * Update the subscription priority. Triggers a SUBSCRIBE_UPDATE
77
- * to the publisher when used on a subscribed track.
260
+ * Update this subscription's options (e.g. priority), triggering a SUBSCRIBE_UPDATE to the
261
+ * publisher. Mirrors the Rust `Subscriber::update`.
78
262
  */
79
- updatePriority(priority: number): void;
80
- /**
81
- * Closes the publisher and all associated groups.
82
- */
83
- close(abort?: Error): void;
263
+ update(options: Subscription): void;
84
264
  }
85
265
  //# sourceMappingURL=track.d.ts.map
package/track.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,iHAAiH;AACjH,qBAAa,UAAU;IACtB,MAAM,kBAA2B;IACjC,MAAM,0BAAsC;IAC5C,QAAQ,6BAA6C;CACrD;AAED,sEAAsE;AACtE,qBAAa,KAAK;;IACjB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,8BAA8B;IAC9B,KAAK,aAAoB;IAIzB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAE5C,YAAY,IAAI,EAAE,MAAM,EAUvB;IAED;;;OAGG;IACH,WAAW,IAAI,KAAK,CAYnB;IAED;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,KAAK,QAYtB;IAED;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,UAAU,QAI3B;IAED,mEAAmE;IACnE,WAAW,CAAC,GAAG,EAAE,MAAM,QAItB;IAED,uEAAuE;IACvE,SAAS,CAAC,IAAI,EAAE,OAAO,QAItB;IAED,oEAAoE;IACpE,SAAS,CAAC,IAAI,EAAE,OAAO,QAItB;IAED;;;;;;OAMG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAa5C;IAED;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAE5C;IAED;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAWnD;IAED,uEAAuE;IACjE,SAAS,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAEjD;IAED,4EAA4E;IACtE,iBAAiB,IAAI,OAAO,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