@opensea/sdk 11.8.0 → 12.0.0
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/README.md +46 -15
- package/lib/api/api.d.ts +9 -0
- package/lib/api/api.js +15 -2
- package/lib/api/api.js.map +1 -1
- package/lib/api/collections.d.ts +7 -0
- package/lib/api/collections.js +10 -1
- package/lib/api/collections.js.map +1 -1
- package/lib/api/fetcher.d.ts +5 -2
- package/lib/api/types.d.ts +20 -64
- package/lib/api/types.js.map +1 -1
- package/lib/api/walletAuth.d.ts +95 -8
- package/lib/api/walletAuth.js +75 -6
- package/lib/api/walletAuth.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/orders/attribution.d.ts +18 -0
- package/lib/orders/attribution.js +29 -0
- package/lib/orders/attribution.js.map +1 -0
- package/lib/orders/privateListings.js +8 -0
- package/lib/orders/privateListings.js.map +1 -1
- package/lib/orders/types.d.ts +16 -28
- package/lib/orders/types.js.map +1 -1
- package/lib/scopes.d.ts +1 -0
- package/lib/scopes.js +1 -0
- package/lib/scopes.js.map +1 -1
- package/lib/sdk/fulfillment.js +7 -3
- package/lib/sdk/fulfillment.js.map +1 -1
- package/lib/stream/client.d.ts +80 -0
- package/lib/stream/client.js +191 -0
- package/lib/stream/client.js.map +1 -0
- package/lib/stream/constants.d.ts +3 -0
- package/lib/stream/constants.js +8 -0
- package/lib/stream/constants.js.map +1 -0
- package/lib/stream/helpers.d.ts +1 -0
- package/lib/stream/helpers.js +8 -0
- package/lib/stream/helpers.js.map +1 -0
- package/lib/stream/index.d.ts +17 -0
- package/lib/stream/index.js +34 -0
- package/lib/stream/index.js.map +1 -0
- package/lib/stream/transport/phoenix.d.ts +121 -0
- package/lib/stream/transport/phoenix.js +642 -0
- package/lib/stream/transport/phoenix.js.map +1 -0
- package/lib/stream/transport/types.d.ts +85 -0
- package/lib/stream/transport/types.js +24 -0
- package/lib/stream/transport/types.js.map +1 -0
- package/lib/stream/types.d.ts +238 -0
- package/lib/stream/types.js +36 -0
- package/lib/stream/types.js.map +1 -0
- package/lib/types.d.ts +14 -0
- package/lib/utils/units.d.ts +5 -0
- package/lib/utils/units.js +48 -9
- package/lib/utils/units.js.map +1 -1
- package/package.json +10 -9
- package/src/api/api.ts +19 -2
- package/src/api/collections.ts +14 -1
- package/src/api/fetcher.ts +5 -2
- package/src/api/types.ts +27 -64
- package/src/api/walletAuth.ts +100 -13
- package/src/index.ts +1 -1
- package/src/orders/attribution.ts +29 -0
- package/src/orders/privateListings.ts +15 -0
- package/src/orders/types.ts +21 -44
- package/src/scopes.ts +1 -0
- package/src/sdk/fulfillment.ts +8 -3
- package/src/stream/client.ts +299 -0
- package/src/stream/constants.ts +5 -0
- package/src/stream/helpers.ts +3 -0
- package/src/stream/index.ts +18 -0
- package/src/stream/transport/phoenix.ts +815 -0
- package/src/stream/transport/types.ts +91 -0
- package/src/stream/types.ts +289 -0
- package/src/types.ts +14 -0
- package/src/utils/units.ts +54 -9
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenSeaStreamClient = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const phoenix_1 = require("./transport/phoenix");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
/**
|
|
9
|
+
* Client for the OpenSea Stream API.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { OpenSeaStreamClient } from "@opensea/sdk/stream"
|
|
14
|
+
*
|
|
15
|
+
* const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
|
|
16
|
+
*
|
|
17
|
+
* const unsubscribe = client.onItemListed("doodles-official", event => {
|
|
18
|
+
* console.log(event.payload.item.nft_id)
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category Main Classes
|
|
23
|
+
*/
|
|
24
|
+
class OpenSeaStreamClient {
|
|
25
|
+
transport;
|
|
26
|
+
logLevel;
|
|
27
|
+
onEvent;
|
|
28
|
+
constructor({ network = types_1.Network.MAINNET, apiKey, token, apiUrl, connectOptions, logLevel = types_1.LogLevel.INFO, onError, onEvent = () => true, }) {
|
|
29
|
+
const key = apiKey ?? token;
|
|
30
|
+
if (!key) {
|
|
31
|
+
throw new Error("An OpenSea API key is required. Pass it as `apiKey` when constructing OpenSeaStreamClient.");
|
|
32
|
+
}
|
|
33
|
+
this.logLevel = logLevel;
|
|
34
|
+
this.onEvent = onEvent;
|
|
35
|
+
const endpoint = apiUrl || constants_1.ENDPOINTS[network];
|
|
36
|
+
const { params, ...transportOptions } = connectOptions ?? {};
|
|
37
|
+
this.transport = new phoenix_1.PhoenixChannelsTransport({
|
|
38
|
+
endpoint,
|
|
39
|
+
params: { token: key, ...params },
|
|
40
|
+
...transportOptions,
|
|
41
|
+
logger: message => this.debug(message),
|
|
42
|
+
});
|
|
43
|
+
this.transport.onError(onError ?? (error => this.error(error)));
|
|
44
|
+
}
|
|
45
|
+
log(level, message) {
|
|
46
|
+
if (this.logLevel > level) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
switch (level) {
|
|
50
|
+
case types_1.LogLevel.DEBUG:
|
|
51
|
+
console.debug("[DEBUG]:", message);
|
|
52
|
+
break;
|
|
53
|
+
case types_1.LogLevel.INFO:
|
|
54
|
+
console.info("[INFO]:", message);
|
|
55
|
+
break;
|
|
56
|
+
case types_1.LogLevel.WARN:
|
|
57
|
+
console.warn("[WARN]:", message);
|
|
58
|
+
break;
|
|
59
|
+
case types_1.LogLevel.ERROR:
|
|
60
|
+
console.error("[ERROR]:", message);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
debug(message) {
|
|
65
|
+
this.log(types_1.LogLevel.DEBUG, message);
|
|
66
|
+
}
|
|
67
|
+
info(message) {
|
|
68
|
+
this.log(types_1.LogLevel.INFO, message);
|
|
69
|
+
}
|
|
70
|
+
warn(message) {
|
|
71
|
+
this.log(types_1.LogLevel.WARN, message);
|
|
72
|
+
}
|
|
73
|
+
error(message) {
|
|
74
|
+
this.log(types_1.LogLevel.ERROR, message);
|
|
75
|
+
}
|
|
76
|
+
connect = () => {
|
|
77
|
+
this.debug("Connecting to socket");
|
|
78
|
+
this.transport.connect();
|
|
79
|
+
};
|
|
80
|
+
disconnect = (callback = () => this.info(`Successfully disconnected from socket`)) => {
|
|
81
|
+
return this.transport.disconnect(callback);
|
|
82
|
+
};
|
|
83
|
+
on = (eventType, collectionSlug, callback, eventTypes) => {
|
|
84
|
+
const topic = (0, helpers_1.collectionTopic)(collectionSlug);
|
|
85
|
+
this.debug(`Subscribing to ${eventType} events on ${topic}`);
|
|
86
|
+
const onClientEvent = this.onEvent;
|
|
87
|
+
const handler = (message) => {
|
|
88
|
+
const event = message;
|
|
89
|
+
if (onClientEvent(collectionSlug, eventType, event)) {
|
|
90
|
+
callback(event);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const subscription = this.transport.subscribe(topic, { eventTypes }, {
|
|
94
|
+
onSubscribed: () => this.info(`Successfully joined channel "${topic}"`),
|
|
95
|
+
onSubscribeError: reason => {
|
|
96
|
+
this.error(`Failed to join channel "${topic}"`);
|
|
97
|
+
this.debug(reason);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
const off = subscription.on(eventType, handler);
|
|
101
|
+
return () => {
|
|
102
|
+
this.debug(`Unsubscribing from ${eventType} events on ${topic}`);
|
|
103
|
+
// Removes only this handler. The topic is torn down once nothing is
|
|
104
|
+
// listening to it. The original stream-js client left the whole channel
|
|
105
|
+
// here, which silently killed sibling subscriptions on the same
|
|
106
|
+
// collection.
|
|
107
|
+
off();
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
onItemMetadataUpdated = (collectionSlug, callback) => {
|
|
111
|
+
return this.on(types_1.EventType.ITEM_METADATA_UPDATED, collectionSlug, callback);
|
|
112
|
+
};
|
|
113
|
+
onItemCancelled = (collectionSlug, callback) => {
|
|
114
|
+
return this.on(types_1.EventType.ITEM_CANCELLED, collectionSlug, callback);
|
|
115
|
+
};
|
|
116
|
+
onItemListed = (collectionSlug, callback) => {
|
|
117
|
+
return this.on(types_1.EventType.ITEM_LISTED, collectionSlug, callback);
|
|
118
|
+
};
|
|
119
|
+
onItemSold = (collectionSlug, callback) => {
|
|
120
|
+
return this.on(types_1.EventType.ITEM_SOLD, collectionSlug, callback);
|
|
121
|
+
};
|
|
122
|
+
onItemTransferred = (collectionSlug, callback) => {
|
|
123
|
+
return this.on(types_1.EventType.ITEM_TRANSFERRED, collectionSlug, callback);
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* No-op. The Stream API does not emit `item_received_offer` and never has, so
|
|
127
|
+
* this only ever registered a handler that could not fire. Item-level offers
|
|
128
|
+
* arrive as `item_received_bid`, so use {@link onItemReceivedBid} instead.
|
|
129
|
+
*
|
|
130
|
+
* Kept callable, and kept from opening a connection for a topic that yields
|
|
131
|
+
* nothing, so existing call sites keep compiling and running unchanged.
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Use {@link onItemReceivedBid}. This does nothing.
|
|
134
|
+
* @hidden
|
|
135
|
+
*/
|
|
136
|
+
onItemReceivedOffer = (_collectionSlug, _callback) => {
|
|
137
|
+
this.warn("onItemReceivedOffer does nothing: the Stream API does not emit item_received_offer. Item-level offers arrive as item_received_bid, via onItemReceivedBid.");
|
|
138
|
+
return () => { };
|
|
139
|
+
};
|
|
140
|
+
onItemReceivedBid = (collectionSlug, callback) => {
|
|
141
|
+
return this.on(types_1.EventType.ITEM_RECEIVED_BID, collectionSlug, callback);
|
|
142
|
+
};
|
|
143
|
+
onCollectionOffer = (collectionSlug, callback) => {
|
|
144
|
+
return this.on(types_1.EventType.COLLECTION_OFFER, collectionSlug, callback);
|
|
145
|
+
};
|
|
146
|
+
onTraitOffer = (collectionSlug, callback) => {
|
|
147
|
+
return this.on(types_1.EventType.TRAIT_OFFER, collectionSlug, callback);
|
|
148
|
+
};
|
|
149
|
+
onOrderInvalidate = (collectionSlug, callback) => {
|
|
150
|
+
return this.on(types_1.EventType.ORDER_INVALIDATE, collectionSlug, callback);
|
|
151
|
+
};
|
|
152
|
+
onOrderRevalidate = (collectionSlug, callback) => {
|
|
153
|
+
return this.on(types_1.EventType.ORDER_REVALIDATE, collectionSlug, callback);
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to several event types on one collection with a single callback,
|
|
157
|
+
* filtered server-side to the requested types.
|
|
158
|
+
*
|
|
159
|
+
* The callback receives `BaseStreamMessage<unknown>`: one subscription can
|
|
160
|
+
* deliver several event types, so there is no single payload type to hand
|
|
161
|
+
* back. `event_type` identifies which arrived, and the payload needs
|
|
162
|
+
* narrowing before use.
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* client.onEvents(slug, [EventType.ITEM_SOLD, EventType.ITEM_LISTED], event => {
|
|
166
|
+
* if (event.event_type === EventType.ITEM_SOLD) {
|
|
167
|
+
* const sale = event as ItemSoldEvent
|
|
168
|
+
* console.log(sale.payload.sale_price)
|
|
169
|
+
* }
|
|
170
|
+
* })
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* Use the typed single-event methods, such as `onItemSold`, when you want the
|
|
174
|
+
* payload typed for you.
|
|
175
|
+
*
|
|
176
|
+
* @param collectionSlug collection slug, or `"*"` for all collections
|
|
177
|
+
* @param eventTypes event types to subscribe to
|
|
178
|
+
* @param callback invoked for every subscribed event type
|
|
179
|
+
* @returns a function that removes all of this call's handlers
|
|
180
|
+
*/
|
|
181
|
+
onEvents = (collectionSlug, eventTypes, callback) => {
|
|
182
|
+
const subscriptions = eventTypes.map(eventType => this.on(eventType, collectionSlug, callback, eventTypes));
|
|
183
|
+
return () => {
|
|
184
|
+
for (const unsubscribe of subscriptions) {
|
|
185
|
+
unsubscribe();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
exports.OpenSeaStreamClient = OpenSeaStreamClient;
|
|
191
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/stream/client.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,uCAA2C;AAC3C,iDAA8D;AAE9D,mCAkBgB;AAEhB;;;;;;;;;;;;;;;GAeG;AACH,MAAa,mBAAmB;IACtB,SAAS,CAAiB;IAC1B,QAAQ,CAAU;IAClB,OAAO,CAAe;IAE9B,YAAY,EACV,OAAO,GAAG,eAAO,CAAC,OAAO,EACzB,MAAM,EACN,KAAK,EACL,MAAM,EACN,cAAc,EACd,QAAQ,GAAG,gBAAQ,CAAC,IAAI,EACxB,OAAO,EACP,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,GACP;QACb,MAAM,GAAG,GAAG,MAAM,IAAI,KAAK,CAAA;QAC3B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAA;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QAEtB,MAAM,QAAQ,GAAG,MAAM,IAAI,qBAAS,CAAC,OAAO,CAAC,CAAA;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,GAAG,cAAc,IAAI,EAAE,CAAA;QAE5D,IAAI,CAAC,SAAS,GAAG,IAAI,kCAAwB,CAAC;YAC5C,QAAQ;YACR,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE;YACjC,GAAG,gBAAgB;YACnB,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;SACvC,CAAC,CAAA;QAEF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C;QACH,CAAC,CAAA;IACH,CAAC,CAAA;CACF;AAlQD,kDAkQC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ENDPOINTS = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
exports.ENDPOINTS = {
|
|
6
|
+
[types_1.Network.MAINNET]: "wss://stream-api.opensea.io/socket",
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/stream/constants.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAEpB,QAAA,SAAS,GAAG;IACvB,CAAC,eAAO,CAAC,OAAO,CAAC,EAAE,oCAAoC;CACxD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const collectionTopic: (slug: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectionTopic = void 0;
|
|
4
|
+
const collectionTopic = (slug) => {
|
|
5
|
+
return `collection:${slug}`;
|
|
6
|
+
};
|
|
7
|
+
exports.collectionTopic = collectionTopic;
|
|
8
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/stream/helpers.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE;IAC9C,OAAO,cAAc,IAAI,EAAE,CAAA;AAC7B,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenSea Stream API client.
|
|
3
|
+
*
|
|
4
|
+
* Subscribe to real-time marketplace events over WebSocket.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { OpenSeaStreamClient } from "@opensea/sdk/stream"
|
|
9
|
+
*
|
|
10
|
+
* const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
|
|
11
|
+
* client.onItemSold("doodles-official", event => console.log(event))
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
export * from "./client";
|
|
17
|
+
export * from "./types";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenSea Stream API client.
|
|
4
|
+
*
|
|
5
|
+
* Subscribe to real-time marketplace events over WebSocket.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { OpenSeaStreamClient } from "@opensea/sdk/stream"
|
|
10
|
+
*
|
|
11
|
+
* const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
|
|
12
|
+
* client.onItemSold("doodles-official", event => console.log(event))
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
29
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./client"), exports);
|
|
33
|
+
__exportStar(require("./types"), exports);
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,2CAAwB;AACxB,0CAAuB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { StreamMessageHandler, StreamSubscription, StreamTransport, StreamWebSocketConstructor, SubscribeCallbacks, SubscribeOptions } from "./types";
|
|
2
|
+
export interface PhoenixTransportOptions {
|
|
3
|
+
/** Base socket URL, e.g. `wss://stream-api.opensea.io/socket`. */
|
|
4
|
+
endpoint: string;
|
|
5
|
+
/** Query parameters appended to the socket URL, e.g. the API key. */
|
|
6
|
+
params?: Record<string, string>;
|
|
7
|
+
/** WebSocket implementation. Defaults to the global `WebSocket`. */
|
|
8
|
+
transport?: StreamWebSocketConstructor;
|
|
9
|
+
/** Milliseconds to wait for a subscribe acknowledgement. Default 10000. */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Milliseconds between heartbeats. Default 30000. */
|
|
12
|
+
heartbeatIntervalMs?: number;
|
|
13
|
+
/** Backoff for reconnect attempt `tries` (1-indexed). */
|
|
14
|
+
reconnectAfterMs?: (tries: number) => number;
|
|
15
|
+
/** Optional debug logger. */
|
|
16
|
+
logger?: (message: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class PhoenixChannelsTransport implements StreamTransport {
|
|
19
|
+
private readonly endpoint;
|
|
20
|
+
private readonly params;
|
|
21
|
+
private readonly webSocketCtor;
|
|
22
|
+
private readonly timeout;
|
|
23
|
+
private readonly heartbeatIntervalMs;
|
|
24
|
+
private readonly reconnectAfterMs;
|
|
25
|
+
private readonly logger?;
|
|
26
|
+
private socket;
|
|
27
|
+
private readonly subscriptions;
|
|
28
|
+
private readonly pendingReplies;
|
|
29
|
+
private errorHandlers;
|
|
30
|
+
/**
|
|
31
|
+
* Unsubscribe callbacks still waiting for a `phx_leave` reply. `disconnect()`
|
|
32
|
+
* closes the socket without a round trip, so these are drained there instead;
|
|
33
|
+
* otherwise a caller awaiting unsubscribe confirmation waits forever.
|
|
34
|
+
*/
|
|
35
|
+
private readonly pendingUnsubscribes;
|
|
36
|
+
private refCounter;
|
|
37
|
+
private reconnectTries;
|
|
38
|
+
private reconnectTimer;
|
|
39
|
+
private heartbeatTimer;
|
|
40
|
+
private pendingHeartbeatRef;
|
|
41
|
+
private disconnectedIntentionally;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the current socket has ever answered us. An open socket is not
|
|
44
|
+
* proof of a working connection: a server that accepts the TCP/WS handshake
|
|
45
|
+
* but never replies would otherwise reset the backoff on every attempt and
|
|
46
|
+
* be hammered at the shortest delay forever.
|
|
47
|
+
*/
|
|
48
|
+
private connectionProven;
|
|
49
|
+
constructor(options: PhoenixTransportOptions);
|
|
50
|
+
endpointUrl(): string;
|
|
51
|
+
protocol(): string;
|
|
52
|
+
connect(): void;
|
|
53
|
+
isConnected(): boolean;
|
|
54
|
+
disconnect(onDisconnect?: () => void): void;
|
|
55
|
+
onError(handler: (error: unknown) => void): void;
|
|
56
|
+
/** Surface an error raised by consumer code, used by subscriptions. */
|
|
57
|
+
reportError(error: unknown): void;
|
|
58
|
+
/**
|
|
59
|
+
* Run a consumer callback without letting it escape into our state machine.
|
|
60
|
+
*
|
|
61
|
+
* These fire from inside teardown and reply handling, where an escaping
|
|
62
|
+
* exception would skip the work that follows: a throwing unsubscribe
|
|
63
|
+
* callback would abort `handleClose` before `scheduleReconnect`, leaving the
|
|
64
|
+
* client permanently disconnected, and a throwing subscribe callback would
|
|
65
|
+
* starve every later subscriber to the same topic.
|
|
66
|
+
*/
|
|
67
|
+
private safeInvoke;
|
|
68
|
+
private handleOpen;
|
|
69
|
+
private handleClose;
|
|
70
|
+
private scheduleReconnect;
|
|
71
|
+
private clearReconnectTimer;
|
|
72
|
+
private startHeartbeat;
|
|
73
|
+
private stopHeartbeat;
|
|
74
|
+
private sendHeartbeat;
|
|
75
|
+
/** Close the socket without marking the disconnect intentional. */
|
|
76
|
+
private teardownForReconnect;
|
|
77
|
+
subscribe(topic: string, options?: SubscribeOptions, callbacks?: SubscribeCallbacks): StreamSubscription;
|
|
78
|
+
private sendJoin;
|
|
79
|
+
/**
|
|
80
|
+
* Rejoin a topic whose channel died while the socket stayed open. Uses the
|
|
81
|
+
* same backoff schedule as reconnects, so a channel that keeps crashing does
|
|
82
|
+
* not turn into a join loop.
|
|
83
|
+
*/
|
|
84
|
+
private scheduleRejoin;
|
|
85
|
+
private clearRejoinTimer;
|
|
86
|
+
/**
|
|
87
|
+
* A topic is joined once and shared, and the join payload carries the
|
|
88
|
+
* server-side `event_types` filter. A later subscriber asking for an event
|
|
89
|
+
* outside that filter would otherwise register a handler the server never
|
|
90
|
+
* feeds, which fails silently. Widen the filter and re-join instead.
|
|
91
|
+
*
|
|
92
|
+
* `undefined` means no filter, so it is the widest value rather than the
|
|
93
|
+
* narrowest: an individual `on*` call subscribes to everything.
|
|
94
|
+
*/
|
|
95
|
+
private widenFilterIfNeeded;
|
|
96
|
+
private drainPendingUnsubscribes;
|
|
97
|
+
/** Called by a subscription, and directly by the client. */
|
|
98
|
+
unsubscribeTopic(topic: string, onUnsubscribed?: () => void): void;
|
|
99
|
+
/** Remove a single handler, unsubscribing only when the topic goes quiet. */
|
|
100
|
+
removeHandler(topic: string, event: string, handler: StreamMessageHandler, onUnsubscribed?: () => void): void;
|
|
101
|
+
private handleMessage;
|
|
102
|
+
private handleReply;
|
|
103
|
+
private awaitReply;
|
|
104
|
+
/**
|
|
105
|
+
* Drop every in-flight reply without invoking its handler. The socket going
|
|
106
|
+
* away is not a rejection: a join whose ack never arrives is re-sent by
|
|
107
|
+
* `handleOpen` after the reconnect, so reporting it as a subscribe failure
|
|
108
|
+
* here would be both wrong and noisy.
|
|
109
|
+
*
|
|
110
|
+
* Unsubscribes are the exception and are settled rather than dropped. A left
|
|
111
|
+
* topic stays left across a reconnect, so its acknowledgement is never coming
|
|
112
|
+
* and a caller waiting on one would hang. Draining here covers every teardown
|
|
113
|
+
* path: `disconnect`, `handleClose`, and `teardownForReconnect`.
|
|
114
|
+
*/
|
|
115
|
+
private clearPendingReplies;
|
|
116
|
+
private push;
|
|
117
|
+
private decode;
|
|
118
|
+
private nextRef;
|
|
119
|
+
private emitError;
|
|
120
|
+
private log;
|
|
121
|
+
}
|