@wooksjs/event-ws 0.7.0 → 0.7.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/index.cjs +19 -19
- package/dist/index.mjs +20 -20
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -432,24 +432,25 @@ var WooksWs = class extends wooks.WooksAdapterBase {
|
|
|
432
432
|
...this.eventContextOptions,
|
|
433
433
|
...parentCtx ? { parent: parentCtx } : {}
|
|
434
434
|
};
|
|
435
|
-
|
|
436
|
-
const connection = new WsConnection(id, ws$1, connectionCtx, this.serializer);
|
|
437
|
-
connectionCtx.seed(wsConnectionKind, {
|
|
435
|
+
(0, __wooksjs_event_core.createEventContext)(ctxOptions, wsConnectionKind, {
|
|
438
436
|
id,
|
|
439
437
|
ws: ws$1
|
|
440
|
-
})
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if (
|
|
445
|
-
result
|
|
446
|
-
|
|
438
|
+
}, () => {
|
|
439
|
+
const connectionCtx = (0, __wooksjs_event_core.current)();
|
|
440
|
+
const connection = new WsConnection(id, ws$1, connectionCtx, this.serializer);
|
|
441
|
+
try {
|
|
442
|
+
if (this.onConnectHandler) {
|
|
443
|
+
const result = this.onConnectHandler();
|
|
444
|
+
if (result !== null && result !== void 0 && typeof result.then === "function") {
|
|
445
|
+
result.then(() => this.acceptConnection(connection)).catch((error) => this.rejectConnection(connection, error));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
447
448
|
}
|
|
449
|
+
this.acceptConnection(connection);
|
|
450
|
+
} catch (error) {
|
|
451
|
+
this.rejectConnection(connection, error);
|
|
448
452
|
}
|
|
449
|
-
|
|
450
|
-
} catch (error) {
|
|
451
|
-
this.rejectConnection(connection, error);
|
|
452
|
-
}
|
|
453
|
+
});
|
|
453
454
|
});
|
|
454
455
|
}
|
|
455
456
|
acceptConnection(connection) {
|
|
@@ -491,18 +492,17 @@ var WooksWs = class extends wooks.WooksAdapterBase {
|
|
|
491
492
|
return;
|
|
492
493
|
}
|
|
493
494
|
const { event, path, data, id: messageId } = msg;
|
|
494
|
-
|
|
495
|
+
(0, __wooksjs_event_core.createEventContext)({
|
|
495
496
|
...this.eventContextOptions,
|
|
496
497
|
parent: connection.ctx
|
|
497
|
-
}
|
|
498
|
-
msgCtx.seed(wsMessageKind, {
|
|
498
|
+
}, wsMessageKind, {
|
|
499
499
|
data,
|
|
500
500
|
rawMessage: raw,
|
|
501
501
|
messageId,
|
|
502
502
|
messagePath: path,
|
|
503
503
|
messageEvent: event
|
|
504
|
-
})
|
|
505
|
-
|
|
504
|
+
}, () => {
|
|
505
|
+
const msgCtx = (0, __wooksjs_event_core.current)();
|
|
506
506
|
const handlers = this.wooks.lookupHandlers(event, path, msgCtx);
|
|
507
507
|
if (!handlers) {
|
|
508
508
|
if (messageId !== void 0) connection.replyError(messageId, 404, "Not found");
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventContext, current, defineEventKind, defineWook, key, routeParamsKey, run, slot, useLogger, useRouteParams, useRouteParams as useRouteParams$1 } from "@wooksjs/event-core";
|
|
1
|
+
import { EventContext, createEventContext, current, defineEventKind, defineWook, key, routeParamsKey, run, slot, useLogger, useRouteParams, useRouteParams as useRouteParams$1 } from "@wooksjs/event-core";
|
|
2
2
|
import http from "http";
|
|
3
3
|
import { WooksAdapterBase } from "wooks";
|
|
4
4
|
import { WebSocketServer } from "ws";
|
|
@@ -409,24 +409,25 @@ var WooksWs = class extends WooksAdapterBase {
|
|
|
409
409
|
...this.eventContextOptions,
|
|
410
410
|
...parentCtx ? { parent: parentCtx } : {}
|
|
411
411
|
};
|
|
412
|
-
|
|
413
|
-
const connection = new WsConnection(id, ws, connectionCtx, this.serializer);
|
|
414
|
-
connectionCtx.seed(wsConnectionKind, {
|
|
412
|
+
createEventContext(ctxOptions, wsConnectionKind, {
|
|
415
413
|
id,
|
|
416
414
|
ws
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
result
|
|
423
|
-
|
|
415
|
+
}, () => {
|
|
416
|
+
const connectionCtx = current();
|
|
417
|
+
const connection = new WsConnection(id, ws, connectionCtx, this.serializer);
|
|
418
|
+
try {
|
|
419
|
+
if (this.onConnectHandler) {
|
|
420
|
+
const result = this.onConnectHandler();
|
|
421
|
+
if (result !== null && result !== void 0 && typeof result.then === "function") {
|
|
422
|
+
result.then(() => this.acceptConnection(connection)).catch((error) => this.rejectConnection(connection, error));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
424
425
|
}
|
|
426
|
+
this.acceptConnection(connection);
|
|
427
|
+
} catch (error) {
|
|
428
|
+
this.rejectConnection(connection, error);
|
|
425
429
|
}
|
|
426
|
-
|
|
427
|
-
} catch (error) {
|
|
428
|
-
this.rejectConnection(connection, error);
|
|
429
|
-
}
|
|
430
|
+
});
|
|
430
431
|
});
|
|
431
432
|
}
|
|
432
433
|
acceptConnection(connection) {
|
|
@@ -468,18 +469,17 @@ var WooksWs = class extends WooksAdapterBase {
|
|
|
468
469
|
return;
|
|
469
470
|
}
|
|
470
471
|
const { event, path, data, id: messageId } = msg;
|
|
471
|
-
|
|
472
|
+
createEventContext({
|
|
472
473
|
...this.eventContextOptions,
|
|
473
474
|
parent: connection.ctx
|
|
474
|
-
}
|
|
475
|
-
msgCtx.seed(wsMessageKind, {
|
|
475
|
+
}, wsMessageKind, {
|
|
476
476
|
data,
|
|
477
477
|
rawMessage: raw,
|
|
478
478
|
messageId,
|
|
479
479
|
messagePath: path,
|
|
480
480
|
messageEvent: event
|
|
481
|
-
})
|
|
482
|
-
|
|
481
|
+
}, () => {
|
|
482
|
+
const msgCtx = current();
|
|
483
483
|
const handlers = this.wooks.lookupHandlers(event, path, msgCtx);
|
|
484
484
|
if (!handlers) {
|
|
485
485
|
if (messageId !== void 0) connection.replyError(messageId, 404, "Not found");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-ws",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "WebSocket adapter for Wooks with path-based message routing, rooms, and broadcasting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"@types/ws": "^8.18.1",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^3.2.4",
|
|
50
|
-
"@wooksjs/event-core": "^0.7.
|
|
51
|
-
"wooks": "^0.7.
|
|
50
|
+
"@wooksjs/event-core": "^0.7.2",
|
|
51
|
+
"wooks": "^0.7.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@prostojs/logger": "^0.4.3",
|
|
55
55
|
"@prostojs/router": "^0.3.2",
|
|
56
56
|
"ws": "^8.0.0",
|
|
57
|
-
"@wooksjs/event-core": "^0.7.
|
|
58
|
-
"wooks": "^0.7.
|
|
57
|
+
"@wooksjs/event-core": "^0.7.2",
|
|
58
|
+
"wooks": "^0.7.2"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "rolldown -c ../../rolldown.config.mjs",
|