npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socket.io.lite

v2.1.25

Published

lightweight socket.io for websoket by ws, 支持微信小程序

Downloads

8

Readme

socket.io.lite

NPM Downloads CNPM Downloads NPM Version License Dependency Status devDependency Status Code Style

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 using io() to create connections.

Installation

$ yarn add socket.io.lite

# or npm
$ npm install socket.io.lite

Usage

server

const http = require('http')
const express = require('express')
const socketLite = require('../lib/server') // require('socket.io.lite')
const app = express()
...
const server = http.createServer(app)
const io = socketLite(server)
// events: open, close, error, ...
io.$on("open", client => {
  console.log('open')
  client.$on('testA', data => {
    console.log(data)
  })
  client.$emit('testB', { foo: 'bar' })
})
server.listen(3002)

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 = new SocketLite('ws://127.0.0.1:3002')
socket.$on('open', function () {
  console.log('open')
})
socket.$emit('testA', { bar: 'foo' })
socket.$on('testB', function (data) {
  console.log()
})

weapp (微信小程序)

const SocketLite = require('socket.io.lite/lib/weapp.js')
var socket = new SocketLite('ws://127.0.0.1:3002')
socket.$on('open', function () {
  console.log('open')
})
socket.$emit('testA', { bar: 'foo' })
socket.$on('testB', function (data) {
  console.log()
})

API

client

socket.$on(eventName, callback)
socket.$emit(eventName, data)  

server

io.$on(eventName, data)
io.$emit(eventName, callback) // braodcast
socket.$on(eventName, data)
socket.$emit(eventName, callback)

about the $on !!!
Because JSON.stringify and JSON.parse are used in the current code, data is required to be an object and not to pass in a JSON format string.

Todos

  • [ ] 支持直接传递基本数据类型
  • [ ] 支持传递二进制数据

License

MIT © 小花猫