Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 688 Bytes

File metadata and controls

37 lines (29 loc) · 688 Bytes

Work in progress.

Usage

Install with npm install nodejs-websocket-parser

Import package

import * as net from "net"
import { WebsocketParser } from "nodejs-websocket-parser/dist/WebsocketParser"

Initialize parser

const wsp = new WebsocketParser()

On socket connection, add it to the parser

wsp.addConnection(socket)

On socket disconnect, remove it

wsp.removeConnection(socket)

When you recieve data from socket parse it with

wsp.parse(data,socket)

Handle parsed data with

wsp.on("text",(data) => {console.log(data)})  
wsp.on("binary",(data) => {console.log(data)})