@dxos/network-manager 0.3.5-main.927500d → 0.3.5-main.94a28b0

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.
@@ -2627,14 +2627,17 @@ var MemoryTransport = class _MemoryTransport {
2627
2627
  });
2628
2628
  this._remoteConnection._destroyed = true;
2629
2629
  _MemoryTransport._connections.delete(this._remoteInstanceId);
2630
- this._outgoingDelay.unpipe();
2631
- this._incomingDelay.unpipe();
2630
+ this.options.stream.unpipe(this._incomingDelay);
2631
+ this._incomingDelay.unpipe(this._remoteConnection.options.stream);
2632
+ this._remoteConnection.options.stream.unpipe(this._outgoingDelay);
2633
+ this._outgoingDelay.unpipe(this.options.stream);
2634
+ this.options.stream.unpipe(this._outgoingDelay);
2632
2635
  this._remoteConnection.closed.emit();
2633
2636
  this._remoteConnection._remoteConnection = void 0;
2634
2637
  this._remoteConnection = void 0;
2635
2638
  log10("closed", void 0, {
2636
2639
  F: __dxlog_file11,
2637
- L: 147,
2640
+ L: 150,
2638
2641
  S: this,
2639
2642
  C: (f, a) => f(...a)
2640
2643
  });
@@ -2642,7 +2645,7 @@ var MemoryTransport = class _MemoryTransport {
2642
2645
  this.closed.emit();
2643
2646
  log10("closed", void 0, {
2644
2647
  F: __dxlog_file11,
2645
- L: 151,
2648
+ L: 154,
2646
2649
  S: this,
2647
2650
  C: (f, a) => f(...a)
2648
2651
  });
@@ -2652,7 +2655,7 @@ var MemoryTransport = class _MemoryTransport {
2652
2655
  payload
2653
2656
  }, {
2654
2657
  F: __dxlog_file11,
2655
- L: 155,
2658
+ L: 158,
2656
2659
  S: this,
2657
2660
  C: (f, a) => f(...a)
2658
2661
  });
@@ -3023,7 +3026,7 @@ var SimplePeerTransportService = class {
3023
3026
 
3024
3027
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts
3025
3028
  import { Writable } from "@dxos/node-std/stream";
3026
- import { Event as Event9 } from "@dxos/async";
3029
+ import { Event as Event9, scheduleTask as scheduleTask4 } from "@dxos/async";
3027
3030
  import { Context as Context6 } from "@dxos/context";
3028
3031
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3029
3032
  import { invariant as invariant13 } from "@dxos/invariant";
@@ -3033,11 +3036,14 @@ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutE
3033
3036
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3034
3037
  import { arrayToBuffer } from "@dxos/util";
3035
3038
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3039
+ var RESP_MIN_THRESHOLD = 500;
3040
+ var TIMEOUT_THRESHOLD = 10;
3036
3041
  var SimplePeerTransportProxy = class {
3037
3042
  constructor(_params) {
3038
3043
  this._params = _params;
3039
3044
  this._proxyId = PublicKey12.random();
3040
3045
  this._ctx = new Context6();
3046
+ this._timeoutCount = 0;
3041
3047
  this.closed = new Event9();
3042
3048
  this.connected = new Event9();
3043
3049
  this.errors = new ErrorStream5();
@@ -3050,7 +3056,7 @@ var SimplePeerTransportProxy = class {
3050
3056
  this._serviceStream.subscribe(async (event) => {
3051
3057
  log13("SimplePeerTransportProxy: event", event, {
3052
3058
  F: __dxlog_file14,
3053
- L: 55,
3059
+ L: 59,
3054
3060
  S: this,
3055
3061
  C: (f, a) => f(...a)
3056
3062
  });
@@ -3062,24 +3068,63 @@ var SimplePeerTransportProxy = class {
3062
3068
  await this._handleSignal(event.signal);
3063
3069
  }
3064
3070
  });
3065
- this._params.stream.pipe(new Writable({
3071
+ const proxyStream = new Writable({
3066
3072
  write: (chunk, _, callback) => {
3073
+ const then = performance.now();
3067
3074
  this._params.bridgeService.sendData({
3068
3075
  proxyId: this._proxyId,
3069
3076
  payload: chunk
3070
- }).then(() => callback(), (err) => {
3071
- log13.catch(err, void 0, {
3072
- F: __dxlog_file14,
3073
- L: 76,
3074
- S: this,
3075
- C: (f, a) => f(...a)
3076
- });
3077
+ }).then(() => {
3078
+ if (performance.now() - then > RESP_MIN_THRESHOLD) {
3079
+ log13("slow response, delaying callback", void 0, {
3080
+ F: __dxlog_file14,
3081
+ L: 80,
3082
+ S: this,
3083
+ C: (f, a) => f(...a)
3084
+ });
3085
+ scheduleTask4(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
3086
+ } else {
3087
+ callback();
3088
+ }
3089
+ this._timeoutCount = 0;
3090
+ }, (err) => {
3091
+ if (err instanceof TimeoutError2 || err.constructor.name === "TimeoutError") {
3092
+ if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
3093
+ throw new TimeoutError2(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3094
+ } else {
3095
+ log13("timeout error, but still invoking callback", void 0, {
3096
+ F: __dxlog_file14,
3097
+ L: 92,
3098
+ S: this,
3099
+ C: (f, a) => f(...a)
3100
+ });
3101
+ callback();
3102
+ }
3103
+ } else {
3104
+ log13.catch(err, void 0, {
3105
+ F: __dxlog_file14,
3106
+ L: 96,
3107
+ S: this,
3108
+ C: (f, a) => f(...a)
3109
+ });
3110
+ }
3077
3111
  });
3078
3112
  }
3079
- }));
3113
+ });
3114
+ proxyStream.on("error", (err) => {
3115
+ log13("proxystream error", {
3116
+ err
3117
+ }, {
3118
+ F: __dxlog_file14,
3119
+ L: 104,
3120
+ S: this,
3121
+ C: (f, a) => f(...a)
3122
+ });
3123
+ });
3124
+ this._params.stream.pipe(proxyStream);
3080
3125
  }, (error) => log13.catch(error, void 0, {
3081
3126
  F: __dxlog_file14,
3082
- L: 83,
3127
+ L: 109,
3083
3128
  S: this,
3084
3129
  C: (f, a) => f(...a)
3085
3130
  }));
@@ -3125,7 +3170,7 @@ var SimplePeerTransportProxy = class {
3125
3170
  } catch (err) {
3126
3171
  log13.catch(err, void 0, {
3127
3172
  F: __dxlog_file14,
3128
- L: 134,
3173
+ L: 160,
3129
3174
  S: this,
3130
3175
  C: (f, a) => f(...a)
3131
3176
  });
@@ -3161,7 +3206,7 @@ var SimplePeerTransportProxyFactory = class {
3161
3206
  createTransport(options) {
3162
3207
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3163
3208
  F: __dxlog_file14,
3164
- L: 171,
3209
+ L: 197,
3165
3210
  S: this,
3166
3211
  A: [
3167
3212
  "this._bridgeService",
@@ -3602,4 +3647,4 @@ export {
3602
3647
  TcpTransport,
3603
3648
  createTeleportProtocolFactory
3604
3649
  };
3605
- //# sourceMappingURL=chunk-W7BW2FK6.mjs.map
3650
+ //# sourceMappingURL=chunk-APBMCUJP.mjs.map