@mongchhi/plugin-socket
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @mongchhi/plugin-socket

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

14.3 kB

Total Files

8

Last publish

Collaborators

  • xiaohuoni