@wxn0brp/gloves-link-server 0.1.0-beta.0 → 0.1.0-beta.2
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/http.d.ts +2 -2
- package/dist/http.js +3 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -2
- package/dist/namespace.d.ts +7 -1
- package/dist/namespace.js +10 -2
- package/dist/socket.d.ts +5 -0
- package/dist/socket.js +8 -1
- package/package.json +4 -4
package/dist/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from "@wxn0brp/falcon-frame";
|
|
2
|
-
import { SocketStatus } from "./types.js";
|
|
3
2
|
import { GlovesLinkServer } from "./index.js";
|
|
3
|
+
import { SocketStatus } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Saves the status of a socket connection for temporary tracking
|
|
6
6
|
*/
|
|
@@ -9,7 +9,7 @@ export declare function saveSocketStatus(wss: GlovesLinkServer, socketStatus: So
|
|
|
9
9
|
* Creates a router for handling status requests
|
|
10
10
|
* @returns A router instance for status endpoints
|
|
11
11
|
*/
|
|
12
|
-
export declare function statusRouter(): Router;
|
|
12
|
+
export declare function statusRouter(wss: GlovesLinkServer): Router;
|
|
13
13
|
/**
|
|
14
14
|
* Creates a router for serving client files
|
|
15
15
|
* @param clientDir - Optional directory path for client files, defaults to node_modules/@wxn0brp/gloves-link-client/dist/
|
package/dist/http.js
CHANGED
|
@@ -19,7 +19,7 @@ export function saveSocketStatus(wss, socketStatus) {
|
|
|
19
19
|
* Creates a router for handling status requests
|
|
20
20
|
* @returns A router instance for status endpoints
|
|
21
21
|
*/
|
|
22
|
-
export function statusRouter() {
|
|
22
|
+
export function statusRouter(wss) {
|
|
23
23
|
const router = new Router();
|
|
24
24
|
router.get("/status", (req, res) => {
|
|
25
25
|
const id = req.query.id;
|
|
@@ -33,13 +33,13 @@ export function statusRouter() {
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
const statusKey = path + "-" + id;
|
|
36
|
-
const status =
|
|
36
|
+
const status = wss.initStatusTemp[statusKey];
|
|
37
37
|
if (status === undefined) {
|
|
38
38
|
res.status(404).json({ err: true, msg: "Socket not found" });
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
res.json({ err: false, status });
|
|
42
|
-
delete
|
|
42
|
+
delete wss.initStatusTemp[statusKey];
|
|
43
43
|
});
|
|
44
44
|
return router;
|
|
45
45
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,12 @@ export declare class GlovesLinkServer {
|
|
|
41
41
|
* @returns The room instance
|
|
42
42
|
*/
|
|
43
43
|
room(name: string): Room;
|
|
44
|
+
/**
|
|
45
|
+
* Gets or creates a room by user ID (from the root namespace)
|
|
46
|
+
* @param userId - The user ID
|
|
47
|
+
* @returns The room instance
|
|
48
|
+
*/
|
|
49
|
+
userRoom(userId: string): Room;
|
|
44
50
|
/**
|
|
45
51
|
* Emits an event to the socket associated with the specified user ID
|
|
46
52
|
* @param userId - The user ID to target
|
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ export class GlovesLinkServer {
|
|
|
51
51
|
url, headers,
|
|
52
52
|
request, socket, head,
|
|
53
53
|
};
|
|
54
|
-
const authResult = await namespace.
|
|
54
|
+
const authResult = await namespace._authFn(authData);
|
|
55
55
|
if (!authResult || authResult.status !== 200) {
|
|
56
56
|
saveSocketStatus(this, {
|
|
57
57
|
socketSelfId,
|
|
@@ -137,6 +137,14 @@ export class GlovesLinkServer {
|
|
|
137
137
|
room(name) {
|
|
138
138
|
return this.of("/").room(name);
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Gets or creates a room by user ID (from the root namespace)
|
|
142
|
+
* @param userId - The user ID
|
|
143
|
+
* @returns The room instance
|
|
144
|
+
*/
|
|
145
|
+
userRoom(userId) {
|
|
146
|
+
return this.of("/").userRoom(userId);
|
|
147
|
+
}
|
|
140
148
|
/**
|
|
141
149
|
* Emits an event to the socket associated with the specified user ID
|
|
142
150
|
* @param userId - The user ID to target
|
|
@@ -154,7 +162,7 @@ export class GlovesLinkServer {
|
|
|
154
162
|
falconFrame(app, clientDir) {
|
|
155
163
|
const router = new Router();
|
|
156
164
|
app.use("/gloves-link", router);
|
|
157
|
-
router.use(statusRouter());
|
|
165
|
+
router.use(statusRouter(this));
|
|
158
166
|
if (clientDir !== false)
|
|
159
167
|
router.use(clientRouter(clientDir));
|
|
160
168
|
}
|
package/dist/namespace.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class Namespace {
|
|
|
9
9
|
name: string;
|
|
10
10
|
private server;
|
|
11
11
|
_onConnectHandler: OnConnect;
|
|
12
|
-
|
|
12
|
+
_authFn: AuthFn;
|
|
13
13
|
_room: Room;
|
|
14
14
|
rooms: Rooms;
|
|
15
15
|
users: Rooms;
|
|
@@ -43,6 +43,12 @@ export declare class Namespace {
|
|
|
43
43
|
* @returns The Room instance
|
|
44
44
|
*/
|
|
45
45
|
room(name: string): Room;
|
|
46
|
+
/**
|
|
47
|
+
* Gets or creates a room by user ID
|
|
48
|
+
* @param id - The user ID to get or create the room for
|
|
49
|
+
* @returns The Room instance
|
|
50
|
+
*/
|
|
51
|
+
userRoom(id: string): Room;
|
|
46
52
|
/**
|
|
47
53
|
* Emits an event to all sockets in the namespace's room except the specified socket
|
|
48
54
|
* @param socket - The socket to exclude from the emission
|
package/dist/namespace.js
CHANGED
|
@@ -6,7 +6,7 @@ export class Namespace {
|
|
|
6
6
|
name;
|
|
7
7
|
server;
|
|
8
8
|
_onConnectHandler = () => { };
|
|
9
|
-
|
|
9
|
+
_authFn = async () => ({ status: 200 });
|
|
10
10
|
_room = new Room();
|
|
11
11
|
rooms = new Map();
|
|
12
12
|
users = new Map();
|
|
@@ -34,7 +34,7 @@ export class Namespace {
|
|
|
34
34
|
* @returns The current Namespace instance for chaining
|
|
35
35
|
*/
|
|
36
36
|
auth(authFn) {
|
|
37
|
-
this.
|
|
37
|
+
this._authFn = authFn;
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -53,6 +53,14 @@ export class Namespace {
|
|
|
53
53
|
room(name) {
|
|
54
54
|
return getRoom(this.rooms, name);
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets or creates a room by user ID
|
|
58
|
+
* @param id - The user ID to get or create the room for
|
|
59
|
+
* @returns The Room instance
|
|
60
|
+
*/
|
|
61
|
+
userRoom(id) {
|
|
62
|
+
return getRoom(this.users, id);
|
|
63
|
+
}
|
|
56
64
|
/**
|
|
57
65
|
* Emits an event to all sockets in the namespace's room except the specified socket
|
|
58
66
|
* @param socket - The socket to exclude from the emission
|
package/dist/socket.d.ts
CHANGED
package/dist/socket.js
CHANGED
|
@@ -70,7 +70,7 @@ export class GLSocket {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
this.handlers
|
|
73
|
+
this.handlers.emit(evt, ...data);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Registers an event handler for the specified event
|
|
@@ -148,4 +148,11 @@ export class GLSocket {
|
|
|
148
148
|
room(name) {
|
|
149
149
|
return this.namespace.room(name);
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Gets a room by user ID
|
|
153
|
+
* @returns The room object or undefined if not found
|
|
154
|
+
*/
|
|
155
|
+
userRoom() {
|
|
156
|
+
return this.namespace.userRoom(this.user?._id);
|
|
157
|
+
}
|
|
151
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/gloves-link-server",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/wxn0brP/GlovesLink",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@wxn0brp/falcon-frame": "^0.
|
|
15
|
+
"@wxn0brp/falcon-frame": "^0.6.0",
|
|
16
16
|
"@types/bun": "*",
|
|
17
17
|
"@types/ws": "^8.18.1",
|
|
18
18
|
"tsc-alias": "*",
|
|
19
19
|
"typescript": "*"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@wxn0brp/falcon-frame": ">=0.
|
|
22
|
+
"@wxn0brp/falcon-frame": ">=0.6.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependenciesMeta": {
|
|
25
25
|
"@wxn0brp/falcon-frame": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"ws": "^8.
|
|
30
|
+
"ws": "^8.19.0"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist"
|