Skip to content

Commit

Permalink
docs: update wxapp-socket-io project to weapp.socket.io (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
gongzili456 authored and popomore committed Apr 28, 2018
1 parent 1ada8e3 commit 73dac08
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions docs/source/zh-cn/tutorials/socketio.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,21 +391,27 @@ window.onload = function () {

#### 微信小程序

微信小程序提供的 API 为 WebSocket ,而 socket.io 是 Websocket 的上层封装,故我们无法直接用小程序的 API 连接,可以使用类似 [wxapp-socket-io](https://github.com/wxsocketio/wxapp-socket-io) 的库来适配。
微信小程序提供的 API 为 WebSocket ,而 socket.io 是 Websocket 的上层封装,故我们无法直接用小程序的 API 连接,可以使用类似 [weapp.socket.io](https://github.com/wxsocketio/weapp.socket.io) 的库来适配。

示例代码如下:

```js
// 小程序端示例代码
import io from 'vendor/wxapp-socket-io.js';
const io = require('./yout_path/weapp.socket.io.js')

const socket = io('http://localhost:8000')

const socket = io('ws://127.0.0.1:7001');
socket.on('connect', function () {
socket.emit('chat', 'hello world!');
});
socket.on('res', msg => {
console.log('res from server: %s!', msg);
console.log('connected')
});

socket.on('news', d => {
console.log('received news: ', d)
})

socket.emit('news', {
title: 'this is a news'
})
```


Expand Down Expand Up @@ -644,4 +650,4 @@ socket.emit('exchange', {

[socket.io]: https://socket.io
[egg-socket.io]: https://github.com/eggjs/egg-socket.io
[uws]: https://github.com/uWebSockets/uWebSockets
[uws]: https://github.com/uWebSockets/uWebSockets

0 comments on commit 73dac08

Please sign in to comment.