@actuallab/rpc 12.1.100 → 12.1.115

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/dist/index.cjs CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  DEFAULT_SERIALIZATION_FORMAT: () => DEFAULT_SERIALIZATION_FORMAT,
25
25
  ENVELOPE_DELIMITER: () => ENVELOPE_DELIMITER,
26
26
  FRAME_DELIMITER: () => FRAME_DELIMITER,
27
+ RPC_CLOSE_CODE_UNSUPPORTED_FORMAT: () => RPC_CLOSE_CODE_UNSUPPORTED_FORMAT,
27
28
  RpcCallTypeId: () => RpcCallTypeId,
28
29
  RpcClientPeer: () => RpcClientPeer,
29
30
  RpcClientPeerReconnectDelayer: () => RpcClientPeerReconnectDelayer,
@@ -866,6 +867,7 @@ var RpcClientPeerReconnectDelayer = class extends import_core6.RetryDelayer {
866
867
 
867
868
  // src/rpc-peer.ts
868
869
  var DEFAULT_SERIALIZATION_FORMAT = "json5np";
870
+ var RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
869
871
  var defaultConnectionUrlResolver = (peer) => {
870
872
  const sep = peer.ref.includes("?") ? "&" : "?";
871
873
  return peer.ref + sep + `clientId=${peer.clientId}&f=${peer.serializationFormat}`;
@@ -1071,6 +1073,8 @@ var RpcClientPeer = class extends RpcPeer {
1071
1073
  /** Builds the WebSocket URL for this peer. Replace to customize URL construction. */
1072
1074
  connectionUrlResolver = defaultConnectionUrlResolver;
1073
1075
  peerChanged = new import_core7.EventHandlerSet();
1076
+ /** Fired when the server rejects the connection due to an unsupported serialization format (close code 4010). */
1077
+ unsupportedFormat = new import_core7.EventHandlerSet();
1074
1078
  reconnectDelayer = new RpcClientPeerReconnectDelayer();
1075
1079
  reconnectsAtChanged = new import_core7.EventHandlerSet();
1076
1080
  get reconnectsAt() {
@@ -1098,10 +1102,16 @@ var RpcClientPeer = class extends RpcPeer {
1098
1102
  async run(wsFactory) {
1099
1103
  const connUrl = this.connectionUrlResolver(this);
1100
1104
  while (!this._disposed) {
1105
+ let lastCloseCode = 0;
1106
+ let lastCloseReason = "";
1101
1107
  try {
1102
1108
  const ws = wsFactory?.(connUrl) ?? new WebSocket(connUrl);
1103
1109
  const conn = new RpcWebSocketConnection(ws);
1104
1110
  this._connectionKind = 1 /* Connecting */;
1111
+ conn.closed.add((ev) => {
1112
+ lastCloseCode = ev.code;
1113
+ lastCloseReason = ev.reason;
1114
+ });
1105
1115
  this._pendingHandshake = new import_core7.PromiseSource();
1106
1116
  this.setupConnection(conn);
1107
1117
  this._connection = void 0;
@@ -1134,6 +1144,11 @@ var RpcClientPeer = class extends RpcPeer {
1134
1144
  }
1135
1145
  this._connectionKind = 0 /* Disconnected */;
1136
1146
  if (this._disposed) break;
1147
+ if (lastCloseCode === RPC_CLOSE_CODE_UNSUPPORTED_FORMAT) {
1148
+ this.unsupportedFormat.trigger({ reason: lastCloseReason });
1149
+ this._disposed = true;
1150
+ break;
1151
+ }
1137
1152
  this._tryIndex++;
1138
1153
  const delay = this.reconnectDelayer.getDelay(this._tryIndex);
1139
1154
  if (delay.isLimitExceeded) {
@@ -1605,6 +1620,7 @@ var RpcPeerStateMonitor = class {
1605
1620
  DEFAULT_SERIALIZATION_FORMAT,
1606
1621
  ENVELOPE_DELIMITER,
1607
1622
  FRAME_DELIMITER,
1623
+ RPC_CLOSE_CODE_UNSUPPORTED_FORMAT,
1608
1624
  RpcCallTypeId,
1609
1625
  RpcClientPeer,
1610
1626
  RpcClientPeerReconnectDelayer,