-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6757 from The-K-R-O-K/UlyanaAndrukhiv/6639-ws-pin…
…g-pong [Access] Implement keepalive routine with ping-ponging to ws connection in ws controller
- Loading branch information
Showing
8 changed files
with
634 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package websockets | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gorilla/websocket" | ||
) | ||
|
||
type WebsocketConnection interface { | ||
ReadJSON(v interface{}) error | ||
WriteJSON(v interface{}) error | ||
WriteControl(messageType int, deadline time.Time) error | ||
Close() error | ||
SetReadDeadline(deadline time.Time) error | ||
SetWriteDeadline(deadline time.Time) error | ||
SetPongHandler(h func(string) error) | ||
} | ||
|
||
type WebsocketConnectionImpl struct { | ||
conn *websocket.Conn | ||
} | ||
|
||
func NewWebsocketConnection(conn *websocket.Conn) *WebsocketConnectionImpl { | ||
return &WebsocketConnectionImpl{ | ||
conn: conn, | ||
} | ||
} | ||
|
||
var _ WebsocketConnection = (*WebsocketConnectionImpl)(nil) | ||
|
||
func (c *WebsocketConnectionImpl) ReadJSON(v interface{}) error { | ||
return c.conn.ReadJSON(v) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) WriteJSON(v interface{}) error { | ||
return c.conn.WriteJSON(v) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) WriteControl(messageType int, deadline time.Time) error { | ||
return c.conn.WriteControl(messageType, nil, deadline) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) Close() error { | ||
return c.conn.Close() | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) SetReadDeadline(deadline time.Time) error { | ||
return c.conn.SetReadDeadline(deadline) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) SetWriteDeadline(deadline time.Time) error { | ||
return c.conn.SetWriteDeadline(deadline) | ||
} | ||
|
||
func (c *WebsocketConnectionImpl) SetPongHandler(h func(string) error) { | ||
c.conn.SetPongHandler(h) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.