@wxn0brp/gloves-link-server 0.0.11 → 0.0.13

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/index.d.ts CHANGED
@@ -10,7 +10,6 @@ import { Server_Opts } from "./types.js";
10
10
  */
11
11
  export declare class GlovesLinkServer {
12
12
  wss: WebSocketServer;
13
- logs: boolean;
14
13
  opts: Server_Opts;
15
14
  initStatusTemp: Record<string, {
16
15
  status: number;
package/dist/index.js CHANGED
@@ -8,7 +8,6 @@ import { GLSocket } from "./socket.js";
8
8
  */
9
9
  export class GlovesLinkServer {
10
10
  wss;
11
- logs = false;
12
11
  opts;
13
12
  initStatusTemp = {};
14
13
  rooms = new Map();
@@ -55,7 +54,9 @@ export class GlovesLinkServer {
55
54
  }
56
55
  this.wss.handleUpgrade(request, socket, head, (ws) => {
57
56
  const glSocket = new GLSocket(ws, this);
58
- glSocket.logs = this.logs;
57
+ glSocket.logs = this.opts.logs;
58
+ glSocket.authData = authData;
59
+ glSocket.authResult = authResult;
59
60
  if (typeof authResult.user === "object" && authResult.user !== null)
60
61
  glSocket.user = authResult.user;
61
62
  glSocket.namespace = pathname;
@@ -70,8 +71,8 @@ export class GlovesLinkServer {
70
71
  catch (err) {
71
72
  if (process.env.NODE_ENV === "development")
72
73
  console.error("[GlovesLinkServer]", err);
73
- if (this.logs)
74
- console.warn("[auth] Error during authentication:", err);
74
+ if (this.opts.logs)
75
+ console.warn("[ws auth] Error during authentication:", err);
75
76
  this.saveSocketStatus(socketSelfId, "/", 500);
76
77
  socket.write("HTTP/1.1 500 Internal Server Error\r\n\r\n");
77
78
  socket.destroy();
package/dist/socket.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { WebSocket } from "ws";
2
2
  import { GlovesLinkServer } from "./index.js";
3
3
  import { Room, Rooms } from "./room.js";
4
+ import { AuthFnResult, Server_Auth_Opts } from "./types.js";
4
5
  /**
5
6
  * GLSocket class represents a WebSocket connection with additional functionality
6
7
  * @template T - The type of user data associated with the socket
@@ -20,6 +21,8 @@ export declare class GLSocket<T = {
20
21
  [key: string]: Function;
21
22
  };
22
23
  rooms: Set<string>;
24
+ authData: Server_Auth_Opts;
25
+ authResult: AuthFnResult;
23
26
  /**
24
27
  * Creates a new GLSocket instance
25
28
  * @param ws - The underlying WebSocket connection
@@ -90,4 +93,5 @@ export declare class GLSocket<T = {
90
93
  * @returns A map of all rooms on the server
91
94
  */
92
95
  serverRooms(): Rooms;
96
+ disconnect(): void;
93
97
  }
package/dist/socket.js CHANGED
@@ -14,6 +14,8 @@ export class GLSocket {
14
14
  logs = false;
15
15
  handlers;
16
16
  rooms = new Set();
17
+ authData;
18
+ authResult;
17
19
  /**
18
20
  * Creates a new GLSocket instance
19
21
  * @param ws - The underlying WebSocket connection
@@ -44,6 +46,8 @@ export class GLSocket {
44
46
  }
45
47
  if ("ack" in msg) {
46
48
  const ackId = msg.ack;
49
+ if (this.logs)
50
+ console.log("[ws] Received ack:", ackId);
47
51
  const ackCallback = this.ackCallbacks.get(ackId);
48
52
  if (ackCallback) {
49
53
  this.ackCallbacks.delete(ackId);
@@ -54,6 +58,8 @@ export class GLSocket {
54
58
  const { evt, data, ackI } = msg;
55
59
  if (!evt || (data && !Array.isArray(data)))
56
60
  return;
61
+ if (this.logs)
62
+ console.log("[ws] Received event:", evt, data);
57
63
  if (Array.isArray(ackI)) {
58
64
  for (let i = 0; i < ackI.length; i++) {
59
65
  const ackIndex = ackI[i];
@@ -166,4 +172,7 @@ export class GLSocket {
166
172
  serverRooms() {
167
173
  return this.server.rooms;
168
174
  }
175
+ disconnect() {
176
+ this.ws.close();
177
+ }
169
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/gloves-link-server",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",