@dnax/core 0.60.3 → 0.60.4
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/app/hono.ts +3 -1
- package/lib/socket/index.ts +0 -1
- package/lib/socket/instance.ts +17 -3
- package/package.json +1 -1
- package/utils/index.ts +9 -1
package/app/hono.ts
CHANGED
|
@@ -99,7 +99,9 @@ function HonoInstance(): typeof app {
|
|
|
99
99
|
return asyncLocalStorage.run(new Map(), async () => {
|
|
100
100
|
let cookie = getCookie(c);
|
|
101
101
|
let session = sessionStorage();
|
|
102
|
-
var token =
|
|
102
|
+
var token =
|
|
103
|
+
jwt.getToken("Bearer", c.req.header()["authorization"]) || null;
|
|
104
|
+
|
|
103
105
|
var { decode, valid, error } = jwt.verify(token);
|
|
104
106
|
let sessionData = {};
|
|
105
107
|
if (valid && decode && decode?.session) {
|
package/lib/socket/index.ts
CHANGED
package/lib/socket/instance.ts
CHANGED
|
@@ -5,13 +5,16 @@ import { v4 } from "uuid";
|
|
|
5
5
|
const wsClients = new Map<string, ServerWebSocket>();
|
|
6
6
|
const wsEvents: optionsIo[] = [];
|
|
7
7
|
|
|
8
|
+
type _clbFunc = (data: any) => void;
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* reason for disconnection
|
|
10
12
|
*/
|
|
11
13
|
type reasonType = any;
|
|
12
14
|
export type callbackType = (
|
|
13
15
|
socket: socketIoType,
|
|
14
|
-
data: any | reasonType
|
|
16
|
+
data: any | reasonType,
|
|
17
|
+
clb?: _clbFunc
|
|
15
18
|
) => void;
|
|
16
19
|
|
|
17
20
|
class Io {
|
|
@@ -75,7 +78,6 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
75
78
|
let id = v4();
|
|
76
79
|
ws.id = id;
|
|
77
80
|
wsClients.set(id, ws);
|
|
78
|
-
|
|
79
81
|
// set Id to client and emit it
|
|
80
82
|
ws.send(JSON.stringify({ type: "setId", id: id }));
|
|
81
83
|
// run all listenners event for connection
|
|
@@ -127,6 +129,17 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
127
129
|
(e) => e.event == options?.event && e?.type == "on"
|
|
128
130
|
);
|
|
129
131
|
|
|
132
|
+
// callback to
|
|
133
|
+
let clb_ = null;
|
|
134
|
+
if (options?.uuid) {
|
|
135
|
+
clb_ = (data: any) => {
|
|
136
|
+
ws.send(
|
|
137
|
+
JSON.stringify({ type: "emit", event: options?.uuid, data })
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
clb_ = () => {};
|
|
142
|
+
}
|
|
130
143
|
// run all listeners function if matchs
|
|
131
144
|
evs?.map((ev) => {
|
|
132
145
|
ws.token = options?.token || null;
|
|
@@ -143,7 +156,8 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
143
156
|
emit: (event: string, data: any) =>
|
|
144
157
|
ws.send(JSON.stringify({ type: "emit", event, data })),
|
|
145
158
|
},
|
|
146
|
-
options
|
|
159
|
+
options?.data,
|
|
160
|
+
clb_
|
|
147
161
|
);
|
|
148
162
|
}
|
|
149
163
|
});
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -28,7 +28,15 @@ function copy(data: object): object | any {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const jwt = {
|
|
31
|
-
verify: (
|
|
31
|
+
verify: (
|
|
32
|
+
token: string | null | undefined
|
|
33
|
+
): { decode: any; valid: boolean; error: any } => {
|
|
34
|
+
if (!token)
|
|
35
|
+
return {
|
|
36
|
+
decode: null,
|
|
37
|
+
valid: false,
|
|
38
|
+
error: "Token required",
|
|
39
|
+
};
|
|
32
40
|
const JWT_SECRET = String(Cfg.server?.jwt?.secret);
|
|
33
41
|
let decode = null;
|
|
34
42
|
let valid = true;
|