JSPM

mwebsocket

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q19075F
  • License ISC

easy to use websocket for react and use heartbeat mechanism

Package Exports

  • mwebsocket

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mwebsocket) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

...