ws-json-client

0.2.0 • Public • Published

WS JSON client

Simple WS with some helpers

Installation

npm install ws-json-client

Usage

import { makeSocket, createSocketEventFactory } from "ws-json-client"

const socket = makeSocket("ws://localhost:8080")
const createSocketEvent = createSocketEventFactory(socket)

// Will trigger on data with { action: "users.received", payload: ... }
// with data.payload
const usersReceived = createSocketEvent("users.received")
usersReceived.watch(console.log)

// Will send JSON.stringify({ action: "action", payload: { foo: "bar" } })
socket.sendAction("action", { foo: "bar" })

Readme

Keywords

none

Package Sidebar

Install

npm i ws-json-client

Weekly Downloads

1

Version

0.2.0

License

none

Unpacked Size

7.5 kB

Total Files

5

Last publish

Collaborators

  • kelin2025