Egg: 关于微信小程序链接websocket问题。

Created on 2 Mar 2018  ·  2Comments  ·  Source: eggjs/egg

微信小程序服务端使用websocket方式。socket.io已作为nodejs体系中被广泛应用的websocket解决方案,却因socket.io对websocket做了高级封装,不能兼容微信小程序所采用的websocket标准协议无法直接使用.
微信小程序并不能链接上 egg-socket.io开启的websocket
egg有没有什么插件可以应对这中情况。

Most helpful comment

微信小程序所采用的 websocket 协议版本为13, 而 egg-socket.io 基于的 socket.io 支持的协议版本为4 socket.io-protocol

可以在小程序端封装一个适配小程序的 socket.io, github 也有现成的库可以参考下 wxapp-socket-io 跟 egg-socket.io/example 中使用基本一致

import io  from 'vendor/wxapp-socket-io.js';

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);
});

All 2 comments

微信小程序所采用的 websocket 协议版本为13, 而 egg-socket.io 基于的 socket.io 支持的协议版本为4 socket.io-protocol

可以在小程序端封装一个适配小程序的 socket.io, github 也有现成的库可以参考下 wxapp-socket-io 跟 egg-socket.io/example 中使用基本一致

import io  from 'vendor/wxapp-socket-io.js';

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);
});

@suinia 可以 PR 到文档

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andylei18 picture andylei18  ·  35Comments

XadillaX picture XadillaX  ·  44Comments

Yao-JSON picture Yao-JSON  ·  34Comments

popomore picture popomore  ·  38Comments

itsky365 picture itsky365  ·  62Comments