0.0.4 • Published 2 years ago
@mongchhi/plugin-socket v0.0.4
mongchhi socket
插件中添加
import { MongChhiIApi } from '@mongchhi/types';
export default (api: IApi) => {
    api.onMongChhiSocket(({ type, send, payload }) => {
        switch (type) {
            case 'call':
              // 给前端发数据
              send({ type: 'MongChhi serve', data: 'first' });
              break;
            default:
            // Do nothing
        }
    });
};前端添加监听
import { socket } from 'umi';
useEffect(() => {
    return socket.listen((type) => {
        console.log(type);
    });
}, []);前端发送消息
import { socket } from 'umi';
socket.send({type:'call'})