@wxn0brp/gloves-link-server 0.0.10 → 0.0.11

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.js CHANGED
@@ -41,11 +41,12 @@ export class GlovesLinkServer {
41
41
  return;
42
42
  }
43
43
  const data = url.searchParams.has("data") ? JSON.parse(url.searchParams.get("data")) : {};
44
- const authResult = await namespace.authFn({
44
+ const authData = {
45
45
  token, data,
46
46
  url, headers,
47
47
  request, socket, head,
48
- });
48
+ };
49
+ const authResult = await namespace.authFn(authData);
49
50
  if (!authResult || authResult.status !== 200) {
50
51
  this.saveSocketStatus(socketSelfId, pathname, authResult?.status || 401, authResult?.msg || "Unauthorized");
51
52
  socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
@@ -59,7 +60,7 @@ export class GlovesLinkServer {
59
60
  glSocket.user = authResult.user;
60
61
  glSocket.namespace = pathname;
61
62
  namespace.room.join(glSocket);
62
- namespace.onConnectHandler(glSocket);
63
+ namespace.onConnectHandler(glSocket, authData, authResult);
63
64
  ws.on("close", () => {
64
65
  glSocket.handlers?.disconnect?.();
65
66
  namespace.room.leave(glSocket);
@@ -1,4 +1,4 @@
1
- import { AuthFn } from "./types.js";
1
+ import { AuthFn, OnConnect } from "./types.js";
2
2
  import { GLSocket } from "./socket.js";
3
3
  import { Room } from "./room.js";
4
4
  import { GlovesLinkServer } from "./index.js";
@@ -22,7 +22,7 @@ export declare class Namespace {
22
22
  * @param handler - The function to be called when a socket connects to this namespace
23
23
  * @returns The current Namespace instance for chaining
24
24
  */
25
- onConnect(handler: (ws: GLSocket) => void): this;
25
+ onConnect(handler: OnConnect): this;
26
26
  /**
27
27
  * Sets the authentication function for this namespace
28
28
  * @param authFn - The authentication function to be used for this namespace
@@ -33,7 +33,7 @@ export declare class Namespace {
33
33
  * Gets the connection event handler for this namespace
34
34
  * @returns The connection event handler function
35
35
  */
36
- get onConnectHandler(): (ws: GLSocket) => void;
36
+ get onConnectHandler(): OnConnect;
37
37
  /**
38
38
  * Emits an event to all sockets in the namespace's room
39
39
  * @param event - The event name to emit
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import http from "http";
2
2
  import Stream from "stream";
3
+ import { GLSocket } from "./socket.js";
3
4
  export interface Server_Opts {
4
5
  logs: boolean;
5
6
  }
@@ -28,3 +29,4 @@ export interface AuthFnResult {
28
29
  toSet?: Record<string, any>;
29
30
  }
30
31
  export type AuthFn = (data: Server_Auth_Opts) => Promise<AuthFnResult>;
32
+ export type OnConnect = (socket: GLSocket, auth: Server_Auth_Opts, result: AuthFnResult) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/gloves-link-server",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",