socket.io.lite
a lightweight socket.io library for websocket
支持微信小程序
contain heartbeat auto reconnect
Tip
2.0 upgraded the api, using
new SocketLite ()
to create connections, no longer usingio()
to create connections.
Installation
$ yarn add socket.io.lite # or npm $ npm install socket.io.lite
Usage
server
const http = const express = const socketLite = // require('socket.io.lite')const app = ...const server = httpconst io = // events: open, close, error, ...ioserver
browser
// <script src="node_modules/socket.io.lite/dist/browser.js"></script> // window.SocketLite// or// const SocketLite = require('socket.io.lite/lib/browser.js')// const SocketLite = require('socket.io.lite/dist/browser.js')var socket = 'ws://127.0.0.1:3002'socketsocketsocket
weapp (微信小程序)
const SocketLite = var socket = 'ws://127.0.0.1:3002'socketsocketsocket
API
client
socketsocket
server
ioio // braodcastsocketsocket
about the $on !!!
BecauseJSON.stringify
andJSON.parse
are used in the current code, data is required to be an object and not to pass in a JSON format string.
Todos
- 支持直接传递基本数据类型
- 支持传递二进制数据