Socket
Socket
Sign inDemoInstall

@cimo/websocket

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cimo/websocket

Websocket (server/client). Light, fast and secure.


Version published
Weekly downloads
2
decreased by-93.1%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Websocket

Websocket (server/client). Light, fast and secure. Write with native Typescript code and no dependencies is used.

Pack

  1. npm run pack
  2. Copy the file "cimo-websocket-x.x.x.tgz" in the project root folder.
  3. In the "package.json" file insert: "@cimo/websocket": "file:cimo-websocket-x.x.x.tgz"

Publish

  1. npm run build
  2. npm login --auth-type=legacy
  3. npm publish --auth-type=legacy --access public

Installation

  1. 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");
});

...

Keywords

FAQs

Last updated on 11 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc