Wondering what’s next for npm?Check out our public roadmap! »

@dalisoft/ws-events-syncTypeScript 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

Install

npm i @dalisoft/ws-events-sync

DownloadsWeekly Downloads

25

Version

1.1.8

License

MIT

Unpacked Size

17.1 kB

Total Files

9

Last publish

Collaborators

  • avatar