1.1.34 • Published 12 months ago
@cimo/websocket v1.1.34
Websocket
Websocket (server/client). Light, fast and secure. Writed with native Typescript code and no dependencies are used.
Pack
- npm run pack
- Copy the file "package_name-x.x.x.tgz" in the project root folder.
- In the "package.json" file insert: "@cimo/package_name": "file:package_name-x.x.x.tgz"
Publish
- npm run build
- npm login --auth-type=legacy
- npm publish --auth-type=legacy --access public
Installation
- Link for npm package -> https://www.npmjs.com/package/@cimo/websocket
Server - Example with "NodeJs Express"
- Server.ts
...
import { CwsServer } from "@cimo/websocket";
// Source
import * as ControllerTest from "../controller/Test";
...
const cwsServer = new CwsServer(server, "secret-key");
ControllerTester.websocket(cwsServer);
...
- ControllerTester.ts
...
import { CwsServer } from "@cimo/websocket";
...
export const websocket = (cwsServer: CwsServer, cp: Cp) => {
cwsServer.receiveData("action_test", (clientId, data) => {
if (typeof data === "string") {
const requestWsData = { test: "end" } as Record<string, string>;
cwsServer.sendData(clientId, 1, JSON.stringify(requestWsData), "action_test");
}
});
};
...
Client
- Index.ts
...
import CwsClient from "@cimo/websocket/dist/client/Service";
...
const cwsClient = new CwsClient("wss://localhost");
cwsClient.checkConnection(() => {
cwsClient.receiveData("action_test", (data) => {
if (typeof data === "string") {
const responseWsData = JSON.parse(data) as Record<string, string>;
console.log(responseWsData);
}
});
});
elementButton.addEventListener("click", (event) => {
const requestWsData = { test: "start" } as Record<string, string>;
cwsClient.sendData(1, JSON.stringify(requestWsData), "action_test");
});
...
1.1.34
12 months ago
1.1.33
12 months ago
1.1.32
12 months ago
1.1.31
1 year ago
1.1.30
1 year ago
1.1.29
1 year ago
1.1.28
1 year ago
1.1.27
1 year ago
1.1.26
1 year ago
1.1.25
1 year ago
1.1.24
2 years ago
1.1.23
2 years ago
1.1.22
2 years ago
1.1.21
2 years ago
1.1.20
2 years ago
1.1.19
2 years ago
1.1.18
2 years ago
1.1.17
2 years ago
1.1.16
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago