0.0.4 • Published 4 months ago

@mongchhi/plugin-socket v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

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