@dalisoft/ws-events-sync
TypeScript icon, indicating that this package has built-in type declarations

1.1.8 • Public • Published

ws-events-sync

Greenkeeper badge

Event sync between server and client in Websocket

Features

  • Node.js wrapper
  • Browser wrapper
  • Fast
  • Performant
  • Easy
  • UMD compatible

Installation

We recommend install via npm because of it's cache and flat node modules tree

npm i @dalisoft/ws-events-sync

then you able to import to Node.js/Browser easily

// Node.js
const WSEventsWrapper = require("@dalisoft/ws-events-sync").Server;

// Browser
// window.WSEventsSync.Client OR WSEventsSync.Client

// ES6
import { Client /* Server */ } from "@dalisoft/ws-events-sync";

Usage

// Client
const ws = new Websocket("ws://{WEBSOCKET_URL}");
const wsc = new Client(ws);

wsc.emit("server-event", {
  type: "ping"
});
wsc.on("client-event", data => console.log("client event emitter", data));

// Server
const ws = new WSServer();

ws.on("connection", client => {
  const wss = new Server(client);

  wss.emit("client-event", {
    type: "pong"
  });
  wss.on("server-event", data => console.log("server event emitter", data));
});

Browser snippet

Add this script into your before script and after body to be this library working out-of-the-box.

Thanks to jsDelivr!

<script src="https://cdn.jsdelivr.net/combine/npm/@dalisoft/args,npm/@dalisoft/events,npm/@dalisoft/ws-events-sync"></script>

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.8
    0
    • latest

Version History

Package Sidebar

Install

npm i @dalisoft/ws-events-sync

Weekly Downloads

0

Version

1.1.8

License

MIT

Unpacked Size

17.1 kB

Total Files

9

Last publish

Collaborators

  • dalisoft