@forinda/kickjs-ws 1.6.0 → 1.7.1-alpha.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/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import { randomUUID as k } from "node:crypto";
2
2
  import { WebSocketServer as u } from "ws";
3
3
  import { Service as p, createLogger as R, ref as h } from "@forinda/kickjs-core";
4
4
  import "reflect-metadata";
5
- var i = {
5
+ var c = {
6
6
  WS_CONTROLLER: /* @__PURE__ */ Symbol("kick:ws:controller"),
7
7
  WS_HANDLERS: /* @__PURE__ */ Symbol("kick:ws:handlers")
8
- }, S = /* @__PURE__ */ new Set(), M = class {
8
+ }, g = /* @__PURE__ */ new Set(), M = class {
9
9
  id;
10
10
  data;
11
11
  event;
@@ -87,7 +87,7 @@ var i = {
87
87
  event: t,
88
88
  data: s
89
89
  });
90
- for (const [c, r] of o) c !== a && r.readyState === r.OPEN && r.send(n);
90
+ for (const [i, r] of o) i !== a && r.readyState === r.OPEN && r.send(n);
91
91
  }
92
92
  }, d = R("WsAdapter"), A = class {
93
93
  name = "WsAdapter";
@@ -123,47 +123,47 @@ var i = {
123
123
  rooms: this.roomManager.getAllRooms()
124
124
  };
125
125
  }
126
- beforeStart(e, t) {
127
- this.container = t;
128
- for (const s of S) {
129
- const a = Reflect.getMetadata(i.WS_CONTROLLER, s);
130
- if (a === void 0) continue;
131
- const o = Reflect.getMetadata(i.WS_HANDLERS, s) || [], n = this.basePath + (a === "/" ? "" : a);
132
- this.namespaces.set(n, {
133
- namespace: a,
134
- controllerClass: s,
135
- handlers: o,
126
+ beforeStart({ container: e }) {
127
+ this.container = e;
128
+ for (const t of g) {
129
+ const s = Reflect.getMetadata(c.WS_CONTROLLER, t);
130
+ if (s === void 0) continue;
131
+ const a = Reflect.getMetadata(c.WS_HANDLERS, t) || [], o = this.basePath + (s === "/" ? "" : s);
132
+ this.namespaces.set(o, {
133
+ namespace: s,
134
+ controllerClass: t,
135
+ handlers: a,
136
136
  sockets: /* @__PURE__ */ new Map(),
137
137
  contexts: /* @__PURE__ */ new Map()
138
- }), d.info(`Registered WS namespace: ${n} (${s.name})`);
138
+ }), d.info(`Registered WS namespace: ${o} (${t.name})`);
139
139
  }
140
140
  }
141
- afterStart(e, t) {
141
+ afterStart({ server: e }) {
142
142
  this.wss = new u({
143
143
  noServer: !0,
144
144
  maxPayload: this.maxPayload
145
- }), e.on("upgrade", (a, o, n) => {
146
- const c = (a.url || "/").split("?")[0], r = this.namespaces.get(c);
147
- if (!r) {
148
- o.write(`HTTP/1.1 404 Not Found\r
145
+ }), e.on("upgrade", (s, a, o) => {
146
+ const n = (s.url || "/").split("?")[0], i = this.namespaces.get(n);
147
+ if (!i) {
148
+ a.write(`HTTP/1.1 404 Not Found\r
149
149
  \r
150
- `), o.destroy();
150
+ `), a.destroy();
151
151
  return;
152
152
  }
153
- this.wss.handleUpgrade(a, o, n, (m) => {
154
- this.handleConnection(m, r);
153
+ this.wss.handleUpgrade(s, a, o, (r) => {
154
+ this.handleConnection(r, i);
155
155
  });
156
156
  }), this.heartbeatInterval > 0 && (this.heartbeatTimer = setInterval(() => {
157
- for (const [, a] of this.namespaces) for (const [, o] of a.sockets) {
158
- if (o.__alive === !1) {
159
- o.terminate();
157
+ for (const [, s] of this.namespaces) for (const [, a] of s.sockets) {
158
+ if (a.__alive === !1) {
159
+ a.terminate();
160
160
  continue;
161
161
  }
162
- o.__alive = !1, o.ping();
162
+ a.__alive = !1, a.ping();
163
163
  }
164
164
  }, this.heartbeatInterval));
165
- const s = Array.from(this.namespaces.values()).reduce((a, o) => a + o.handlers.length, 0);
166
- d.info(`WebSocket ready — ${this.namespaces.size} namespace(s), ${s} handler(s)`);
165
+ const t = Array.from(this.namespaces.values()).reduce((s, a) => s + a.handlers.length, 0);
166
+ d.info(`WebSocket ready — ${this.namespaces.size} namespace(s), ${t} handler(s)`);
167
167
  }
168
168
  shutdown() {
169
169
  this.heartbeatTimer && clearInterval(this.heartbeatTimer);
@@ -184,16 +184,16 @@ var i = {
184
184
  }), this.invokeHandlers(o, t.handlers, "connect", a), e.on("message", (n) => {
185
185
  this.messagesReceived.value++;
186
186
  try {
187
- const c = JSON.parse(n.toString()), r = c.event, m = c.data;
187
+ const i = JSON.parse(n.toString()), r = i.event, S = i.data;
188
188
  if (!r || typeof r != "string") {
189
189
  a.send("error", { message: 'Invalid message format: missing "event" field' });
190
190
  return;
191
191
  }
192
- a.event = r, a.data = m;
193
- const v = t.handlers.find((l) => l.type === "message" && l.event === r);
194
- if (v) this.safeInvoke(o, v.handlerName, a);
192
+ a.event = r, a.data = S;
193
+ const f = t.handlers.find((l) => l.type === "message" && l.event === r);
194
+ if (f) this.safeInvoke(o, f.handlerName, a);
195
195
  else {
196
- const l = t.handlers.find((g) => g.type === "message" && g.event === "*");
196
+ const l = t.handlers.find((v) => v.type === "message" && v.event === "*");
197
197
  l && this.safeInvoke(o, l.handlerName, a);
198
198
  }
199
199
  } catch {
@@ -224,37 +224,37 @@ var i = {
224
224
  };
225
225
  function O(e) {
226
226
  return (t) => {
227
- p()(t), Reflect.defineMetadata(i.WS_CONTROLLER, e || "/", t), S.add(t);
227
+ p()(t), Reflect.defineMetadata(c.WS_CONTROLLER, e || "/", t), g.add(t);
228
228
  };
229
229
  }
230
- function f(e, t) {
230
+ function m(e, t) {
231
231
  return () => (s, a) => {
232
- const o = Reflect.getMetadata(i.WS_HANDLERS, s.constructor) || [];
232
+ const o = Reflect.getMetadata(c.WS_HANDLERS, s.constructor) || [];
233
233
  o.push({
234
234
  type: e,
235
235
  event: t,
236
236
  handlerName: a
237
- }), Reflect.defineMetadata(i.WS_HANDLERS, o, s.constructor);
237
+ }), Reflect.defineMetadata(c.WS_HANDLERS, o, s.constructor);
238
238
  };
239
239
  }
240
- var _ = f("connect"), y = f("disconnect"), E = f("error");
240
+ var y = m("connect"), E = m("disconnect"), _ = m("error");
241
241
  function P(e) {
242
242
  return (t, s) => {
243
- const a = Reflect.getMetadata(i.WS_HANDLERS, t.constructor) || [];
243
+ const a = Reflect.getMetadata(c.WS_HANDLERS, t.constructor) || [];
244
244
  a.push({
245
245
  type: "message",
246
246
  event: e,
247
247
  handlerName: s
248
- }), Reflect.defineMetadata(i.WS_HANDLERS, a, t.constructor);
248
+ }), Reflect.defineMetadata(c.WS_HANDLERS, a, t.constructor);
249
249
  };
250
250
  }
251
251
  export {
252
- _ as OnConnect,
253
- y as OnDisconnect,
254
- E as OnError,
252
+ y as OnConnect,
253
+ E as OnDisconnect,
254
+ _ as OnError,
255
255
  P as OnMessage,
256
256
  N as RoomManager,
257
- i as WS_METADATA,
257
+ c as WS_METADATA,
258
258
  A as WsAdapter,
259
259
  M as WsContext,
260
260
  O as WsController
@@ -1,4 +1,4 @@
1
- import { type AppAdapter, type Container, type Ref } from '@forinda/kickjs-core';
1
+ import { type AppAdapter, type AdapterContext, type Ref } from '@forinda/kickjs-core';
2
2
  import { type WsAdapterOptions } from './interfaces';
3
3
  /**
4
4
  * WebSocket adapter for KickJS. Attaches to the HTTP server and routes
@@ -53,8 +53,8 @@ export declare class WsAdapter implements AppAdapter {
53
53
  }>;
54
54
  rooms: Record<string, number>;
55
55
  };
56
- beforeStart(_app: any, container: Container): void;
57
- afterStart(server: any, _container: Container): void;
56
+ beforeStart({ container }: AdapterContext): void;
57
+ afterStart({ server }: AdapterContext): void;
58
58
  shutdown(): void;
59
59
  private handleConnection;
60
60
  private invokeHandlers;
@@ -1 +1 @@
1
- {"version":3,"file":"ws-adapter.d.ts","sourceRoot":"","sources":["../src/ws-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAqB,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAA;AACnG,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAA;AAcrB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,SAAU,YAAW,UAAU;IAC1C,QAAQ,CAAC,IAAI,eAA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ooms, and DI integration for KickJS",
5
5
  "keywords": [
6
6
  "kickjs",
@@ -52,7 +52,7 @@
52
52
  "dependencies": {
53
53
  "reflect-metadata": "^0.2.2",
54
54
  "ws": "^8.20.0",
55
- "@forinda/kickjs-core": "1.6.0"
55
+ "@forinda/kickjs-core": "1.7.1-alpha.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@swc/core": "^1.7.28",