Feathersjs框架的微信小程序websocket客户端。
npm install @holytiny/wxmp-socket.io-client --save
在client.js中
import feathers from '@feathersjs/feathers';
import auth from '@feathersjs/authentication-client';
import feathersSocketioClient from '@feathersjs/socketio-client';
import io from '@holytiny/wxmp-socket.io-client';
import Debug from 'debug';
if ('production'.localeCompare(process.env.NODE_ENV) !== 0) {
Debug.enable('*');
}
const debug = Debug('@feathersjs/socketio-client');
export default function FeathersClient () {
debug('create socketio client');
const socketioInit = io('http://localhost:3030', {
transports: ['websocket'],
forceNew: true,
timeout: false
});
const feathersClient = feathers();
//feathersClient.configure(feathersSocketioClient(socketioInit, { timeout: 1000 * 20 }));
feathersClient.configure(feathersSocketioClient(socketioInit));
feathersClient.configure(auth());
return feathersClient;
}
在xxx.js中
import FeathersClient from './client';
const feathersClient = FeathersClient();
具体使用请参考Feathersjs的@feathersjs/socketio-client文档
@holytiny/wxmp-socket.io-client是本项目的一个包,提供了Socket.IO-client在微信小程序环境下的兼容版本。 这个包可以单独使用,具体请看说明。