@dxos/network-manager 0.1.56-main.e47dfd1 → 0.1.56-main.ec96785

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.
@@ -2218,6 +2218,13 @@ var WebRTCTransportService = class {
2218
2218
  const rpcStream = new Stream(({ ready, next, close }) => {
2219
2219
  const duplex = new Duplex({
2220
2220
  read: () => {
2221
+ const callbacks = [
2222
+ ...transportState.writeCallbacks
2223
+ ];
2224
+ transportState.writeCallbacks.length = 0;
2225
+ for (const cb of callbacks) {
2226
+ cb();
2227
+ }
2221
2228
  },
2222
2229
  write: function(chunk, _, callback) {
2223
2230
  next({
@@ -2269,11 +2276,13 @@ var WebRTCTransportService = class {
2269
2276
  });
2270
2277
  close();
2271
2278
  });
2272
- ready();
2273
- this.transports.set(request.proxyId, {
2279
+ const transportState = {
2274
2280
  transport,
2275
- stream: duplex
2276
- });
2281
+ stream: duplex,
2282
+ writeCallbacks: []
2283
+ };
2284
+ ready();
2285
+ this.transports.set(request.proxyId, transportState);
2277
2286
  });
2278
2287
  return rpcStream;
2279
2288
  }
@@ -2283,7 +2292,13 @@ var WebRTCTransportService = class {
2283
2292
  }
2284
2293
  async sendData({ proxyId, payload }) {
2285
2294
  invariant12(this.transports.has(proxyId));
2286
- await this.transports.get(proxyId).stream.push(payload);
2295
+ const state = this.transports.get(proxyId);
2296
+ const bufferHasSpace = state.stream.push(payload);
2297
+ if (!bufferHasSpace) {
2298
+ await new Promise((resolve) => {
2299
+ state.writeCallbacks.push(resolve);
2300
+ });
2301
+ }
2287
2302
  }
2288
2303
  async close({ proxyId }) {
2289
2304
  var _a, _b;
@@ -2292,7 +2307,7 @@ var WebRTCTransportService = class {
2292
2307
  this.transports.delete(proxyId);
2293
2308
  log12("Closed.", void 0, {
2294
2309
  F: __dxlog_file12,
2295
- L: 109,
2310
+ L: 132,
2296
2311
  S: this,
2297
2312
  C: (f, a) => f(...a)
2298
2313
  });
@@ -2300,6 +2315,7 @@ var WebRTCTransportService = class {
2300
2315
  };
2301
2316
 
2302
2317
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
2318
+ import { Writable } from "@dxos/node-std/stream";
2303
2319
  import invariant13 from "tiny-invariant";
2304
2320
  import { Event as Event8 } from "@dxos/async";
2305
2321
  import { Context as Context6 } from "@dxos/context";
@@ -2327,7 +2343,7 @@ var WebRTCTransportProxy = class {
2327
2343
  this._serviceStream.subscribe(async (event) => {
2328
2344
  log13("WebRTCTransportProxy: event", event, {
2329
2345
  F: __dxlog_file13,
2330
- L: 50,
2346
+ L: 51,
2331
2347
  S: this,
2332
2348
  C: (f, a) => f(...a)
2333
2349
  });
@@ -2339,28 +2355,24 @@ var WebRTCTransportProxy = class {
2339
2355
  await this._handleSignal(event.signal);
2340
2356
  }
2341
2357
  });
2342
- const dataListener = async (data) => {
2343
- try {
2344
- await this._params.bridgeService.sendData({
2358
+ this._params.stream.pipe(new Writable({
2359
+ write: (chunk, _, callback) => {
2360
+ this._params.bridgeService.sendData({
2345
2361
  proxyId: this._proxyId,
2346
- payload: data
2347
- });
2348
- } catch (err) {
2349
- log13.catch(err, void 0, {
2350
- F: __dxlog_file13,
2351
- L: 67,
2352
- S: this,
2353
- C: (f, a) => f(...a)
2362
+ payload: chunk
2363
+ }).then(() => callback(), (err) => {
2364
+ log13.catch(err, void 0, {
2365
+ F: __dxlog_file13,
2366
+ L: 69,
2367
+ S: this,
2368
+ C: (f, a) => f(...a)
2369
+ });
2354
2370
  });
2355
2371
  }
2356
- };
2357
- this._params.stream.on("data", dataListener);
2358
- this._ctx.onDispose(() => {
2359
- this._params.stream.off("data", dataListener);
2360
- });
2372
+ }));
2361
2373
  }, (error) => log13.catch(error, void 0, {
2362
2374
  F: __dxlog_file13,
2363
- L: 73,
2375
+ L: 75,
2364
2376
  S: this,
2365
2377
  C: (f, a) => f(...a)
2366
2378
  }));
@@ -2406,7 +2418,7 @@ var WebRTCTransportProxy = class {
2406
2418
  } catch (err) {
2407
2419
  log13.catch(err, void 0, {
2408
2420
  F: __dxlog_file13,
2409
- L: 124,
2421
+ L: 126,
2410
2422
  S: this,
2411
2423
  C: (f, a) => f(...a)
2412
2424
  });
@@ -2492,4 +2504,4 @@ export {
2492
2504
  WebRTCTransportProxyFactory,
2493
2505
  createTeleportProtocolFactory
2494
2506
  };
2495
- //# sourceMappingURL=chunk-5R7TDXUU.mjs.map
2507
+ //# sourceMappingURL=chunk-HI2MCQKY.mjs.map