jsflow-sdk 1.1.0-rc.1 → 1.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
@@ -6,6 +6,45 @@ All notable changes to `jsflow-sdk`. The format follows
6
6
  contract; metric names passed to `onMetric` are diagnostic and may change in
7
7
  any minor release.
8
8
 
9
+ ## [1.1.1] - 2026-11-22
10
+
11
+ A patch under the npm tag `latest`. Nothing in the API changes (`jsflow.d.ts`
12
+ is byte-identical to 1.1.0's), the wire version is still 2, and peers on
13
+ 1.1.0 and 1.1.1 share a room.
14
+
15
+ ### Fixed
16
+
17
+ - **Large reliable transfers through a TURN relay complete, and the peer no
18
+ longer goes down and up while one runs.** A relay caps each allocation
19
+ (jsflow's relays at 500 KB/s). `sendReliable` kept up to 64 packets in
20
+ flight whatever the path could carry, so a bulk transfer overran the cap;
21
+ the relay's drops stalled the connection for over half a second at a time,
22
+ the peer was reported down and up every few seconds, and a 5 MB transfer
23
+ through a relay never finished. Two changes, neither on the wire:
24
+ - any packet from a neighbour now counts as a sign of life, not only its
25
+ keepalives, so a peer whose keepalives queue behind bulk data stays up;
26
+ - the sender paces reliable data to what the path delivers (congestion
27
+ control): it starts at 10 packets in flight, grows while they arrive, and
28
+ backs off when a round trip loses a tenth of them.
29
+
30
+ Measured on staging's relay with Chrome: 5 MB in 12.5 to 13.5 s and 10 MB in
31
+ 27 s (before: never), with the peer up throughout; 5 MB over a direct
32
+ connection is unchanged at 1.9 s.
33
+
34
+ ### Changed
35
+
36
+ - Under heavy random loss the slowest messages of a heavy stream arrive later:
37
+ in the simulator, at 5 % loss with 100 messages a second of up to 64 KB,
38
+ the 99th percentile goes from 353 to 743 ms. Messages at an ordinary rate
39
+ are unaffected (10 a second of 100 to 500 bytes at 5 % loss: median 20 ms,
40
+ 99th percentile 282 ms, the same as 1.1.0).
41
+
42
+ ## [1.1.0] - 2026-11-21
43
+
44
+ Under the npm tag `latest` (`npm install jsflow-sdk`). The code is
45
+ 1.1.0-rc.1's, and the changes are those listed for it below: additions only,
46
+ nothing in 1.0.0's API changes, and the wire version is still 2.
47
+
9
48
  ## [1.1.0-rc.1] - 2026-11-20
10
49
 
11
50
  The first release candidate for 1.1.0, under the npm tag `next`
package/README.md CHANGED
@@ -20,7 +20,7 @@ Or from the CDN, at an exact version with its integrity hash (`sri.json` in
20
20
  each version directory):
21
21
 
22
22
  ```html
23
- <script type="module" integrity="sha384-…" crossorigin src="https://cdn.jsflow.com/v1.0.0/jsflow.js"></script>
23
+ <script type="module" integrity="sha384-…" crossorigin src="https://cdn.jsflow.com/v1.1.1/jsflow.js"></script>
24
24
  ```
25
25
 
26
26
  The SDK starts a worker (`worker.js`, next to `jsflow.js`). Vite and webpack
package/jsflow.js CHANGED
@@ -1,4 +1,4 @@
1
- // jsflow-sdk 1.1.0-rc.1. Licence: see LICENSE (https://jsflow.com). Built by client/build.js.
1
+ // jsflow-sdk 1.1.1. Licence: see LICENSE (https://jsflow.com). Built by client/build.js.
2
2
 
3
3
  // core/link-main.js
4
4
  function linkKind(stats) {
@@ -285,7 +285,7 @@ function ticketRegion(ticket) {
285
285
  return void 0;
286
286
  }
287
287
  }
288
- var SDK_VERSION = "1.1.0-rc.1";
288
+ var SDK_VERSION = "1.1.1";
289
289
  var WIRE = 2;
290
290
  var MAX_DATAGRAM = 1052;
291
291
  var MAX_RELIABLE = 65536;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsflow-sdk",
3
- "version": "1.1.0-rc.1",
3
+ "version": "1.1.1",
4
4
  "description": "jsflow: peer-to-peer rooms for the browser (WebRTC mesh, signalling and relays as a service).",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
package/sri.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "1.1.0-rc.1",
3
- "jsflow.js": "sha384-O381tD0tzvsCNFFFCtgtr5WAGV31aWS3FZjHi33wT2Oh/yt4Wb9sI80Z6B+iJyOQ",
4
- "worker.js": "sha384-0XqeO3D/M7TXSmGr37saYSJ0iek9R2Hr7GT8NX53S7FeB71xr06kszVbOB7gpoXt",
2
+ "version": "1.1.1",
3
+ "jsflow.js": "sha384-ugDbrtqBevA7WJvu/IMV4128uc+iYLBFLq04YF8Nb5cOcUf5r6yErM9TAVc4KNrI",
4
+ "worker.js": "sha384-K9nbXm7n5ia3bxGtbkYWmqlnSTpxGQmxz7/W+P3iLNnisWM8er+yhG7CCGOLwo7m",
5
5
  "jsflow.d.ts": "sha384-VM+jOFBiVG6Z3ElnDVldrvSTyha/lJh9kC8el+JL/77bYFOp6ScbTHFK2tCnFsN5"
6
6
  }
package/worker.js CHANGED
@@ -1,4 +1,4 @@
1
- // jsflow-sdk 1.1.0-rc.1. Licence: see LICENSE (https://jsflow.com). Built by client/build.js.
1
+ // jsflow-sdk 1.1.1. Licence: see LICENSE (https://jsflow.com). Built by client/build.js.
2
2
 
3
3
  // core/header.js
4
4
  var VERSION = 2;
@@ -1023,6 +1023,8 @@ function meshNode(opts = {}) {
1023
1023
  if (!h2) return env2.metric("badVersion", from);
1024
1024
  if (h2.type === T.HELLO) return onHello(from, h2);
1025
1025
  if (h2.type === T.BYE) return onBye(from, h2);
1026
+ const n = nbr.get(from);
1027
+ if (n && n.byeTs === void 0) n.lastHeard = env2.now();
1026
1028
  route(raw, h2, from);
1027
1029
  },
1028
1030
  // ---- app API used by experiments ----
@@ -1838,6 +1840,8 @@ function reliable({
1838
1840
  minRto = 200,
1839
1841
  maxRto = 1e4,
1840
1842
  initRto = 1e3,
1843
+ initCwnd = 10,
1844
+ congestion = true,
1841
1845
  giveUpMs = 3e4,
1842
1846
  txIdleMs = 3e4,
1843
1847
  rxIdleMs = 6e4,
@@ -1850,7 +1854,7 @@ function reliable({
1850
1854
  if (!(rxIdleMs > giveUpMs && rxIdleMs > txIdleMs)) throw new RangeError("reliable: rxIdleMs must outlast giveUpMs and txIdleMs");
1851
1855
  const peers = /* @__PURE__ */ new Map();
1852
1856
  const meshInc = /* @__PURE__ */ new Map();
1853
- const stats = { sent: 0, data: 0, retx: 0, fast: 0, timeLoss: 0, rto: 0, acks: 0, piggy: 0, dup: 0, delivered: 0, giveUps: 0, resets: 0, bad: 0 };
1857
+ const stats = { sent: 0, data: 0, retx: 0, fast: 0, timeLoss: 0, rto: 0, cuts: 0, acks: 0, piggy: 0, dup: 0, delivered: 0, giveUps: 0, resets: 0, bad: 0 };
1854
1858
  let sids = 0, sweep = null;
1855
1859
  const bad = (why) => {
1856
1860
  stats.bad++;
@@ -1863,13 +1867,22 @@ function reliable({
1863
1867
  metric2("reliablePeersFull", peer);
1864
1868
  return null;
1865
1869
  }
1866
- peers.set(peer, rec = { inc: meshInc.get(peer) ?? 0, tx: null, rx: null, rtt: { srtt: null, var: 0, min: Infinity, latest: 0 }, seen: now(), noticeAt: -Infinity });
1870
+ peers.set(peer, rec = {
1871
+ inc: meshInc.get(peer) ?? 0,
1872
+ tx: null,
1873
+ rx: null,
1874
+ rtt: { srtt: null, var: 0, min: Infinity, latest: 0 },
1875
+ seen: now(),
1876
+ noticeAt: -Infinity,
1877
+ cc: { cwnd: Math.min(W, initCwnd), ssthresh: Infinity, delivered: 0, roundDel: 0, rDel0: 0, rLost: 0 }
1878
+ });
1867
1879
  if (!sweep) sweep = setTimer(sweepMs, onSweep);
1868
1880
  return rec;
1869
1881
  }
1870
1882
  function dropTx(rec) {
1871
1883
  if (rec.tx) {
1872
1884
  clearTimer(rec.tx.timer);
1885
+ clearTimer(rec.tx.paceTimer);
1873
1886
  rec.tx = null;
1874
1887
  }
1875
1888
  }
@@ -1974,7 +1987,9 @@ function reliable({
1974
1987
  rto: rtoOf(rec.rtt),
1975
1988
  rtoAt: 0,
1976
1989
  progress: now(),
1977
- timer: null
1990
+ timer: null,
1991
+ paceAt: 0,
1992
+ paceTimer: null
1978
1993
  };
1979
1994
  }
1980
1995
  function transmit(peer, rec, p) {
@@ -1983,11 +1998,46 @@ function reliable({
1983
1998
  p.sentAt = now();
1984
1999
  p.txn = ++tx.txn;
1985
2000
  p.n++;
2001
+ p.del = rec.cc.delivered;
1986
2002
  out2(peer, rec, p);
1987
2003
  }
2004
+ function pipe(tx) {
2005
+ let n = 0;
2006
+ for (const p of tx.inflight.values()) if (!p.sacked) n++;
2007
+ return n;
2008
+ }
2009
+ function delivered(rec, ps) {
2010
+ const cc = rec.cc;
2011
+ let roundEnd = false;
2012
+ for (const p of ps) {
2013
+ cc.delivered++;
2014
+ if (p.del >= cc.roundDel) roundEnd = true;
2015
+ }
2016
+ cc.cwnd = Math.min(W, cc.cwnd < cc.ssthresh ? cc.cwnd + ps.length : cc.cwnd + ps.length / cc.cwnd);
2017
+ if (!roundEnd) return;
2018
+ const rDel = cc.delivered - cc.rDel0;
2019
+ if (rDel >= 8 && cc.rLost >= 3 && cc.rLost >= 0.1 * (rDel + cc.rLost)) {
2020
+ cc.cwnd = Math.max(4, Math.min(cc.cwnd, 0.85 * rDel));
2021
+ cc.ssthresh = cc.cwnd;
2022
+ stats.cuts++;
2023
+ }
2024
+ cc.roundDel = cc.rDel0 = cc.delivered;
2025
+ cc.rLost = 0;
2026
+ }
1988
2027
  function pump(peer, rec) {
1989
- const tx = rec.tx;
1990
- while (tx.queue.length && d32(tx.next, tx.una) < W) {
2028
+ const tx = rec.tx, cc = rec.cc, t = now();
2029
+ let room = (congestion ? Math.floor(cc.cwnd) : W) - pipe(tx);
2030
+ const srtt = rec.rtt.srtt, gap = congestion && srtt ? srtt / ((cc.cwnd < cc.ssthresh ? 2 : 1.2) * cc.cwnd) : 0;
2031
+ tx.paceAt = Math.max(tx.paceAt, t - 4 * gap);
2032
+ while (tx.queue.length && d32(tx.next, tx.una) < W && room-- > 0) {
2033
+ if (tx.paceAt > t) {
2034
+ if (!tx.paceTimer) tx.paceTimer = setTimer(Math.max(1, tx.paceAt - t), () => {
2035
+ tx.paceTimer = null;
2036
+ if (rec.tx === tx && peers.get(peer) === rec && live(peer, rec)) pump(peer, rec);
2037
+ });
2038
+ break;
2039
+ }
2040
+ tx.paceAt += gap;
1991
2041
  if (!tx.inflight.size) {
1992
2042
  tx.progress = now();
1993
2043
  tx.rtoAt = now() + tx.rto;
@@ -2016,6 +2066,7 @@ function reliable({
2016
2066
  if (!live(peer, rec)) return;
2017
2067
  const lost = detectLost(rec);
2018
2068
  if (lost.length) {
2069
+ rec.cc.rLost += lost.length;
2019
2070
  for (const p of lost) transmit(peer, rec, p);
2020
2071
  return arm(peer, rec);
2021
2072
  }
@@ -2025,6 +2076,11 @@ function reliable({
2025
2076
  stats.rto++;
2026
2077
  break;
2027
2078
  }
2079
+ if (tx.rto === rtoOf(rec.rtt)) {
2080
+ const cc = rec.cc;
2081
+ cc.cwnd = cc.ssthresh = Math.max(4, cc.cwnd / 2);
2082
+ stats.cuts++;
2083
+ }
2028
2084
  tx.rto = Math.min(2 * tx.rto, maxRto);
2029
2085
  tx.rtoAt = now() + tx.rto;
2030
2086
  }
@@ -2078,13 +2134,18 @@ function reliable({
2078
2134
  const adv = d32(next, tx.una);
2079
2135
  if (adv > d32(tx.next, tx.una)) return bad("ackBeyondSent");
2080
2136
  let newest = null;
2137
+ const acked = [];
2081
2138
  const got = (p) => {
2139
+ acked.push(p);
2082
2140
  if (!newest || p.txn > newest.txn) newest = p;
2083
2141
  if (p.txn < tx.rack.txn) {
2084
2142
  if (p.n === 1) tx.reordered = true;
2085
2143
  return;
2086
2144
  }
2087
- if (p.n > 1 && rec.rtt.min < Infinity && now() - p.sentAt < rec.rtt.min) return;
2145
+ if (p.n > 1 && rec.rtt.min < Infinity && now() - p.sentAt < rec.rtt.min) {
2146
+ if (rec.cc.rLost) rec.cc.rLost--;
2147
+ return;
2148
+ }
2088
2149
  tx.rack.txn = p.txn;
2089
2150
  tx.rack.rtt = now() - p.sentAt;
2090
2151
  };
@@ -2108,7 +2169,10 @@ function reliable({
2108
2169
  tx.progress = now();
2109
2170
  tx.rtoAt = now() + tx.rto;
2110
2171
  }
2111
- for (const p of detectLost(rec)) transmit(peer, rec, p);
2172
+ if (acked.length) delivered(rec, acked);
2173
+ const lost = detectLost(rec);
2174
+ rec.cc.rLost += lost.length;
2175
+ for (const p of lost) transmit(peer, rec, p);
2112
2176
  pump(peer, rec);
2113
2177
  }
2114
2178
  function onData(peer, rec, sid, seq, una, flags, bytes) {