@neuroinfoapi-client/native 2.6.0 → 2.7.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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +291 -288
  3. package/package.json +50 -50
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Appstun
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Appstun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,288 +1,291 @@
1
- # @neuroinfoapi-client/native
2
-
3
- A comprehensive TypeScript/JavaScript client that provides full access to NeuroInfoAPI endpoints with proper type definitions.
4
-
5
- ## Other runtime clients
6
-
7
- - [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with the `ws` npm package, automatic protocol pongs, and header authentication by default.
8
- - [@neuroinfoapi-client/bun](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/bun/README.md): Bun's native WebSocket, automatic protocol pongs, and header authentication by default.
9
-
10
- ## Features
11
-
12
- - HTTP access to streams, VODs, schedules, subathons, blog and X feeds
13
- - Full TypeScript support with typed API responses and event payloads
14
- - HTTP Bearer authentication with an optional token in the constructor
15
- - Type-safe HTTP error handling through `{ data, error }`
16
- - Configurable API base URL and HTTP request timeout (10 seconds by default)
17
- - Standard WebSocket in browsers and Node.js, with ticket authentication
18
- - Real-time subscriptions with automatic reconnect and subscription recovery
19
- - JSON heartbeat with a 30-second interval and 10-second pong timeout by default
20
- - `NeuroInfoApiEventer` for polling-based updates (deprecated)
21
-
22
- ## Installation
23
-
24
- ```bash
25
- npm install @neuroinfoapi-client/native
26
- ```
27
-
28
- ## Quick Start
29
-
30
- ```ts
31
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
32
-
33
- // Optional token can be passed directly in the constructor
34
- const client = new NeuroInfoApiClient("your-api-token-here");
35
-
36
- const { data, error } = await client.getCurrentStream();
37
-
38
- if (error) {
39
- console.error(`Error ${error.code}: ${error.message}`);
40
- } else {
41
- console.log(data);
42
- }
43
- ```
44
-
45
- ## Client Configuration
46
-
47
- Constructor signature:
48
-
49
- ```ts
50
- new NeuroInfoApiClient(token?: string, options?: NeuroInfoApiClientOptions)
51
- ```
52
-
53
- `NeuroInfoApiClientOptions` supports:
54
-
55
- | Option | Default | Description |
56
- | ------------------ | ------------------------- | ---------------------------------------- |
57
- | `apiBaseUrl` | `neuroinfoapi.dev/api/v2` | API host and path without a protocol |
58
- | `useTls` | `true` | Use HTTPS when `true`, HTTP when `false` |
59
- | `requestTimeoutMs` | `10000` | HTTP request timeout in milliseconds |
60
-
61
- The legacy `baseUrl` option is deprecated and will be removed in a future major version.
62
-
63
- Examples:
64
-
65
- ```ts
66
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
67
-
68
- // 1) No token in constructor (set later)
69
- const clientA = new NeuroInfoApiClient();
70
- clientA.setApiToken("your-api-token-here");
71
-
72
- // 2) Token in constructor
73
- const clientB = new NeuroInfoApiClient("your-api-token-here");
74
-
75
- // 3) for testing with Mock-TesServer (https://github.com/NeuroInfoAPI/Mock-TestServer)
76
- const clientC = new NeuroInfoApiClient(undefined, {
77
- apiBaseUrl: "localhost:8787/api/v2",
78
- useTls: false,
79
- requestTimeoutMs: 15000,
80
- });
81
- ```
82
-
83
- ## Browser Usage
84
-
85
- ```ts
86
- import { NeuroInfoApiClient, NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
87
-
88
- const client = new NeuroInfoApiClient();
89
- client.setApiToken("your-api-token-here");
90
-
91
- // Browser-safe default uses ticket auth (no token in WS URL)
92
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
93
- await wsClient.connect();
94
- ```
95
-
96
- This package defaults to `authMethod: "ticket"` in browsers and in any other runtime. Set `authMethod: "header"` to send an `Authorization: Bearer` header when the global WebSocket implementation supports custom headers, including Node.js's built-in WebSocket (verified on Node v26.8.1), Bun, or a `ws` polyfill. Browsers do not support custom handshake headers; use ticket authentication there. For Node.js with `ws` already integrated, use `@neuroinfoapi-client/node`.
97
-
98
- ## Error Handling
99
-
100
- All HTTP API request methods return a result object with either `data` or `error`:
101
-
102
- ```ts
103
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
104
-
105
- const client = new NeuroInfoApiClient("your-api-token-here");
106
- const { data, error } = await client.getCurrentStream();
107
-
108
- if (error) {
109
- // error is NeuroApiError with code, message, and optional status
110
- console.log(`Error ${error.code}: ${error.message}`);
111
- } else if (data.isLive) {
112
- console.log(data.title);
113
- } else {
114
- console.log("Stream is offline");
115
- }
116
- ```
117
-
118
- ## HTTP API Methods
119
-
120
- All methods below return `Promise<ApiResult<T>>`:
121
-
122
- - `getCurrentStream()` — current Twitch stream state
123
- - `getAllVods()` — all Twitch VODs
124
- - `getVod(id)` — a VOD by stream ID
125
- - `getSchedule(week, year?)` — schedule for a specific week and optional year
126
- - `getLatestSchedule()` — latest schedule
127
- - `getScheduleWeeks()` — available schedule weeks grouped by year
128
- - `getDevstreamTimes()` — devstream schedule timestamps
129
- - `getScheduleSearch(query, options?)` — search schedules with filters and cursor pagination
130
- - `getCurrentSubathons()` — currently active subathons
131
- - `getSubathon(year)` — subathon data for a year
132
- - `getSubathonYears()` — available subathon years
133
- - `getBlogFeed(raw?)` — Neuro-sama blog feed; requires an API token
134
- - `getXFeed(user)` — cached X feed for `NeurosamaAI`, `EvilNeuroAI`, or `Vedal987`; requires an API token
135
-
136
- ## Schedule Search Pagination
137
-
138
- Use `getScheduleSearch` and continue with `nextCursor`.
139
- Optional filter: `type` (`normal`, `offline`, `canceled`, `TBD`, `unknown`).
140
-
141
- `/schedule/search` has rate limits (`6 requests/minute` and `2 requests/10 seconds` per token), so avoid tight loops.
142
-
143
- ```ts
144
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
145
-
146
- const client = new NeuroInfoApiClient("your-api-token-here");
147
- const firstPage = await client.getScheduleSearch("karaoke", { limit: 5, sort: "desc", type: "normal" });
148
- if (firstPage.error) {
149
- console.error(firstPage.error.code, firstPage.error.message);
150
- } else {
151
- console.log("matches:", firstPage.data.results.length);
152
-
153
- if (firstPage.data.nextCursor) {
154
- const secondPage = await client.getScheduleSearch("karaoke", {
155
- limit: 5,
156
- sort: "desc",
157
- cursor: firstPage.data.nextCursor,
158
- });
159
- console.log("next page:", secondPage.data?.results.length ?? 0);
160
- }
161
- }
162
- ```
163
-
164
- ## Event System (Deprecated)
165
-
166
- `NeuroInfoApiEventer` is deprecated in favor of `NeuroInfoApiWebsocketClient`.
167
-
168
- ```ts
169
- import { NeuroInfoApiEventer } from "@neuroinfoapi-client/native";
170
-
171
- const eventer = new NeuroInfoApiEventer();
172
- eventer.setApiToken("your-api-token-here");
173
-
174
- eventer.on("streamOnline", (stream) => {
175
- console.log(`${stream.title} is now live!`);
176
- });
177
-
178
- eventer.on(
179
- "scheduleUpdate",
180
- (schedule) => console.log(`New schedule for week ${schedule.week}`),
181
- (error) => console.log(`Failed to fetch schedule: ${error.code}`),
182
- );
183
-
184
- // Default: 60s, minimum: 10s
185
- eventer.fetchInterval = 30000;
186
- eventer.startEventLoop();
187
- ```
188
-
189
- Available events: `streamOnline`, `streamOffline`, `streamUpdate`, `scheduleUpdate`, `subathonUpdate`, `subathonGoalUpdate`
190
-
191
- ## WebSocket Client
192
-
193
- `heartbeatMonitoring` defaults to `true` and can also be changed on the client
194
- instance. Set it to `false` to disable heartbeat timeout monitoring; Native also
195
- stops its automatic JSON pings. Protocol pong replies and incoming `_pong`
196
- notifications remain active.
197
-
198
- Constructor signature:
199
-
200
- ```ts
201
- new NeuroInfoApiWebsocketClient(token: string, options?: NeuroInfoApiWebsocketClientOptions)
202
- ```
203
-
204
- The options include `apiBaseUrl`, `useTls`, `websocketUrl`, `authMethod`, `autoReconnect`, `maxReconnectAttempts`, `reconnectBaseDelay`, `heartbeatMonitoring`, `heartbeatIntervalMs`, `heartbeatTimeoutMs`, and `connectTimeoutMs`. The legacy WebSocket `baseUrl` option is deprecated; use `websocketUrl` for a full URL override.
205
-
206
- ```ts
207
- import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
208
-
209
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
210
-
211
- wsClient.on("_connected", (sessionId) => {
212
- console.log("Connected with session:", sessionId);
213
- });
214
-
215
- wsClient.on("_eventAdded", (eventType) => {
216
- console.log("Subscribed:", eventType);
217
- });
218
-
219
- wsClient.on("_eventRemoved", (eventType) => {
220
- console.log("Unsubscribed:", eventType);
221
- });
222
-
223
- wsClient.on("streamOnline", (stream) => {
224
- console.log("Stream online:", stream.title);
225
- });
226
-
227
- await wsClient.connect();
228
- ```
229
-
230
- Available WebSocket events:
231
-
232
- - `streamOnline`
233
- - `streamOffline`
234
- - `streamUpdate`
235
- - `secretneuroaccountOnline`
236
- - `streamRaidIncoming`
237
- - `streamRaidOutgoing`
238
- - `scheduleUpdate`
239
- - `subathonUpdate`
240
- - `subathonGoalUpdate`
241
- - `blogFeedUpdate`
242
- - `xFeedNewEntries`
243
- - `xFeedUpdate` (deprecated alias for `xFeedNewEntries`)
244
-
245
- **Heartbeat:** While connected, the client periodically sends a JSON `ping` and expects a `pong` from the server (default interval **30s**, pong timeout **10s**). If the pong is missing, the socket is closed and automatic reconnect runs—this detects stale or half-open connections. Disable or tune via constructor options: `heartbeatMonitoring`, `heartbeatIntervalMs` (minimum 5000), `heartbeatTimeoutMs` (minimum 1000). Keep the ping interval below the server WebSocket idle timeout if you self-host with aggressive idle limits.
246
-
247
- ## Unsubscribe and clean up
248
-
249
- Using the connected `wsClient` from the WebSocket example:
250
-
251
- ```ts
252
- const unsubscribe = wsClient.on("streamUpdate", (stream) => {
253
- console.log("Updated stream:", stream.title);
254
- });
255
-
256
- // Later, remove this listener.
257
- unsubscribe();
258
-
259
- // Disconnect intentionally; listeners are retained for a later connect().
260
- wsClient.disconnect();
261
-
262
- // When finished, remove every listener and disconnect.
263
- wsClient.destroy();
264
- ```
265
-
266
- `connect()` returns a promise that can reject. Handle connection failures with `try`/`catch`, and register an `_error` listener for errors after connecting:
267
-
268
- ```ts
269
- import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
270
-
271
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
272
- wsClient.on("_error", (error) => console.error("WebSocket error:", error));
273
-
274
- try {
275
- await wsClient.connect();
276
- } catch (error) {
277
- console.error("Connection failed:", error);
278
- wsClient.destroy();
279
- }
280
- ```
281
-
282
- ## Documentation
283
-
284
- - [API documentation](https://neuroinfoapi.dev/api/docs)
285
-
286
- ## License
287
-
288
- MIT
1
+ # @neuroinfoapi-client/native
2
+
3
+ A comprehensive TypeScript/JavaScript client that provides full access to NeuroInfoAPI endpoints with proper type definitions.
4
+
5
+ ## Other runtime clients
6
+
7
+ - [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with the `ws` npm package, automatic protocol pongs, and header authentication by default.
8
+ - [@neuroinfoapi-client/bun](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/bun/README.md): Bun's native WebSocket, automatic protocol pongs, and header authentication by default.
9
+
10
+ ## Features
11
+
12
+ - HTTP access to streams, VODs, schedules, subathons, shop products, blog and X feeds
13
+ - Full TypeScript support with typed API responses and event payloads
14
+ - HTTP Bearer authentication with an optional token in the constructor
15
+ - Type-safe HTTP error handling through `{ data, error }`
16
+ - Configurable API base URL and HTTP request timeout (10 seconds by default)
17
+ - Standard WebSocket in browsers and Node.js, with ticket authentication
18
+ - Real-time subscriptions with automatic reconnect and subscription recovery
19
+ - JSON heartbeat with a 30-second interval and 10-second pong timeout by default
20
+ - `NeuroInfoApiEventer` for polling-based updates (deprecated)
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @neuroinfoapi-client/native
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```ts
31
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
32
+
33
+ // Optional token can be passed directly in the constructor
34
+ const client = new NeuroInfoApiClient("your-api-token-here");
35
+
36
+ const { data, error } = await client.getCurrentStream();
37
+
38
+ if (error) {
39
+ console.error(`Error ${error.code}: ${error.message}`);
40
+ } else {
41
+ console.log(data);
42
+ }
43
+ ```
44
+
45
+ ## Client Configuration
46
+
47
+ Constructor signature:
48
+
49
+ ```ts
50
+ new NeuroInfoApiClient(token?: string, options?: NeuroInfoApiClientOptions)
51
+ ```
52
+
53
+ `NeuroInfoApiClientOptions` supports:
54
+
55
+ | Option | Default | Description |
56
+ | ------------------ | ------------------------- | ---------------------------------------- |
57
+ | `apiBaseUrl` | `neuroinfoapi.dev/api/v2` | API host and path without a protocol |
58
+ | `useTls` | `true` | Use HTTPS when `true`, HTTP when `false` |
59
+ | `requestTimeoutMs` | `10000` | HTTP request timeout in milliseconds |
60
+
61
+ The legacy `baseUrl` option is deprecated and will be removed in a future major version.
62
+
63
+ Examples:
64
+
65
+ ```ts
66
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
67
+
68
+ // 1) No token in constructor (set later)
69
+ const clientA = new NeuroInfoApiClient();
70
+ clientA.setApiToken("your-api-token-here");
71
+
72
+ // 2) Token in constructor
73
+ const clientB = new NeuroInfoApiClient("your-api-token-here");
74
+
75
+ // 3) for testing with Mock-TesServer (https://github.com/NeuroInfoAPI/Mock-TestServer)
76
+ const clientC = new NeuroInfoApiClient(undefined, {
77
+ apiBaseUrl: "localhost:8787/api/v2",
78
+ useTls: false,
79
+ requestTimeoutMs: 15000,
80
+ });
81
+ ```
82
+
83
+ ## Browser Usage
84
+
85
+ ```ts
86
+ import { NeuroInfoApiClient, NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
87
+
88
+ const client = new NeuroInfoApiClient();
89
+ client.setApiToken("your-api-token-here");
90
+
91
+ // Browser-safe default uses ticket auth (no token in WS URL)
92
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
93
+ await wsClient.connect();
94
+ ```
95
+
96
+ This package defaults to `authMethod: "ticket"` in browsers and in any other runtime. Set `authMethod: "header"` to send an `Authorization: Bearer` header when the global WebSocket implementation supports custom headers, including Node.js's built-in WebSocket (verified on Node v26.8.1), Bun, or a `ws` polyfill. Browsers do not support custom handshake headers; use ticket authentication there. For Node.js with `ws` already integrated, use `@neuroinfoapi-client/node`.
97
+
98
+ ## Error Handling
99
+
100
+ All HTTP API request methods return a result object with either `data` or `error`:
101
+
102
+ ```ts
103
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
104
+
105
+ const client = new NeuroInfoApiClient("your-api-token-here");
106
+ const { data, error } = await client.getCurrentStream();
107
+
108
+ if (error) {
109
+ // error is NeuroApiError with code, message, and optional status
110
+ console.log(`Error ${error.code}: ${error.message}`);
111
+ } else if (data.isLive) {
112
+ console.log(data.title);
113
+ } else {
114
+ console.log("Stream is offline");
115
+ }
116
+ ```
117
+
118
+ ## HTTP API Methods
119
+
120
+ All methods below return `Promise<ApiResult<T>>`:
121
+
122
+ - `getCurrentStream()` — current Twitch stream state
123
+ - `getAllVods()` — all Twitch VODs
124
+ - `getVod(id)` — a VOD by stream ID
125
+ - `getSchedule(week, year?)` — schedule for a specific week and optional year
126
+ - `getLatestSchedule()` — latest schedule
127
+ - `getScheduleWeeks()` — available schedule weeks grouped by year
128
+ - `getDevstreamTimes()` — devstream schedule timestamps
129
+ - `getScheduleSearch(query, options?)` — search schedules with filters and cursor pagination
130
+ - `getCurrentSubathons()` — currently active subathons
131
+ - `getSubathon(year)` — subathon data for a year
132
+ - `getSubathonYears()` — available subathon years
133
+ - `getBlogFeed(raw?)` — Neuro-sama blog feed; requires an API token
134
+ - `getShopProducts(currency?)` — shop catalog; requires an API token
135
+ - `getShopProduct(id, currency?)` — one shop product; requires an API token
136
+ - `getXFeed(user)` — cached X feed for `NeurosamaAI`, `EvilNeuroAI`, or `Vedal987`; requires an API token
137
+
138
+ ## Schedule Search Pagination
139
+
140
+ Use `getScheduleSearch` and continue with `nextCursor`.
141
+ Optional filter: `type` (`normal`, `offline`, `canceled`, `TBD`, `unknown`).
142
+
143
+ `/schedule/search` has rate limits (`6 requests/minute` and `2 requests/10 seconds` per token), so avoid tight loops.
144
+
145
+ ```ts
146
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/native";
147
+
148
+ const client = new NeuroInfoApiClient("your-api-token-here");
149
+ const firstPage = await client.getScheduleSearch("karaoke", { limit: 5, sort: "desc", type: "normal" });
150
+ if (firstPage.error) {
151
+ console.error(firstPage.error.code, firstPage.error.message);
152
+ } else {
153
+ console.log("matches:", firstPage.data.results.length);
154
+
155
+ if (firstPage.data.nextCursor) {
156
+ const secondPage = await client.getScheduleSearch("karaoke", {
157
+ limit: 5,
158
+ sort: "desc",
159
+ cursor: firstPage.data.nextCursor,
160
+ });
161
+ console.log("next page:", secondPage.data?.results.length ?? 0);
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## Event System (Deprecated)
167
+
168
+ `NeuroInfoApiEventer` is deprecated in favor of `NeuroInfoApiWebsocketClient`.
169
+
170
+ ```ts
171
+ import { NeuroInfoApiEventer } from "@neuroinfoapi-client/native";
172
+
173
+ const eventer = new NeuroInfoApiEventer();
174
+ eventer.setApiToken("your-api-token-here");
175
+
176
+ eventer.on("streamOnline", (stream) => {
177
+ console.log(`${stream.title} is now live!`);
178
+ });
179
+
180
+ eventer.on(
181
+ "scheduleUpdate",
182
+ (schedule) => console.log(`New schedule for week ${schedule.week}`),
183
+ (error) => console.log(`Failed to fetch schedule: ${error.code}`),
184
+ );
185
+
186
+ // Default: 60s, minimum: 10s
187
+ eventer.fetchInterval = 30000;
188
+ eventer.startEventLoop();
189
+ ```
190
+
191
+ Available events: `streamOnline`, `streamOffline`, `streamUpdate`, `scheduleUpdate`, `subathonUpdate`, `subathonGoalUpdate`
192
+
193
+ ## WebSocket Client
194
+
195
+ `heartbeatMonitoring` defaults to `true` and can also be changed on the client
196
+ instance. Set it to `false` to disable heartbeat timeout monitoring; Native also
197
+ stops its automatic JSON pings. Protocol pong replies and incoming `_pong`
198
+ notifications remain active.
199
+
200
+ Constructor signature:
201
+
202
+ ```ts
203
+ new NeuroInfoApiWebsocketClient(token: string, options?: NeuroInfoApiWebsocketClientOptions)
204
+ ```
205
+
206
+ The options include `apiBaseUrl`, `useTls`, `websocketUrl`, `authMethod`, `autoReconnect`, `maxReconnectAttempts`, `reconnectBaseDelay`, `heartbeatMonitoring`, `heartbeatIntervalMs`, `heartbeatTimeoutMs`, and `connectTimeoutMs`. The legacy WebSocket `baseUrl` option is deprecated; use `websocketUrl` for a full URL override.
207
+
208
+ ```ts
209
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
210
+
211
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
212
+
213
+ wsClient.on("_connected", (sessionId) => {
214
+ console.log("Connected with session:", sessionId);
215
+ });
216
+
217
+ wsClient.on("_eventAdded", (eventType) => {
218
+ console.log("Subscribed:", eventType);
219
+ });
220
+
221
+ wsClient.on("_eventRemoved", (eventType) => {
222
+ console.log("Unsubscribed:", eventType);
223
+ });
224
+
225
+ wsClient.on("streamOnline", (stream) => {
226
+ console.log("Stream online:", stream.title);
227
+ });
228
+
229
+ await wsClient.connect();
230
+ ```
231
+
232
+ Available WebSocket events:
233
+
234
+ - `streamOnline`
235
+ - `streamOffline`
236
+ - `streamUpdate`
237
+ - `secretneuroaccountOnline`
238
+ - `streamRaidIncoming`
239
+ - `streamRaidOutgoing`
240
+ - `scheduleUpdate`
241
+ - `subathonUpdate`
242
+ - `subathonGoalUpdate`
243
+ - `shopProductsUpdate`
244
+ - `blogFeedUpdate`
245
+ - `xFeedNewEntries`
246
+ - `xFeedUpdate` (deprecated alias for `xFeedNewEntries`)
247
+
248
+ **Heartbeat:** While connected, the client periodically sends a JSON `ping` and expects a `pong` from the server (default interval **30s**, pong timeout **10s**). If the pong is missing, the socket is closed and automatic reconnect runs—this detects stale or half-open connections. Disable or tune via constructor options: `heartbeatMonitoring`, `heartbeatIntervalMs` (minimum 5000), `heartbeatTimeoutMs` (minimum 1000). Keep the ping interval below the server WebSocket idle timeout if you self-host with aggressive idle limits.
249
+
250
+ ## Unsubscribe and clean up
251
+
252
+ Using the connected `wsClient` from the WebSocket example:
253
+
254
+ ```ts
255
+ const unsubscribe = wsClient.on("streamUpdate", (stream) => {
256
+ console.log("Updated stream:", stream.title);
257
+ });
258
+
259
+ // Later, remove this listener.
260
+ unsubscribe();
261
+
262
+ // Disconnect intentionally; listeners are retained for a later connect().
263
+ wsClient.disconnect();
264
+
265
+ // When finished, remove every listener and disconnect.
266
+ wsClient.destroy();
267
+ ```
268
+
269
+ `connect()` returns a promise that can reject. Handle connection failures with `try`/`catch`, and register an `_error` listener for errors after connecting:
270
+
271
+ ```ts
272
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/native";
273
+
274
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
275
+ wsClient.on("_error", (error) => console.error("WebSocket error:", error));
276
+
277
+ try {
278
+ await wsClient.connect();
279
+ } catch (error) {
280
+ console.error("Connection failed:", error);
281
+ wsClient.destroy();
282
+ }
283
+ ```
284
+
285
+ ## Documentation
286
+
287
+ - [API documentation](https://neuroinfoapi.dev/api/docs)
288
+
289
+ ## License
290
+
291
+ MIT
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@neuroinfoapi-client/native",
3
- "version": "2.6.0",
4
- "description": "A client for interacting with the NeuroInfoAPI (Native edition)",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
12
- }
13
- },
14
- "files": [
15
- "dist/*.js",
16
- "dist/*.d.ts",
17
- "README.md",
18
- "LICENSE"
19
- ],
20
- "scripts": {
21
- "build": "tsc -b",
22
- "typecheck": "tsc -p tsconfig.json --noEmit",
23
- "publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package native",
24
- "deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package native"
25
- },
26
- "keywords": [
27
- "neuroinfoapi",
28
- "nia",
29
- "vedal987",
30
- "neurosama",
31
- "neuro-sama"
32
- ],
33
- "author": "Appstun",
34
- "license": "MIT",
35
- "bugs": {
36
- "url": "https://github.com/NeuroInfoAPI/NPM-Package/issues"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/NeuroInfoAPI/NPM-Package.git",
41
- "directory": "packages/native"
42
- },
43
- "homepage": "https://neuroinfoapi.dev/api/docs",
44
- "dependencies": {
45
- "@neuroinfoapi-client/core": "2.6.0"
46
- },
47
- "publishConfig": {
48
- "access": "public"
49
- }
50
- }
1
+ {
2
+ "name": "@neuroinfoapi-client/native",
3
+ "version": "2.7.0",
4
+ "description": "A client for interacting with the NeuroInfoAPI (Native edition)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/*.js",
16
+ "dist/*.d.ts",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -b",
22
+ "typecheck": "tsc -p tsconfig.json --noEmit",
23
+ "publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package native",
24
+ "deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package native"
25
+ },
26
+ "keywords": [
27
+ "neuroinfoapi",
28
+ "nia",
29
+ "vedal987",
30
+ "neurosama",
31
+ "neuro-sama"
32
+ ],
33
+ "author": "Appstun",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/NeuroInfoAPI/NPM-Packages/issues"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/NeuroInfoAPI/NPM-Packages.git",
41
+ "directory": "packages/native"
42
+ },
43
+ "homepage": "https://neuroinfoapi.dev/api/docs",
44
+ "dependencies": {
45
+ "@neuroinfoapi-client/core": "2.7.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }