@pulsepairs/sdk 0.5.0 → 0.5.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/dist/ws.js +31 -1
- package/package.json +2 -2
package/dist/ws.js
CHANGED
|
@@ -154,14 +154,42 @@ export class UpDownWsClient {
|
|
|
154
154
|
openSocket() {
|
|
155
155
|
if (this.closed)
|
|
156
156
|
return;
|
|
157
|
+
// Close any socket we're superseding before opening a new one. Without
|
|
158
|
+
// this, a rapid connect→(reconnect|reconnectMode) churn could leave the
|
|
159
|
+
// previous socket open — especially one still in CONNECTING, whose
|
|
160
|
+
// `onopen` fires after we've moved on.
|
|
161
|
+
if (this.ws) {
|
|
162
|
+
const stale = this.ws;
|
|
163
|
+
stale.onopen = stale.onmessage = stale.onclose = stale.onerror = null;
|
|
164
|
+
try {
|
|
165
|
+
stale.close();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* ignore */
|
|
169
|
+
}
|
|
170
|
+
}
|
|
157
171
|
const ws = new WebSocket(this.url);
|
|
158
172
|
this.ws = ws;
|
|
159
173
|
this.state = "idle";
|
|
160
174
|
ws.onopen = () => {
|
|
175
|
+
// Guard: if we were disconnected, or a newer socket has superseded this
|
|
176
|
+
// one, this socket is an orphan (it finished CONNECTING after we moved
|
|
177
|
+
// on). Close it instead of leaving it open and streaming.
|
|
178
|
+
if (this.closed || this.ws !== ws) {
|
|
179
|
+
try {
|
|
180
|
+
ws.close();
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
/* ignore */
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
161
187
|
this.reconnect = 0;
|
|
162
188
|
void this.startHandshake();
|
|
163
189
|
};
|
|
164
190
|
ws.onmessage = (ev) => {
|
|
191
|
+
if (this.ws !== ws)
|
|
192
|
+
return; // ignore frames from a superseded socket
|
|
165
193
|
let parsed;
|
|
166
194
|
try {
|
|
167
195
|
parsed = JSON.parse(String(ev.data));
|
|
@@ -172,7 +200,9 @@ export class UpDownWsClient {
|
|
|
172
200
|
void this.handleIncoming(parsed);
|
|
173
201
|
};
|
|
174
202
|
ws.onclose = () => {
|
|
175
|
-
|
|
203
|
+
// A superseded socket's close must not trigger a reconnect — the live
|
|
204
|
+
// `this.ws` is a different, healthy socket.
|
|
205
|
+
if (this.closed || this.ws !== ws)
|
|
176
206
|
return;
|
|
177
207
|
if (this.state === "unauthed-failure") {
|
|
178
208
|
// signAuth was rejected — don't reconnect into a hot loop.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulsepairs/sdk",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Standalone SDK for the UpDown (PulsePairs) up/down prediction markets
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Standalone SDK for the UpDown (PulsePairs) up/down prediction markets — matcher REST/WS client, EIP-712 order signing, trade-math, and Alchemy Account Kit (smart-account) order signing for rain.trade integration.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|