@0dotxyz/p0-ts-sdk 2.2.0-alpha.5 → 2.2.0-alpha.7

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/vendor.js CHANGED
@@ -29235,12 +29235,28 @@ var V1Client = class _V1Client {
29235
29235
  return new Promise((resolve, reject) => {
29236
29236
  const ws = new WebSocket(url, [SUBPROTOCOL]);
29237
29237
  ws.binaryType = "arraybuffer";
29238
- ws.on("open", () => {
29238
+ const onOpen = () => {
29239
+ ws.off("error", onError);
29240
+ ws.off("close", onClose);
29239
29241
  resolve(new _V1Client(ws));
29240
- });
29241
- ws.on("error", (err) => {
29242
+ };
29243
+ const onError = (err) => {
29244
+ ws.off("open", onOpen);
29245
+ ws.off("close", onClose);
29242
29246
  reject(err);
29243
- });
29247
+ };
29248
+ const onClose = (code, reason) => {
29249
+ ws.off("open", onOpen);
29250
+ ws.off("error", onError);
29251
+ reject(
29252
+ new Error(
29253
+ `WebSocket closed before open (code=${code}${reason.length ? `, reason=${reason.toString()}` : ""})`
29254
+ )
29255
+ );
29256
+ };
29257
+ ws.once("open", onOpen);
29258
+ ws.once("error", onError);
29259
+ ws.once("close", onClose);
29244
29260
  });
29245
29261
  }
29246
29262
  // --- Constructor ---