Skip to content

Repository files navigation

socket.io-msgpack-javascript

An alternative to the default socket.io-parser, encoding and decoding packets with msgpack official latest javascript version msgpack-javascript

Please note that you MUST use the parser on both sides (server & client).

Compatibility table:

Parser versionSocket.IO server version
1.x.x3.x.x / 4.x.x

Installation

npm i -S skgdev/socket.io-msgpack-javascript

Options

EncodeOptions

NameTypeDefault
maxDepthnumber100
initialBufferSizenumber2048
sortKeysbooleanfalse
forceFloat32booleanfalse
forceIntegerToFloatbooleanfalse
ignoreUndefinedbooleanfalse

See: msgpack EncodeOptions

ExtensionCodec context is not supported for now.

DecodeOptions

NameTypeDefault
maxStrLengthnumber4_294_967_295 (UINT32_MAX)
maxBinLengthnumber4_294_967_295 (UINT32_MAX)
maxArrayLengthnumber4_294_967_295 (UINT32_MAX)
maxMapLengthnumber4_294_967_295 (UINT32_MAX)
maxExtLengthnumber4_294_967_295 (UINT32_MAX)

You can use max${Type}Length to limit the length of each type decoded.

See: msgpack DecodeOptions

ExtensionCodec context is not supported for now.

Usage

Example

constio=require('socket.io');constioc=require('socket.io-client');constcustomParser=require('@skgdev/socket.io-msgpack-javascript');constserver=io(PORT,{parser: customParser.build({encoder: ?EncodeOptions,decoder: ?DecodeOptions})});constsocket=ioc('ws://localhost:'+PORT,{parser: customParser});socket.on('connect',()=>{socket.emit('hello');});

Format

socket.emit('hello', 'you') will create the following packet:

{
"type": 2,
"nsp": "/",
"data": ["hello", "you"]
}

which will be encoded by the parser as:

<Buffer 83 a4 74 79 70 65 02 a3 6e 73 70 a1 2f a4 64 61 74 61 92 a5 68 65 6c 6c 6f a3 79 6f 75>

About

A port of msgpack javascript to work transparently with socket io

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages