lahsivjar / react-stomp

React websocket component for STOMP protocol over SockJs
https://www.npmjs.com/package/react-stomp
MIT License
134 stars 41 forks source link

请问如何断开连接,有没有使用实例或者api文档 #138

Closed 521guyu closed 4 years ago

521guyu commented 4 years ago

请问如何断开连接,有没有使用实例或者api文档

521guyu commented 4 years ago

@ @lahsivjar

521guyu commented 4 years ago

您有没有使用的实例,从建立连接到断开连接所有方法都包括的,<SockJsClient //onDisconnect={this.connect.bind(this)} //连接丢失后的回调 url={apiUrl.warn} topics={["/warn"]} onMessage={this.onMessage.bind(this)} onConnect={this.onConnect.bind(this)} onConnectFailure={this.onConnectFailure.bind(this)} debug={true} autoReconnect={true} //断开连接是否自动连接 ref={client => { this.clientRef = client; }} /> 连接和断开连接怎么写呢???

lahsivjar commented 4 years ago

If I understand correctly you want to call disconnect explicitly. If that is the case you can use the disconnect API: https://github.com/lahsivjar/react-stomp/blob/master/API.md#disconnect

For usage see this: https://github.com/lahsivjar/react-stomp/blob/master/test/e2e/connect.test.js#L22-L40

521guyu commented 4 years ago

``connect = () => { this.clientRef.connect(SockJsClient)//调用这个需要传的参数 console.log('建立连接',this.clientRef.connect(SockJsClient),this) }

我现在不知到需要传什么参数,api都是源码感觉,看不太懂

521guyu commented 4 years ago

image 我按照你这个写的,我写了一个按钮断开连接,可以,又写了一个建立连接不行,报iframe.js?1a47:77 Uncaught TypeError: Cannot read property 'contentWindow' of null at eval (iframe.js?1a47:77),现在就是不知道要传什么参数

521guyu commented 4 years ago

和使用方法

521guyu commented 4 years ago

disconnect = (a) => {//断开连接 console.log("断开连接", this.clientRef.disconnect()) } 这个是断开连接的

521guyu commented 4 years ago

希望有一个react中使用的实例和更容易的api文档