1.0.2 • Published 3 years ago

sswebsocket v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

SSWebSocket

On the basis of websocket, add functions as: 1. disconnect auto reconnection

Getting started

$ npm install sswebsocket --save

Usage

import SSWebSocket from 'sswebsocket';

const ws = new SSWebSocket({
	uri: 'ws://your ws host',
	protocols: null,
	options: null,
	needReconnect: false,
	reconnectInterval: 15000,
	maxReconnectAttempts: 10,
	debug: false,
});

// 建立连接
ws.onopen = () => {
	// 发送数据
	ws.sendMessage("send message");
}

// 接收数据
ws.onmessage = (e) => {}

// 错误信息回调
ws.onerror = (e) => {}

// 关闭连接
ws.close = () => {}

// 关闭连接回调
wx.onclose = () => {}

Props

PropTypeRequiredDefaultDescription
uristringYeswebsocket host
protocolsstring or string[] or nullNoSpecify acceptable sub protocols
optionsobject or nullNo
needReconnectbooleanNotrueAutomatic reconnection when disconnected
reconnectIntervalnumberNo30000Reconnection interval(unit:ms)
maxReconnectAttemptsnumberNo5Maximum number of reconnections
debugbooleanNofalseIt will print debugging information