Merge branch 'master' into improve_logging
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
# recws
|
# recws
|
||||||
|
|
||||||
|
***This is fork of [recws-org/recws](https://github.com/recws-org/recws) with some fixes***
|
||||||
|
|
||||||
Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https://github.com/gorilla/websocket) that will automatically reconnect if the connection is dropped - thread safe!
|
Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https://github.com/gorilla/websocket) that will automatically reconnect if the connection is dropped - thread safe!
|
||||||
|
|
||||||
[](https://travis-ci.com/recws-org/recws)
|
[](https://travis-ci.com/recws-org/recws)
|
||||||
@@ -12,7 +14,7 @@ Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https:
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/recws-org/recws
|
go get github.com/nikepan/recws
|
||||||
```
|
```
|
||||||
|
|
||||||
## Sponsors
|
## Sponsors
|
||||||
@@ -21,8 +23,8 @@ go get github.com/recws-org/recws
|
|||||||
|
|
||||||
## Logo
|
## Logo
|
||||||
|
|
||||||
- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx)
|
- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx)
|
||||||
- Gopher by [Gophers](https://github.com/egonelbre/gophers)
|
- Gopher by [Gophers](https://github.com/egonelbre/gophers)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -2,9 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/recws-org/recws"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nikepan/recws"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module github.com/recws-org/recws
|
module github.com/nikepan/recws
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
|
|||||||
@@ -97,13 +97,12 @@ func (rc *RecConn) getConn() *websocket.Conn {
|
|||||||
// Close closes the underlying network connection without
|
// Close closes the underlying network connection without
|
||||||
// sending or waiting for a close frame.
|
// sending or waiting for a close frame.
|
||||||
func (rc *RecConn) Close() {
|
func (rc *RecConn) Close() {
|
||||||
if rc.getConn() != nil {
|
rc.mu.Lock()
|
||||||
rc.mu.Lock()
|
if rc.Conn != nil {
|
||||||
rc.Conn.Close()
|
rc.Conn.Close()
|
||||||
rc.mu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
rc.isConnected = false
|
||||||
rc.setIsConnected(false)
|
rc.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown gracefully closes the connection by sending the websocket.CloseMessage.
|
// Shutdown gracefully closes the connection by sending the websocket.CloseMessage.
|
||||||
@@ -434,7 +433,8 @@ func (rc *RecConn) keepAlive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout() {
|
timeoutOffset := time.Millisecond * 500
|
||||||
|
if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout()+timeoutOffset {
|
||||||
rc.log(LogValues{Err: errors.New("keepalive timeout"), Msg: "Reconnect", Url: rc.url})
|
rc.log(LogValues{Err: errors.New("keepalive timeout"), Msg: "Reconnect", Url: rc.url})
|
||||||
rc.CloseAndReconnect()
|
rc.CloseAndReconnect()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user