npm.io
0.0.4-alpha.120 • Published 6 years ago

umi-plugin-socket

Licence
Version
0.0.4-alpha.120
Deps
3
Size
15 kB
Vulns
0
Weekly
0

socket-mock

NPM version NPM downloads

模拟ws请求

Install

# or yarn
$ npm install
$ npm run build --watch
$ npm run start

Usage

Configure in .umirc.js,

//umi配置模拟ws服务
export default {
  mockws: { 
    port: 3333, 
    watch: ['./database/index.ts'] 
  }
}
//客户端方法引用
import {ws} from 'umi'
ws.init(`socket地址`,`uid=${me.uid}`)
ws.on('msg',(data)=>{
  console.log(data)
  //the client witch uid==data.toUid will be send,it will show {type:'msg',data:'abc'}
})
ws.send({
  type:'msg',
  toUid:[to.uid],
  data:'abc'
})

Options

TODO

LICENSE

MIT