@dnax/core 0.60.6 → 0.61.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/lib/socket/instance.ts +11 -2
- package/package.json +1 -1
package/lib/socket/instance.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ServerWebSocket, WebSocketHandler, Server } from "bun";
|
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { Cfg } from "../../config";
|
|
4
4
|
import { v4 } from "uuid";
|
|
5
|
+
import { uuid } from "../../utils";
|
|
5
6
|
const wsClients = new Map<string, ServerWebSocket>();
|
|
6
7
|
const wsEvents: optionsIo[] = [];
|
|
7
8
|
|
|
@@ -36,7 +37,7 @@ class Io {
|
|
|
36
37
|
}
|
|
37
38
|
emit(event: string, data: any) {
|
|
38
39
|
if (!this?.id || this.id == null) {
|
|
39
|
-
console.error("No id found");
|
|
40
|
+
console.error("ws:: No id found");
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
if (this.id) {
|
|
@@ -133,6 +134,7 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
133
134
|
let clb_ = null;
|
|
134
135
|
if (options?.uuid) {
|
|
135
136
|
clb_ = (data: any) => {
|
|
137
|
+
//console.log("MMM", data);
|
|
136
138
|
ws.send(
|
|
137
139
|
JSON.stringify({ type: "emit", event: options?.uuid, data })
|
|
138
140
|
);
|
|
@@ -150,7 +152,14 @@ function webSocketServer(server: Server): WebSocketHandler {
|
|
|
150
152
|
broadcast: (event: string, data: any) => {
|
|
151
153
|
// send to all clients
|
|
152
154
|
wsClients.forEach((client) => {
|
|
153
|
-
client.send(
|
|
155
|
+
client.send(
|
|
156
|
+
JSON.stringify({
|
|
157
|
+
type: "emit",
|
|
158
|
+
event,
|
|
159
|
+
data,
|
|
160
|
+
uuid: options?.uuid,
|
|
161
|
+
})
|
|
162
|
+
);
|
|
154
163
|
});
|
|
155
164
|
},
|
|
156
165
|
emit: (event: string, data: any) =>
|