npm.io
0.2.0 • Published 7 years ago

ws-json-client

Licence
—
Version
0.2.0
Deps
1
Size
7 kB
Vulns
0
Weekly
0

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" })