@skalfa/skalfa-socket 1.0.0 → 1.0.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.
Files changed (54) hide show
  1. package/.github/workflows/publish.yml +40 -0
  2. package/CONTRIBUTING.md +45 -0
  3. package/LICENSE +21 -0
  4. package/README.md +55 -0
  5. package/dist/disconnect.d.ts +2 -0
  6. package/dist/disconnect.js +7 -0
  7. package/dist/disconnect.js.map +1 -0
  8. package/dist/emit.d.ts +1 -0
  9. package/dist/emit.js +5 -0
  10. package/dist/emit.js.map +1 -0
  11. package/dist/event-registry.d.ts +12 -0
  12. package/dist/event-registry.js +46 -0
  13. package/dist/event-registry.js.map +1 -0
  14. package/dist/index.d.ts +20 -23
  15. package/dist/index.js +23 -133
  16. package/dist/index.js.map +1 -1
  17. package/dist/join.d.ts +2 -0
  18. package/dist/join.js +4 -0
  19. package/dist/join.js.map +1 -0
  20. package/dist/leave.d.ts +2 -0
  21. package/dist/leave.js +4 -0
  22. package/dist/leave.js.map +1 -0
  23. package/dist/of.d.ts +1 -0
  24. package/dist/of.js +7 -0
  25. package/dist/of.js.map +1 -0
  26. package/dist/room.d.ts +3 -0
  27. package/dist/room.js +9 -0
  28. package/dist/room.js.map +1 -0
  29. package/dist/send.d.ts +2 -0
  30. package/dist/send.js +4 -0
  31. package/dist/send.js.map +1 -0
  32. package/dist/shutdown.d.ts +1 -0
  33. package/dist/shutdown.js +10 -0
  34. package/dist/shutdown.js.map +1 -0
  35. package/dist/start.d.ts +2 -0
  36. package/dist/start.js +51 -0
  37. package/dist/start.js.map +1 -0
  38. package/dist/state.d.ts +3 -0
  39. package/dist/state.js +5 -0
  40. package/dist/state.js.map +1 -0
  41. package/package.json +3 -3
  42. package/src/disconnect.ts +8 -0
  43. package/src/emit.ts +5 -0
  44. package/src/event-registry.ts +55 -0
  45. package/src/index.ts +25 -155
  46. package/src/join.ts +5 -0
  47. package/src/leave.ts +5 -0
  48. package/src/of.ts +6 -0
  49. package/src/room.ts +9 -0
  50. package/src/send.ts +5 -0
  51. package/src/shutdown.ts +9 -0
  52. package/src/start.ts +57 -0
  53. package/src/state.ts +7 -0
  54. package/bun.lock +0 -119
@@ -0,0 +1,40 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Setup Node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: 20
20
+ registry-url: https://registry.npmjs.org/
21
+
22
+ - name: Setup Bun
23
+ uses: oven-sh/setup-bun@v1
24
+ with:
25
+ bun-version: latest
26
+
27
+ - name: Publish if version bumped
28
+ run: |
29
+ LOCAL_VER=$(node -p "require('./package.json').version")
30
+ NPM_VER=$(npm view @skalfa/skalfa-socket version 2>/dev/null || echo "0.0.0")
31
+ if [ "$LOCAL_VER" != "$NPM_VER" ]; then
32
+ echo "Publishing @skalfa/skalfa-socket $LOCAL_VER (Registry version: $NPM_VER)"
33
+ bun install
34
+ npm run build
35
+ npm publish --access public
36
+ else
37
+ echo "@skalfa/skalfa-socket is up to date ($LOCAL_VER)"
38
+ fi
39
+ env:
40
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,45 @@
1
+ # Contributing to @skalfa/skalfa-socket
2
+
3
+ Thank you for your interest in contributing to Skalfa! We welcome contributions from the community to help make Skalfa the premier development framework.
4
+
5
+ ## How to Contribute
6
+
7
+ To contribute to this package, please follow these standard open-source steps:
8
+
9
+ ### 1. Fork the Repository
10
+ Fork the official Skalfa repository on GitHub to your personal account.
11
+
12
+ ### 2. Clone Your Fork
13
+ Clone your personal fork to your local machine:
14
+ ```bash
15
+ git clone https://github.com/your-username/skalfa.git
16
+ cd skalfa
17
+ ```
18
+
19
+ ### 3. Create a Feature Branch
20
+ Create a new branch for your feature or bugfix:
21
+ ```bash
22
+ git checkout -b feature/amazing-new-feature
23
+ ```
24
+ *(Use `bugfix/issue-description` for bugfixes).*
25
+
26
+ ### 4. Implement and Commit Your Changes
27
+ Make your changes in the codebase. Write clean, formatted code and ensure all tests and typechecks pass. Commit your changes using semantic commit messages:
28
+ ```bash
29
+ git commit -m "feat: add amazing new feature"
30
+ ```
31
+ *(Use `fix: description` for bugfixes, and `docs: description` for documentation updates).*
32
+
33
+ ### 5. Push to GitHub
34
+ Push your branch to your personal fork on GitHub:
35
+ ```bash
36
+ git push origin feature/amazing-new-feature
37
+ ```
38
+
39
+ ### 6. Submit a Pull Request (PR)
40
+ Go to the official Skalfa repository on GitHub. You will see a prompt to submit a pull request. Click "New Pull Request", describe your changes in detail, link any related issues, and submit it for review by the maintainers.
41
+
42
+ ## Guidelines
43
+ * **Code Style**: Ensure your code conforms to the project's ESLint rules and formatting guidelines.
44
+ * **Type Safety**: Write strict, type-safe TypeScript. Do not bypass the compiler.
45
+ * **Testing**: Run local tests and verify that the build compiles with 0 errors before submitting a PR.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Skalfa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ <p align="center">
2
+ <img src="https://skalfa.sejedigital.com/images/logo-skalfa.png" alt="Skalfa Logo" width="300" />
3
+ </p>
4
+
5
+ # @skalfa/skalfa-socket
6
+
7
+ > Socket.io real-time server gateway and event handler extension for Skalfa backend services.
8
+
9
+ ---
10
+
11
+ ## About this Package
12
+
13
+ This package is part of the **Skalfa Framework**, a premium development ecosystem designed to build high-performance, modular web applications and APIs.
14
+
15
+ ### Usage Scope & Standalone Status
16
+ > 🔒 **Skalfa Ecosystem Integration:** This package is designed to run **integrated within the Skalfa ecosystem** (such as Skalfa API or Skalfa App). It relies on the global service registry and core framework abstractions to operate.
17
+
18
+ ---
19
+
20
+ ## Documentation
21
+
22
+ See the usage documentation at [Documentation](https://skalfa.sejedigital.com).
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ You can install this package using your preferred package manager:
29
+
30
+ ```bash
31
+ # Using npm
32
+ npm install @skalfa/skalfa-socket
33
+
34
+ # Using bun
35
+ bun add @skalfa/skalfa-socket
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Pre-installed Dependencies
41
+
42
+ The following key dependencies are packaged and managed within this project:
43
+
44
+ | Dependency | Scope | Version |
45
+ | :--- | :--- | :--- |
46
+ | `socket.io` | runtime | `^4.7.5` |
47
+ | `@skalfa/skalfa-api-core` | runtime | `file:../skalfa-api-core` |
48
+ | `@types/node` | development | `^26.0.0` |
49
+ | `typescript` | development | `^6.0.3` |
50
+
51
+ ---
52
+
53
+ ## License
54
+
55
+ This package is licensed under the **MIT License**. For full license text, see the [LICENSE](LICENSE) file.
@@ -0,0 +1,2 @@
1
+ import { Socket } from "socket.io";
2
+ export declare function disconnect(client: Socket, reason?: string): void;
@@ -0,0 +1,7 @@
1
+ export function disconnect(client, reason) {
2
+ if (reason) {
3
+ client.emit("force-disconnect", { reason });
4
+ }
5
+ client.disconnect(true);
6
+ }
7
+ //# sourceMappingURL=disconnect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disconnect.js","sourceRoot":"","sources":["../src/disconnect.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,MAAe;IACxD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
package/dist/emit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function emit(event: string, payload?: any): void;
package/dist/emit.js ADDED
@@ -0,0 +1,5 @@
1
+ import { io } from "./state";
2
+ export function emit(event, payload) {
3
+ io?.emit(event, payload);
4
+ }
5
+ //# sourceMappingURL=emit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.js","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAAM,UAAU,IAAI,CAAC,KAAa,EAAE,OAAa;IAC/C,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Socket } from "socket.io";
2
+ type Handler = (client: Socket, data: any) => void;
3
+ export declare class EventRegistry {
4
+ private events;
5
+ private authEvents;
6
+ on(event: string, handler: Handler): void;
7
+ auth(): {
8
+ on: (event: string, handler: Handler) => void;
9
+ };
10
+ bind(client: Socket): void;
11
+ }
12
+ export {};
@@ -0,0 +1,46 @@
1
+ import { auth } from "@skalfa/skalfa-api-core";
2
+ export class EventRegistry {
3
+ constructor() {
4
+ this.events = new Map();
5
+ this.authEvents = new Map();
6
+ }
7
+ on(event, handler) {
8
+ if (!this.events.has(event)) {
9
+ this.events.set(event, []);
10
+ }
11
+ this.events.get(event).push(handler);
12
+ }
13
+ auth() {
14
+ return {
15
+ on: (event, handler) => {
16
+ if (!this.authEvents.has(event)) {
17
+ this.authEvents.set(event, []);
18
+ }
19
+ this.authEvents.get(event).push(handler);
20
+ },
21
+ };
22
+ }
23
+ bind(client) {
24
+ this.events.forEach((handlers, eventName) => {
25
+ client.on(eventName, (data) => {
26
+ handlers.forEach((handler) => handler(client, data));
27
+ });
28
+ });
29
+ this.authEvents.forEach((handlers, eventName) => {
30
+ client.on(eventName, async (data) => {
31
+ const token = data?.accessToken;
32
+ const session = await auth.verifyAccessToken(token);
33
+ if (!session) {
34
+ client.emit("error", {
35
+ event: eventName,
36
+ message: "UNAUTHORIZED_USER",
37
+ });
38
+ return;
39
+ }
40
+ client.data.user = { id: session.user.id, token: session.token };
41
+ handlers.forEach((handler) => handler(client, data));
42
+ });
43
+ });
44
+ }
45
+ }
46
+ //# sourceMappingURL=event-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-registry.js","sourceRoot":"","sources":["../src/event-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAI/C,MAAM,OAAO,aAAa;IAA1B;QACU,WAAM,GAAG,IAAI,GAAG,EAAqB,CAAC;QACtC,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;IA+CpD,CAAC;IA7CC,EAAE,CAAC,KAAa,EAAE,OAAgB;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC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,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC;gBAE/D,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,23 @@
1
- import { Server, Socket } from "socket.io";
2
- type Handler = (client: Socket, data: any) => void;
3
- export declare class EventRegistry {
4
- private events;
5
- private authEvents;
6
- on(event: string, handler: Handler): void;
7
- auth(): {
8
- on: (event: string, handler: Handler) => void;
9
- };
10
- bind(client: Socket): void;
11
- }
1
+ import { EventRegistry } from "./event-registry";
2
+ import { start } from "./start";
3
+ import { emit } from "./emit";
4
+ import { send } from "./send";
5
+ import { join } from "./join";
6
+ import { leave } from "./leave";
7
+ import { room } from "./room";
8
+ import { of } from "./of";
9
+ import { disconnect } from "./disconnect";
10
+ import { shutdown } from "./shutdown";
11
+ export { EventRegistry };
12
12
  export declare const socket: {
13
- start(port: number): Server<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
13
+ start: typeof start;
14
14
  event: EventRegistry;
15
- emit(event: string, payload?: any): void;
16
- send(client: Socket, event: string, payload?: any): void;
17
- join(client: Socket, room: string): void;
18
- leave(client: Socket, room: string): void;
19
- room(room: string): {
20
- emit(event: string, payload?: any): void;
21
- };
22
- of(namespace: string): import("socket.io").Namespace<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any> | null;
23
- disconnect(client: Socket, reason?: string): void;
24
- shutdown(): void;
15
+ emit: typeof emit;
16
+ send: typeof send;
17
+ join: typeof join;
18
+ leave: typeof leave;
19
+ room: typeof room;
20
+ of: typeof of;
21
+ disconnect: typeof disconnect;
22
+ shutdown: typeof shutdown;
25
23
  };
26
- export {};
package/dist/index.js CHANGED
@@ -1,102 +1,20 @@
1
- import os from 'os';
2
- import { Server } from "socket.io";
3
- import { auth, logger } from "@skalfa/skalfa-api-core";
4
- let io = null;
5
- // ===============================
6
- // ## socket: event register handler
7
- // ===============================
8
- export class EventRegistry {
9
- constructor() {
10
- this.events = new Map();
11
- this.authEvents = new Map();
12
- }
13
- on(event, handler) {
14
- if (!this.events.has(event)) {
15
- this.events.set(event, []);
16
- }
17
- this.events.get(event).push(handler);
18
- }
19
- auth() {
20
- return {
21
- on: (event, handler) => {
22
- if (!this.authEvents.has(event)) {
23
- this.authEvents.set(event, []);
24
- }
25
- this.authEvents.get(event).push(handler);
26
- },
27
- };
28
- }
29
- bind(client) {
30
- this.events.forEach((handlers, eventName) => {
31
- client.on(eventName, (data) => {
32
- handlers.forEach((handler) => handler(client, data));
33
- });
34
- });
35
- this.authEvents.forEach((handlers, eventName) => {
36
- client.on(eventName, async (data) => {
37
- const token = data?.accessToken;
38
- const session = await auth.verifyAccessToken(token);
39
- if (!session) {
40
- client.emit("error", {
41
- event: eventName,
42
- message: "UNAUTHORIZED_USER",
43
- });
44
- return;
45
- }
46
- client.data.user = { id: session.user.id, token: session.token };
47
- handlers.forEach((handler) => handler(client, data));
48
- });
49
- });
50
- }
51
- }
1
+ import { registry } from "@skalfa/skalfa-api-core";
2
+ import { EventRegistry } from "./event-registry";
3
+ import { start } from "./start";
4
+ import { emit } from "./emit";
5
+ import { send } from "./send";
6
+ import { join } from "./join";
7
+ import { leave } from "./leave";
8
+ import { room } from "./room";
9
+ import { of } from "./of";
10
+ import { disconnect } from "./disconnect";
11
+ import { shutdown } from "./shutdown";
12
+ export { EventRegistry };
52
13
  export const socket = {
53
14
  // ===============================
54
15
  // ## socket: start server
55
16
  // ===============================
56
- start(port) {
57
- if (io)
58
- return io;
59
- io = new Server(port, {
60
- cors: {
61
- origin: process.env.SOCKET_CORS_ORIGINS || "*",
62
- credentials: true,
63
- },
64
- transports: ["websocket"],
65
- });
66
- io.use(async (client, next) => {
67
- try {
68
- const accessKey = client.handshake.auth?.accessKey || client.handshake.headers["x-api-key"];
69
- if (process.env.SOCKET_KEY) {
70
- if (accessKey !== process.env.SOCKET_APP_KEY) {
71
- return next(new Error("INVALID_SOCKET_KEY"));
72
- }
73
- ;
74
- }
75
- next();
76
- }
77
- catch {
78
- next(new Error("AUTH_ERROR"));
79
- }
80
- });
81
- io.on("connection", (client) => {
82
- logger.socket(`client connected: ${client.id}`);
83
- socket.event.bind(client);
84
- client.on("disconnect", (reason) => {
85
- logger.socket(`client disconnected: ${client.id, reason}`);
86
- });
87
- });
88
- function getLocalIP() {
89
- const interfaces = os.networkInterfaces();
90
- for (const name of Object.keys(interfaces)) {
91
- for (const net of interfaces[name] || []) {
92
- if (net.family === 'IPv4' && !net.internal)
93
- return net.address;
94
- }
95
- }
96
- }
97
- setTimeout(() => logger.start(`WS Server running on \n [LOCAL] http://localhost:${port} \n [NETWORK] http://${getLocalIP()}:${port}!`), 300);
98
- return io;
99
- },
17
+ start,
100
18
  // ===============================
101
19
  // ## socket: event register
102
20
  // ===============================
@@ -104,63 +22,35 @@ export const socket = {
104
22
  // ===============================
105
23
  // ## socket: emit
106
24
  // ===============================
107
- emit(event, payload) {
108
- io?.emit(event, payload);
109
- },
25
+ emit,
110
26
  // ===============================
111
27
  // ## socket: emit specific client
112
28
  // ===============================
113
- send(client, event, payload) {
114
- client.emit(event, payload);
115
- },
29
+ send,
116
30
  // ===============================
117
31
  // ## socket: join room
118
32
  // ===============================
119
- join(client, room) {
120
- client.join(room);
121
- },
33
+ join,
122
34
  // ===============================
123
35
  // ## socket: leave
124
36
  // ===============================
125
- leave(client, room) {
126
- client.leave(room);
127
- },
37
+ leave,
128
38
  // ===============================
129
- // ## socket: disconnect
39
+ // ## socket: room
130
40
  // ===============================
131
- room(room) {
132
- return {
133
- emit(event, payload) {
134
- io?.to(room).emit(event, payload);
135
- },
136
- };
137
- },
41
+ room,
138
42
  // ===============================
139
43
  // ## socket: namespace
140
44
  // ===============================
141
- of(namespace) {
142
- if (!io)
143
- return null;
144
- return io.of(namespace);
145
- },
45
+ of,
146
46
  // ===============================
147
47
  // ## socket: disconnect
148
48
  // ===============================
149
- disconnect(client, reason) {
150
- if (reason) {
151
- client.emit("force-disconnect", { reason });
152
- }
153
- client.disconnect(true);
154
- },
49
+ disconnect,
155
50
  // ===============================
156
51
  // ## socket: shutdown server
157
52
  // ===============================
158
- shutdown() {
159
- if (!io)
160
- return;
161
- io.close();
162
- io = null;
163
- logger.socket("WS shutdown complete");
164
- },
53
+ shutdown,
165
54
  };
55
+ registry.register("socket", socket);
166
56
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,MAAM,EAAU,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEvD,IAAI,EAAE,GAAkB,IAAI,CAAC;AAI7B,kCAAkC;AAClC,oCAAoC;AACpC,kCAAkC;AAClC,MAAM,OAAO,aAAa;IAA1B;QACU,WAAM,GAAG,IAAI,GAAG,EAAqB,CAAC;QACtC,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;IAgDpD,CAAC;IA9CC,EAAE,CAAC,KAAa,EAAE,OAAgB;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,IAAI;QACF,OAAO;YACL,EAAE,EAAE,CAAC,KAAa,EAAE,OAAgB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AClC,6BAA6B;IAC7B,kCAAkC;IAClC,QAAQ;CACT,CAAC;AAEF,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC"}
package/dist/join.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Socket } from "socket.io";
2
+ export declare function join(client: Socket, room: string): void;
package/dist/join.js ADDED
@@ -0,0 +1,4 @@
1
+ export function join(client, room) {
2
+ client.join(room);
3
+ }
4
+ //# sourceMappingURL=join.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.js","sourceRoot":"","sources":["../src/join.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,MAAc,EAAE,IAAY;IAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Socket } from "socket.io";
2
+ export declare function leave(client: Socket, room: string): void;
package/dist/leave.js ADDED
@@ -0,0 +1,4 @@
1
+ export function leave(client, room) {
2
+ client.leave(room);
3
+ }
4
+ //# sourceMappingURL=leave.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leave.js","sourceRoot":"","sources":["../src/leave.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,MAAc,EAAE,IAAY;IAChD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
package/dist/of.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function of(namespace: string): import("socket.io").Namespace<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any> | null;
package/dist/of.js ADDED
@@ -0,0 +1,7 @@
1
+ import { io } from "./state";
2
+ export function of(namespace) {
3
+ if (!io)
4
+ return null;
5
+ return io.of(namespace);
6
+ }
7
+ //# sourceMappingURL=of.js.map
package/dist/of.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"of.js","sourceRoot":"","sources":["../src/of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAAM,UAAU,EAAE,CAAC,SAAiB;IAClC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAC1B,CAAC"}
package/dist/room.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function room(roomName: string): {
2
+ emit(event: string, payload?: any): void;
3
+ };
package/dist/room.js ADDED
@@ -0,0 +1,9 @@
1
+ import { io } from "./state";
2
+ export function room(roomName) {
3
+ return {
4
+ emit(event, payload) {
5
+ io?.to(roomName).emit(event, payload);
6
+ },
7
+ };
8
+ }
9
+ //# sourceMappingURL=room.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room.js","sourceRoot":"","sources":["../src/room.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO;QACL,IAAI,CAAC,KAAa,EAAE,OAAa;YAC/B,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/send.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Socket } from "socket.io";
2
+ export declare function send(client: Socket, event: string, payload?: any): void;
package/dist/send.js ADDED
@@ -0,0 +1,4 @@
1
+ export function send(client, event, payload) {
2
+ client.emit(event, payload);
3
+ }
4
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.js","sourceRoot":"","sources":["../src/send.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,MAAc,EAAE,KAAa,EAAE,OAAa;IAC/D,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function shutdown(): void;
@@ -0,0 +1,10 @@
1
+ import { logger } from "@skalfa/skalfa-api-core";
2
+ import { io, setIo } from "./state";
3
+ export function shutdown() {
4
+ if (!io)
5
+ return;
6
+ io.close();
7
+ setIo(null);
8
+ logger.socket("WS shutdown complete");
9
+ }
10
+ //# sourceMappingURL=shutdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../src/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,UAAU,QAAQ;IACtB,IAAI,CAAC,EAAE;QAAE,OAAO;IAChB,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Server } from "socket.io";
2
+ export declare function start(port: number): Server<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;