easyjssdk 1.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 ADDED
@@ -0,0 +1,103 @@
1
+ # EasyJSSDK
2
+
3
+ A simple and easy-to-use communication SDK for WuKongIM, based on its JSON-RPC protocol.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install easyjssdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ // Import necessary components
15
+ import { WKIM, WKIMChannelType, WKIMEvent } from 'easyjssdk';
16
+
17
+ // 1. Initialization
18
+ const im = WKIM.init("ws://your-wukongim-server.com:5200", {
19
+ uid: "your_user_id",
20
+ token: "your_auth_token"
21
+ // deviceId: "optional_device_id", // Optional
22
+ // deviceFlag: 2 // Optional (1:APP, 2:WEB, default is 2)
23
+ });
24
+
25
+ // 2. Setup Event Listeners
26
+ im.on(WKIMEvent.Connect, (connectResult) => {
27
+ console.log("IM Connected!", connectResult);
28
+ // Connection successful, you can now send messages
29
+ });
30
+
31
+ im.on(WKIMEvent.Disconnect, (disconnectInfo) => {
32
+ console.log("IM Disconnected.", disconnectInfo);
33
+ // Handle disconnection (e.g., show message, attempt reconnect)
34
+ });
35
+
36
+ im.on(WKIMEvent.Message, (message) => {
37
+ console.log("Received Message:", message);
38
+ // Process incoming message (message.payload, message.fromUid, etc.)
39
+ });
40
+
41
+ im.on(WKIMEvent.Error, (error) => {
42
+ console.error("IM Error:", error);
43
+ // Handle errors
44
+ });
45
+
46
+ // 3. Connect to the server
47
+ im.connect()
48
+ .then(() => {
49
+ console.log("Connection process initiated. Waiting for Connect event...");
50
+
51
+ // Example: Send a message after successful connection initiation
52
+ const targetUserId = "friend_user_id";
53
+ const messagePayload = { type: 1, content: "Hello from EasyJSSDK!" }; // Your custom payload
54
+
55
+ return im.send(targetUserId, WKIMChannelType.Person, messagePayload);
56
+ })
57
+ .then((sendAck) => {
58
+ console.log("Message sent successfully, Ack:", sendAck);
59
+ // sendAck contains { messageId, messageSeq }
60
+ })
61
+ .catch((err) => {
62
+ console.error("Connection or initial send failed:", err);
63
+ });
64
+
65
+ // 4. Disconnect (when needed, e.g., user logout)
66
+ // im.disconnect();
67
+
68
+ ```
69
+
70
+ ## Example:
71
+
72
+ ![Example](./docs/example.png)
73
+
74
+ ## Development
75
+
76
+ 1. Clone the repository.
77
+ 2. Run `npm install`.
78
+ 3. Run `npm run build` to compile TypeScript to JavaScript.
79
+
80
+ ## Running the Example
81
+
82
+ This repository includes a simple HTML/JS example to test the SDK.
83
+
84
+ 1. **Build the SDK:** Make sure you have built the library first:
85
+ ```bash
86
+ npm run build
87
+ ```
88
+ 2. **Start a Local Server:** Navigate to the root directory of this project (`EasyJSSDK`) in your terminal. You need to serve the files using a local web server because the example uses ES Modules. A simple way is using `http-server`:
89
+ ```bash
90
+ # If you don't have http-server, install it globally:
91
+ # npm install -g http-server
92
+
93
+ # Run the server from the EasyJSSDK directory:
94
+ http-server .
95
+ ```
96
+ Alternatively, use the VS Code "Live Server" extension or any other local server, ensuring it serves from the project root directory (`EasyJSSDK`).
97
+
98
+ 3. **Open the Example:** Open your web browser and navigate to the example page, typically:
99
+ `http://localhost:8080/example/`
100
+ (Adjust the port number if your server uses a different one).
101
+
102
+ 4. **Test:** Enter your WuKongIM server details (URL, UID, Token) and use the buttons to connect, disconnect, and send messages.
103
+
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Channel Type Enum based on WuKongIM protocol
3
+ */
4
+ export declare enum ChannelType {
5
+ Person = 1,
6
+ Group = 2
7
+ }
8
+ /**
9
+ * SDK Event Names Enum
10
+ */
11
+ export declare enum Event {
12
+ /** Connection successfully established and authenticated */
13
+ Connect = "connect",
14
+ /** Disconnected from server */
15
+ Disconnect = "disconnect",
16
+ /** Received a message */
17
+ Message = "message",
18
+ /** An error occurred (WebSocket error, connection error, etc.) */
19
+ Error = "error",
20
+ /** Received acknowledgment for a sent message */
21
+ SendAck = "sendack"
22
+ }
23
+ interface AuthOptions {
24
+ uid: string;
25
+ token: string;
26
+ deviceId?: string;
27
+ deviceFlag?: number;
28
+ }
29
+ interface SendResult {
30
+ messageId: string;
31
+ messageSeq: number;
32
+ }
33
+ type EventHandler = (...args: any[]) => void;
34
+ export declare class WKIM {
35
+ private ws;
36
+ private url;
37
+ private auth;
38
+ private isConnected;
39
+ private connectionPromise;
40
+ private pingInterval;
41
+ private pingTimeout;
42
+ private PING_INTERVAL_MS;
43
+ private PONG_TIMEOUT_MS;
44
+ private pendingRequests;
45
+ private eventListeners;
46
+ private constructor();
47
+ /**
48
+ * Initializes the WKIM instance.
49
+ * @param url WebSocket server URL (e.g., "ws://localhost:5100")
50
+ * @param auth Authentication options { uid, token, ... }
51
+ * @returns A WKIM instance
52
+ */
53
+ static init(url: string, auth: AuthOptions): WKIM;
54
+ /**
55
+ * Establishes connection and authenticates with the server.
56
+ * Returns a Promise that resolves on successful connection/authentication,
57
+ * or rejects on failure.
58
+ */
59
+ connect(): Promise<void>;
60
+ /**
61
+ * Disconnects from the server.
62
+ */
63
+ disconnect(): void;
64
+ /**
65
+ * Sends a message to a specific channel.
66
+ * @param channelId Target channel ID
67
+ * @param channelType Target channel type (e.g., WKIM.ChannelType.Person)
68
+ * @param payload Message payload (must be a JSON-serializable object)
69
+ * @param options Optional: { clientMsgNo, header, setting, msgKey, expire, topic }
70
+ * @returns Promise resolving with { messageId, messageSeq } on server ack, or rejecting on error.
71
+ */
72
+ send(channelId: string, channelType: ChannelType, payload: object, options?: {
73
+ clientMsgNo?: string;
74
+ header?: any;
75
+ setting?: any;
76
+ msgKey?: string;
77
+ expire?: number;
78
+ topic?: string;
79
+ }): Promise<SendResult>;
80
+ /**
81
+ * Registers an event listener.
82
+ * @param eventName The event to listen for (e.g., WKIM.Event.Message)
83
+ * @param callback The function to call when the event occurs
84
+ */
85
+ on(eventName: Event, callback: EventHandler): void;
86
+ /**
87
+ * Removes an event listener.
88
+ * @param eventName The event to stop listening for
89
+ * @param callback The specific callback function to remove
90
+ */
91
+ off(eventName: Event, callback: EventHandler): void;
92
+ private emit;
93
+ private sendConnectRequest;
94
+ private sendRequest;
95
+ private sendNotification;
96
+ private handleMessage;
97
+ private handleResponse;
98
+ private handleNotification;
99
+ private sendRecvAck;
100
+ private startPing;
101
+ private stopPing;
102
+ private handlePong;
103
+ private handleDisconnect;
104
+ private cleanupConnection;
105
+ }
106
+ export { ChannelType as WKIMChannelType, Event as WKIMEvent };
package/dist/index.js ADDED
@@ -0,0 +1,444 @@
1
+ // import { v4 as uuidv4 } from 'uuid'; // Remove this line
2
+ // --- Environment Detection and WebSocket Initialization ---
3
+ let WebSocketImpl; // Use 'any' initially to avoid complex type conflicts
4
+ if (typeof WebSocket !== 'undefined') {
5
+ // Browser environment
6
+ WebSocketImpl = WebSocket;
7
+ }
8
+ else {
9
+ // Node.js environment (or environment without native WebSocket)
10
+ // Dynamically import 'ws' only if needed
11
+ try {
12
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
13
+ const Ws = require('ws'); // Type the require
14
+ WebSocketImpl = Ws.WebSocket || Ws; // Handle potential default export differences
15
+ }
16
+ catch (e) {
17
+ throw new Error('WebSocket is not available in this environment. Install \'ws\' package for Node.js.');
18
+ }
19
+ }
20
+ // --- Enums and Types ---
21
+ /**
22
+ * Channel Type Enum based on WuKongIM protocol
23
+ */
24
+ export var ChannelType;
25
+ (function (ChannelType) {
26
+ ChannelType[ChannelType["Person"] = 1] = "Person";
27
+ ChannelType[ChannelType["Group"] = 2] = "Group";
28
+ // Add other channel types if needed
29
+ })(ChannelType || (ChannelType = {}));
30
+ /**
31
+ * SDK Event Names Enum
32
+ */
33
+ export var Event;
34
+ (function (Event) {
35
+ /** Connection successfully established and authenticated */
36
+ Event["Connect"] = "connect";
37
+ /** Disconnected from server */
38
+ Event["Disconnect"] = "disconnect";
39
+ /** Received a message */
40
+ Event["Message"] = "message";
41
+ /** An error occurred (WebSocket error, connection error, etc.) */
42
+ Event["Error"] = "error";
43
+ /** Received acknowledgment for a sent message */
44
+ Event["SendAck"] = "sendack";
45
+ // Add other events like 'reconnecting', 'status_change' if desired
46
+ })(Event || (Event = {}));
47
+ // --- WKIM Class ---
48
+ export class WKIM {
49
+ constructor(url, auth) {
50
+ this.ws = null;
51
+ this.isConnected = false;
52
+ this.connectionPromise = null;
53
+ this.pingInterval = null;
54
+ this.pingTimeout = null;
55
+ this.PING_INTERVAL_MS = 25 * 1000; // Send ping every 25 seconds
56
+ this.PONG_TIMEOUT_MS = 10 * 1000; // Expect pong within 10 seconds
57
+ this.pendingRequests = new Map();
58
+ this.eventListeners = new Map();
59
+ this.url = url;
60
+ this.auth = auth;
61
+ // Ensure Event enum values are used for internal map keys
62
+ Object.values(Event).forEach(event => this.eventListeners.set(event, []));
63
+ }
64
+ /**
65
+ * Initializes the WKIM instance.
66
+ * @param url WebSocket server URL (e.g., "ws://localhost:5100")
67
+ * @param auth Authentication options { uid, token, ... }
68
+ * @returns A WKIM instance
69
+ */
70
+ static init(url, auth) {
71
+ if (!url || !auth || !auth.uid || !auth.token) {
72
+ throw new Error("URL, uid, and token are required for initialization.");
73
+ }
74
+ return new WKIM(url, auth);
75
+ }
76
+ /**
77
+ * Establishes connection and authenticates with the server.
78
+ * Returns a Promise that resolves on successful connection/authentication,
79
+ * or rejects on failure.
80
+ */
81
+ connect() {
82
+ return new Promise((resolve, reject) => {
83
+ var _a;
84
+ if (this.isConnected || ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.CONNECTING) {
85
+ console.warn("Connection already established or in progress.");
86
+ // If already connected, resolve immediately. If connecting, wait for existing promise.
87
+ if (this.isConnected) {
88
+ resolve();
89
+ }
90
+ else if (this.connectionPromise) {
91
+ this.connectionPromise.resolve = resolve; // Chain the promises
92
+ this.connectionPromise.reject = reject;
93
+ }
94
+ else {
95
+ reject(new Error("Already connecting, but no connection promise found."));
96
+ }
97
+ return;
98
+ }
99
+ this.connectionPromise = { resolve, reject };
100
+ try {
101
+ console.log(`Connecting to ${this.url}...`);
102
+ this.ws = new WebSocketImpl(this.url);
103
+ this.ws.onopen = () => {
104
+ console.log("WebSocket connection opened. Authenticating...");
105
+ this.sendConnectRequest();
106
+ };
107
+ this.ws.onmessage = (event) => {
108
+ this.handleMessage(event.data);
109
+ };
110
+ this.ws.onerror = (event) => {
111
+ const errorMessage = event.message || (event.error ? event.error.message : 'WebSocket error');
112
+ console.error("WebSocket error:", errorMessage, event);
113
+ this.emit(Event.Error, event.error || new Error(errorMessage));
114
+ this.handleDisconnect(false, `WebSocket error: ${errorMessage}`); // Don't try graceful close
115
+ if (this.connectionPromise) {
116
+ this.connectionPromise.reject(event.error || new Error(errorMessage));
117
+ this.connectionPromise = null;
118
+ }
119
+ this.cleanupConnection();
120
+ };
121
+ this.ws.onclose = (event) => {
122
+ console.log(`WebSocket connection closed. Code: ${event.code}, Reason: ${event.reason}`);
123
+ this.handleDisconnect(false, `Closed with code ${event.code}: ${event.reason}`); // Don't try graceful close
124
+ this.emit(Event.Disconnect, { code: event.code, reason: event.reason });
125
+ if (this.connectionPromise && !this.isConnected) { // Reject connect promise if closed before connect ack
126
+ this.connectionPromise.reject(new Error(`Connection closed before authentication (Code: ${event.code})`));
127
+ this.connectionPromise = null;
128
+ }
129
+ this.cleanupConnection();
130
+ };
131
+ }
132
+ catch (error) {
133
+ console.error("Failed to create WebSocket:", error);
134
+ this.emit(Event.Error, error);
135
+ if (this.connectionPromise) {
136
+ this.connectionPromise.reject(error);
137
+ this.connectionPromise = null;
138
+ }
139
+ this.cleanupConnection();
140
+ }
141
+ });
142
+ }
143
+ /**
144
+ * Disconnects from the server.
145
+ */
146
+ disconnect() {
147
+ this.handleDisconnect(true, "Manual disconnection");
148
+ }
149
+ /**
150
+ * Sends a message to a specific channel.
151
+ * @param channelId Target channel ID
152
+ * @param channelType Target channel type (e.g., WKIM.ChannelType.Person)
153
+ * @param payload Message payload (must be a JSON-serializable object)
154
+ * @param options Optional: { clientMsgNo, header, setting, msgKey, expire, topic }
155
+ * @returns Promise resolving with { messageId, messageSeq } on server ack, or rejecting on error.
156
+ */
157
+ send(channelId, channelType, payload, options = {}) {
158
+ if (!this.isConnected || !this.ws || this.ws.readyState !== WebSocket.OPEN) {
159
+ return Promise.reject(new Error("Not connected. Call connect() first."));
160
+ }
161
+ if (typeof payload !== 'object' || payload === null) {
162
+ return Promise.reject(new Error("Payload must be a non-null object."));
163
+ }
164
+ const clientMsgNo = options.clientMsgNo || crypto.randomUUID();
165
+ const params = Object.assign({ clientMsgNo: clientMsgNo, channelId: channelId, channelType: channelType, payload: payload }, options // Include other optional params
166
+ );
167
+ return this.sendRequest('send', params);
168
+ }
169
+ /**
170
+ * Registers an event listener.
171
+ * @param eventName The event to listen for (e.g., WKIM.Event.Message)
172
+ * @param callback The function to call when the event occurs
173
+ */
174
+ on(eventName, callback) {
175
+ var _a;
176
+ if (this.eventListeners.has(eventName)) {
177
+ (_a = this.eventListeners.get(eventName)) === null || _a === void 0 ? void 0 : _a.push(callback);
178
+ }
179
+ else {
180
+ console.warn(`Attempted to register listener for unknown event: ${eventName}`);
181
+ }
182
+ }
183
+ /**
184
+ * Removes an event listener.
185
+ * @param eventName The event to stop listening for
186
+ * @param callback The specific callback function to remove
187
+ */
188
+ off(eventName, callback) {
189
+ if (this.eventListeners.has(eventName)) {
190
+ const listeners = this.eventListeners.get(eventName);
191
+ if (listeners) {
192
+ const index = listeners.indexOf(callback);
193
+ if (index > -1) {
194
+ listeners.splice(index, 1);
195
+ }
196
+ }
197
+ }
198
+ }
199
+ // --- Private Methods ---
200
+ emit(eventName, ...args) {
201
+ const listeners = this.eventListeners.get(eventName);
202
+ if (listeners) {
203
+ listeners.forEach(callback => {
204
+ try {
205
+ callback(...args);
206
+ }
207
+ catch (error) {
208
+ console.error(`Error in event listener for ${eventName}:`, error);
209
+ }
210
+ });
211
+ }
212
+ }
213
+ sendConnectRequest() {
214
+ const params = {
215
+ uid: this.auth.uid,
216
+ token: this.auth.token,
217
+ deviceId: this.auth.deviceId,
218
+ deviceFlag: this.auth.deviceFlag || 2, // Default to WEB
219
+ clientTimestamp: Date.now()
220
+ // Add version, clientKey if needed
221
+ };
222
+ this.sendRequest('connect', params, 5000) // 5s timeout for connect
223
+ .then(result => {
224
+ console.log("Authentication successful:", result);
225
+ this.isConnected = true;
226
+ this.startPing();
227
+ this.emit(Event.Connect, result);
228
+ if (this.connectionPromise) {
229
+ this.connectionPromise.resolve();
230
+ this.connectionPromise = null;
231
+ }
232
+ })
233
+ .catch(error => {
234
+ console.error("Authentication failed:", error);
235
+ this.emit(Event.Error, new Error(`Authentication failed: ${error.message || JSON.stringify(error)}`));
236
+ if (this.connectionPromise) {
237
+ this.connectionPromise.reject(error);
238
+ this.connectionPromise = null;
239
+ }
240
+ this.handleDisconnect(false, "Authentication failed"); // Close connection on auth failure
241
+ this.cleanupConnection(); // Ensure ws is closed
242
+ });
243
+ }
244
+ sendRequest(method, params, timeoutMs = 15000) {
245
+ return new Promise((resolve, reject) => {
246
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
247
+ return reject(new Error("WebSocket is not open."));
248
+ }
249
+ const requestId = crypto.randomUUID();
250
+ const request = {
251
+ method: method,
252
+ params: params,
253
+ id: requestId
254
+ };
255
+ const timeoutTimer = setTimeout(() => {
256
+ this.pendingRequests.delete(requestId);
257
+ reject(new Error(`Request timeout for method ${method} (id: ${requestId})`));
258
+ }, timeoutMs);
259
+ this.pendingRequests.set(requestId, { resolve, reject, timeoutTimer });
260
+ try {
261
+ console.debug(`--> Sending request (id: ${requestId}):`, JSON.stringify(request));
262
+ this.ws.send(JSON.stringify(request));
263
+ }
264
+ catch (error) {
265
+ clearTimeout(timeoutTimer);
266
+ this.pendingRequests.delete(requestId);
267
+ console.error(`Error sending request (id: ${requestId}):`, error);
268
+ reject(error);
269
+ }
270
+ });
271
+ }
272
+ sendNotification(method, params) {
273
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
274
+ console.error("Cannot send notification, WebSocket is not open.");
275
+ return;
276
+ }
277
+ const notification = {
278
+ method: method,
279
+ params: params
280
+ };
281
+ console.debug(`--> Sending notification:`, JSON.stringify(notification));
282
+ try {
283
+ this.ws.send(JSON.stringify(notification));
284
+ }
285
+ catch (error) {
286
+ console.error(`Error sending notification (${method}):`, error);
287
+ this.emit(Event.Error, new Error(`Failed to send notification ${method}: ${error}`));
288
+ }
289
+ }
290
+ handleMessage(data) {
291
+ console.debug("<-- Received raw:", data);
292
+ let message;
293
+ try {
294
+ message = JSON.parse(data.toString());
295
+ }
296
+ catch (error) {
297
+ console.error("Failed to parse incoming message:", error, data);
298
+ this.emit(Event.Error, new Error(`Failed to parse message: ${error}`));
299
+ return;
300
+ }
301
+ if ('id' in message) { // It's a Response
302
+ this.handleResponse(message);
303
+ }
304
+ else if ('method' in message) { // It's a Notification
305
+ this.handleNotification(message);
306
+ }
307
+ else {
308
+ console.warn("Received unknown message format:", message);
309
+ }
310
+ }
311
+ handleResponse(response) {
312
+ console.debug(`<-- Handling response (id: ${response.id}):`, response);
313
+ const pending = this.pendingRequests.get(response.id);
314
+ if (pending) {
315
+ clearTimeout(pending.timeoutTimer);
316
+ this.pendingRequests.delete(response.id);
317
+ if (response.error) {
318
+ pending.reject(response.error);
319
+ }
320
+ else {
321
+ pending.resolve(response.result);
322
+ }
323
+ }
324
+ else {
325
+ console.warn(`Received response for unknown request ID: ${response.id}`);
326
+ }
327
+ }
328
+ handleNotification(notification) {
329
+ var _a, _b;
330
+ console.debug(`<-- Handling notification (${notification.method}):`, notification.params);
331
+ switch (notification.method) {
332
+ case 'recv':
333
+ const messageData = notification.params;
334
+ this.emit(Event.Message, messageData);
335
+ // Automatically acknowledge receipt
336
+ this.sendRecvAck(messageData.messageId, messageData.messageSeq);
337
+ break;
338
+ case 'pong':
339
+ this.handlePong();
340
+ break;
341
+ case 'disconnect':
342
+ console.warn('Server initiated disconnect:', notification.params);
343
+ this.emit(Event.Disconnect, notification.params); // Emit server reason
344
+ this.handleDisconnect(false, `Server disconnected: ${((_a = notification.params) === null || _a === void 0 ? void 0 : _a.reason) || ((_b = notification.params) === null || _b === void 0 ? void 0 : _b.reasonCode)}`); // Close locally
345
+ break;
346
+ // Handle other notifications if needed
347
+ default:
348
+ console.warn(`Received unhandled notification method: ${notification.method}`);
349
+ }
350
+ }
351
+ sendRecvAck(messageId, messageSeq) {
352
+ // Per protocol, recvack is a request, but usually doesn't need a response processed
353
+ // Sending as a notification might be simpler if the server allows it,
354
+ // but sticking to the doc: send as request, ignore response.
355
+ const params = { messageId, messageSeq };
356
+ this.sendRequest('recvack', params).catch(err => {
357
+ console.warn(`Failed to send recvack for msg ${messageId} (seq ${messageSeq}):`, err);
358
+ // Decide if retry is needed?
359
+ });
360
+ // Alternative: Send as notification if server supports it (non-standard)
361
+ // this.sendNotification('recvack', params);
362
+ }
363
+ startPing() {
364
+ this.stopPing(); // Clear existing timers
365
+ this.pingInterval = setInterval(() => {
366
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
367
+ this.sendRequest('ping', {}, this.PONG_TIMEOUT_MS)
368
+ .then(this.handlePong.bind(this)) // Technically pong is a notification, but use req/res for timeout
369
+ .catch(err => {
370
+ console.error("Ping failed or timed out:", err);
371
+ this.emit(Event.Error, new Error("Ping timeout"));
372
+ this.handleDisconnect(false, "Ping timeout"); // Disconnect if ping fails
373
+ });
374
+ }
375
+ else {
376
+ this.stopPing(); // Stop if WS is not open
377
+ }
378
+ }, this.PING_INTERVAL_MS);
379
+ console.log(`Ping interval started (${this.PING_INTERVAL_MS}ms).`);
380
+ }
381
+ stopPing() {
382
+ if (this.pingInterval) {
383
+ clearInterval(this.pingInterval);
384
+ this.pingInterval = null;
385
+ console.log("Ping interval stopped.");
386
+ }
387
+ if (this.pingTimeout) {
388
+ clearTimeout(this.pingTimeout);
389
+ this.pingTimeout = null;
390
+ }
391
+ }
392
+ handlePong() {
393
+ // console.debug("Pong received.");
394
+ // Reset pong timeout if using one (mainly handled by sendRequest timeout now)
395
+ }
396
+ handleDisconnect(graceful, reason) {
397
+ console.log(`Handling disconnect. Graceful: ${graceful}, Reason: ${reason}`);
398
+ if (this.ws) {
399
+ this.stopPing();
400
+ if (graceful && this.ws.readyState === WebSocket.OPEN) {
401
+ // Optionally send disconnect message if protocol supported it
402
+ // this.sendNotification('disconnect', { reasonCode: 0, reason: 'Client initiated disconnect' });
403
+ this.ws.close(1000, "Client disconnected"); // Normal closure
404
+ }
405
+ else if (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN) {
406
+ // Force close if not graceful or already closing
407
+ this.ws.close(1001, reason); // Going away
408
+ }
409
+ }
410
+ this.cleanupConnection(); // Clean up state regardless of how close happened
411
+ }
412
+ cleanupConnection() {
413
+ console.log("Cleaning up connection resources.");
414
+ this.isConnected = false;
415
+ this.stopPing();
416
+ // Reject any pending requests
417
+ this.pendingRequests.forEach((pending, id) => {
418
+ clearTimeout(pending.timeoutTimer);
419
+ pending.reject(new Error("Connection closed"));
420
+ });
421
+ this.pendingRequests.clear();
422
+ // Clear connection promise if it exists and hasn't resolved/rejected
423
+ if (this.connectionPromise) {
424
+ // Check if already connected to avoid rejecting after successful connect but before promise reset
425
+ if (!this.isConnected) {
426
+ this.connectionPromise.reject(new Error("Connection closed during operation"));
427
+ }
428
+ this.connectionPromise = null;
429
+ }
430
+ // Don't nullify ws immediately if onclose handler needs it, but ensure no further ops
431
+ if (this.ws) {
432
+ // Remove listeners to prevent potential memory leaks and duplicate handling
433
+ this.ws.onopen = null;
434
+ this.ws.onmessage = null;
435
+ this.ws.onerror = null;
436
+ this.ws.onclose = null;
437
+ // Consider setting this.ws = null here or after a short delay if needed
438
+ }
439
+ // Do NOT clear eventListeners here, user might want to reconnect.
440
+ }
441
+ }
442
+ // Export ChannelType and Event enums alongside the class for easier use
443
+ export { ChannelType as WKIMChannelType, Event as WKIMEvent };
444
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"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,8BAA8B;QAC9B,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE;YACzC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAE5B,qEAAqE;QACrE,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,kGAAkG;YAClG,IAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACpB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAClC,CAAC;QAEF,sFAAsF;QACtF,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACV,4EAA4E;YAC3E,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,EAAE,CAAC,OAAO,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,EAAE,CAAC,OAAO,GAAG,IAAI,CAAC;YACvB,wEAAwE;QAC7E,CAAC;QACD,kEAAkE;IACtE,CAAC;CAEJ;AAED,wEAAwE;AACxE,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "easyjssdk",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "@types/node": "^20.14.10",
17
+ "@types/uuid": "^10.0.0",
18
+ "@types/ws": "^8.18.1",
19
+ "typescript": "^5.5.3"
20
+ },
21
+ "files": [
22
+ "dist/**/*"
23
+ ],
24
+ "dependencies": {
25
+ "uuid": "^11.1.0",
26
+ "ws": "^8.18.2"
27
+ }
28
+ }