@skalfa/skalfa-socket-client 1.0.3
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/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/connect.d.ts +2 -0
- package/dist/connect.js +34 -0
- package/dist/disconnect.d.ts +1 -0
- package/dist/disconnect.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/state.d.ts +4 -0
- package/dist/state.js +9 -0
- package/dist/use-socket.d.ts +4 -0
- package/dist/use-socket.js +18 -0
- package/package.json +39 -0
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,56 @@
|
|
|
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-client
|
|
6
|
+
|
|
7
|
+
> Real-time Socket.io client wrapper and dynamic hooks extension for Skalfa Next.js applications.
|
|
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-client
|
|
33
|
+
|
|
34
|
+
# Using bun
|
|
35
|
+
bun add @skalfa/skalfa-socket-client
|
|
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-client` | runtime | `^4.7.5` |
|
|
47
|
+
| `@types/node` | development | `^20.0.0` |
|
|
48
|
+
| `@types/react` | development | `^19.0.0` |
|
|
49
|
+
| `@types/react-dom` | development | `^19.0.0` |
|
|
50
|
+
| `typescript` | development | `^6.0.3` |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
This package is licensed under the **MIT License**. For full license text, see the [LICENSE](LICENSE) file.
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connect = connect;
|
|
4
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
5
|
+
const skalfa_app_core_1 = require("@skalfa/skalfa-app-core");
|
|
6
|
+
const state_1 = require("./state");
|
|
7
|
+
function connect() {
|
|
8
|
+
if (state_1.host) {
|
|
9
|
+
if (!state_1.s) {
|
|
10
|
+
const socket = (0, socket_io_client_1.io)(state_1.host, {
|
|
11
|
+
autoConnect: true,
|
|
12
|
+
transports: ["websocket"],
|
|
13
|
+
reconnection: true,
|
|
14
|
+
reconnectionAttempts: 5,
|
|
15
|
+
reconnectionDelay: 2000,
|
|
16
|
+
withCredentials: true,
|
|
17
|
+
});
|
|
18
|
+
(0, state_1.setS)(socket);
|
|
19
|
+
socket.on("connect", () => {
|
|
20
|
+
skalfa_app_core_1.logger.socket("server connected:", socket?.id);
|
|
21
|
+
});
|
|
22
|
+
socket.on("disconnect", (reason) => {
|
|
23
|
+
skalfa_app_core_1.logger.socketError("server disconnected:", reason);
|
|
24
|
+
});
|
|
25
|
+
socket.on("connect_error", (err) => {
|
|
26
|
+
skalfa_app_core_1.logger.socketError("server connection error:", err.message);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (state_1.s.disconnected) {
|
|
30
|
+
state_1.s.connect();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return state_1.s;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function disconnect(): void;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.socket = exports.useSocket = void 0;
|
|
4
|
+
const skalfa_app_core_1 = require("@skalfa/skalfa-app-core");
|
|
5
|
+
const connect_1 = require("./connect");
|
|
6
|
+
const disconnect_1 = require("./disconnect");
|
|
7
|
+
const use_socket_1 = require("./use-socket");
|
|
8
|
+
Object.defineProperty(exports, "useSocket", { enumerable: true, get: function () { return use_socket_1.useSocket; } });
|
|
9
|
+
exports.socket = {
|
|
10
|
+
// ==============================>
|
|
11
|
+
// ## Socket: connect to server
|
|
12
|
+
// ==============================>
|
|
13
|
+
connect: connect_1.connect,
|
|
14
|
+
// ==============================>
|
|
15
|
+
// ## Socket: disconnect from server
|
|
16
|
+
// ==============================>
|
|
17
|
+
disconnect: disconnect_1.disconnect,
|
|
18
|
+
};
|
|
19
|
+
skalfa_app_core_1.registry.register("socket", exports.socket);
|
package/dist/state.d.ts
ADDED
package/dist/state.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.s = exports.host = void 0;
|
|
4
|
+
exports.setS = setS;
|
|
5
|
+
exports.host = globalThis.process?.env?.NEXT_PUBLIC_SOCKET_URL;
|
|
6
|
+
exports.s = null;
|
|
7
|
+
function setS(socket) {
|
|
8
|
+
exports.s = socket;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useSocket = void 0;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
const useSocket = () => {
|
|
8
|
+
const [socketState, setSocketState] = (0, react_1.useState)(null);
|
|
9
|
+
(0, react_1.useEffect)(() => {
|
|
10
|
+
const soc = index_1.socket.connect();
|
|
11
|
+
setSocketState(soc);
|
|
12
|
+
return () => {
|
|
13
|
+
soc?.off();
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
return { socket: socketState };
|
|
17
|
+
};
|
|
18
|
+
exports.useSocket = useSocket;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skalfa/skalfa-socket-client",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Real-time Socket.io client wrapper and dynamic hooks extension for Skalfa Next.js applications.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -p tsconfig.json"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"skalfa",
|
|
15
|
+
"frontend",
|
|
16
|
+
"socket"
|
|
17
|
+
],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "UNLICENSED",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"socket.io-client": "^4.7.5"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@skalfa/skalfa-app-core": "^1.0.0",
|
|
25
|
+
"next": "^15.0.0 || ^16.0.0",
|
|
26
|
+
"react": "^19.0.0",
|
|
27
|
+
"react-dom": "^19.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@skalfa/skalfa-app-core": "^1.0.0",
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"@types/react": "^19.0.0",
|
|
33
|
+
"@types/react-dom": "^19.0.0",
|
|
34
|
+
"next": "16.1.1",
|
|
35
|
+
"react": "^19.2.1",
|
|
36
|
+
"react-dom": "^19.2.1",
|
|
37
|
+
"typescript": "^6.0.3"
|
|
38
|
+
}
|
|
39
|
+
}
|