mwebsocket

1.0.0 • Public • Published

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

...

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i mwebsocket

      Weekly Downloads

      0

      Version

      1.0.0

      License

      ISC

      Unpacked Size

      4.92 kB

      Total Files

      3

      Last publish

      Collaborators

      • ghost60