# xornor-websocket

> The [xornor-websocket](https://www.xornor.co/) library exported as [Node.js](https://nodejs.org/) modules.

Latest version **1.0.4** (published 2023-04-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install xornor-websocket
pnpm add xornor-websocket
yarn add xornor-websocket
bun add xornor-websocket
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-04-21 |
| First published | 2023-04-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | avinash.xor |

## Links

- npm: https://www.npmjs.com/package/xornor-websocket
- npm.io page: https://npm.io/package/xornor-websocket

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^8.13.0
- [https](https://npm.io/package/https.md) ^1.0.0

## Recent versions

- 1.0.4 (latest) — 2023-04-21
- 1.0.3 — 2023-04-21
- 1.0.2 — 2023-04-21
- 1.0.1 — 2023-04-21
- 1.0.0 — 2023-04-21

## README

# xornor-websocket v1.0.4

The [xornor-websocket](https://www.xornor.co/) library exported as [Node.js](https://nodejs.org/) modules.

## Installation

Using npm:

```shell
$ npm i xornor-websocket
```

In Node.js:

```js
const WebSocketServer = require('xornor-websocket');
const fs = require("fs");
// data which send on particular channel
let data = { data: "value" };

//channel name
let channel = 2;

// connnection details
let connection = {
  cert: fs.readFileSync("cert.pem"),
  key: fs.readFileSync("key.pem"),
  passphrase: "this is a websocket key",
};

// create instance of a class
const wsserver = new WebSocketServer(connection);

//call onConnection function for create a connection
wsserver.onConnection(data, channel);

// start a websocket server on particular port
wsserver.start(3002, () => {
  console.log("WebSocket server started on port 3002");
});
```

In client side:

```js
const channel = localStorage.getItem("channel");
// get channel from local storage
// if you have any other storage you can get from that storage

// create a websocket instance and pass path of websocket
const socket = new WebSocket("wss://localhost:8443/" + channel);

// send obj with json stringify
socket.send(JSON.stringify(obj));

socket.onopen = () => {
  console.log(`Connected to channel: ${channel}`);
};

socket.onerror = (error) => {
  console.error("WebSocket error:", error);
};

socket.onclose = (event) => {
  console.log(`WebSocket connection closed with code ${event.code}`);
};

socket.onmessage = (event) => {
  console.log(`Received message: ${event.data}`);
};
```

---
_Source: https://npm.io/package/xornor-websocket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
