Giter VIP home page Giter VIP logo

socket.io-client-wxmp's Introduction

微信小程序 socket.io 客户端

这是一个基于 socket.io 官方版本修改的,可以在微信小程序上使用的 socket.io 客户端,方便利用 socket.io 的更多特性。

使用 engine.io-client-wxmp 作为底层传输协议来支持微信小程序的 WebSocket API.

  • 从当前最新版socket.io-client v3.0.4 fork 修改而来
  • 完整保留 socket.io-client 的 WebSocket 版本的功能
  • 支持二进制格式传输(Binary/ArrayBuffer)、保持长连接(小程序默认约 60s 自动关闭连接)
  • 仅将引用依赖包 engine.io-client 版本替换为 engine.io-client-wxmp,业务代码无任何修改,所以可以跟官方版本保持同步更新

使用方法

下载 dist/socket.io.min.js 到小程序目录:

const io = require('../socket.io.min.js')

const socket = io('ws://192.168.1.100:7001', {
  // path: "",
  transports: ['websocket'], // 此项必须设置
  auth: {

  },
  query: {

  }
})

socket.on('connect', () => {
  console.log('socket.io connected!')
  socket.emit('hello/world', 'hello world!')
})

初始化时必须设置 transports 为 ['websocket'] ,为了保持跟原生 API 一致,小程序 API 里的 method 暂不支持,其他选项参考上面的示例代码.

更多使用方法参考 socket.io 官方文档:https://socket.io/docs/client-api/

API

See API

License

MIT

socket.io-client-wxmp's People

Contributors

3rd-eden avatar alexlmeow avatar crickeys avatar danielbeardsley avatar darrachequesne avatar david-fong avatar defunctzombie avatar digawp avatar dvv avatar einaros avatar fat avatar felixge avatar grant avatar holic avatar jdahlq avatar kevin-roark avatar masakij avatar michael-luo avatar mikelimantara avatar nkzawa avatar paladox avatar paradite avatar pedrorw avatar peterdavehello avatar rase- avatar rauchg avatar sfilatov avatar tootallnate avatar ycarmel avatar zweihan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.