1.0.0 • Published 5 years ago

mwebsocket v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

MWebSocket

websocket use heartbeat mechanism and easy to use for react

yarn add MWebSocket

import MWebSocket fron 'MWebSocket'

...

state = {
    data: ''
  }
  componentDidMount() {
    this.Socket = new MWebSocket('ws://123.207.167.163:9010/ajaxchattest')
    this.Socket.init()
    this.Socket.on('data', this.upDateState.bind(this))
  }
  componentWillUnmount() {
    if (this.Socket) {
      this.Socket.close()
      this.Socket.off('data', this.upDateState.bind(this))
    }
  }
  upDateState() {
    var handlerArgs = [...arguments]
    this.setState({ data: handlerArgs[0] })
  }

...