Code Monkey home page Code Monkey logo

wxapp-socket-io's Introduction

Community

Slack

weapp-socket-io

微信小程序的 Socket.io client 实现,压缩之后体积为 16K

为了让开发者已最低的成本上手,本类库封装了与 socket.io 一致的 API 供开发者调用。

Demo

使用 socket.io 官网的 chat demo server 实现的 小程序版 聊天室应用 使用 “微信开发者工具” 将 weapp_demo 目录打开,运行调试即可

Features

目前已支持

  • Namespace
  • Singleton
  • Reconnect

Build

npm run build

生产环境可使用 NODE_ENV=production npm run build 进行压缩编译

How to use

npm

npm install wxapp-socket-io

manual

拷贝 dist 目录的 index.js 文件到你的项目目录,并 require

const io = require('yourPath/build/index.js')

为了 使用风格与 socket.io 完全一致

const news = io('ws://localhost:9999/news')
news.on('news', function(data) {
  console.log('======news data: ', data)
  news.emit('old', '1234abc')
})

const chat = io('ws://localhost:9999/chat')
console.log('chat: ', chat)
chat.on('chat', function(data) {
  console.log('======chat data: ', data)
  chat.emit('comment', 'Hi server chat')
})

Collaborator

TODO

  • emit buffer
  • Binary support
  • Room 的支持
  • Smaller size

wxapp-socket-io's People

Contributors

gongzili456 avatar fanweixiao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.