mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 21:01:21 +00:00
[rpc/lib/server] wrote a basic test for WebsocketManager
This commit is contained in:
@ -613,11 +613,9 @@ func (wsc *wsConnection) readRoutine() {
|
||||
if err != nil {
|
||||
wsc.WriteRPCResponse(types.RPCInternalError(request.ID, err))
|
||||
continue
|
||||
} else {
|
||||
wsc.WriteRPCResponse(types.NewRPCSuccessResponse(wsc.cdc, request.ID, result))
|
||||
continue
|
||||
}
|
||||
|
||||
wsc.WriteRPCResponse(types.NewRPCSuccessResponse(wsc.cdc, request.ID, result))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -684,20 +682,20 @@ func (wsc *wsConnection) writeMessageWithDeadline(msgType int, msg []byte) error
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
// WebsocketManager is the main manager for all websocket connections.
|
||||
// It holds the event switch and a map of functions for routing.
|
||||
// WebsocketManager provides a WS handler for incoming connections and passes a
|
||||
// map of functions along with any additional params to new connections.
|
||||
// NOTE: The websocket path is defined externally, e.g. in node/node.go
|
||||
type WebsocketManager struct {
|
||||
websocket.Upgrader
|
||||
|
||||
funcMap map[string]*RPCFunc
|
||||
cdc *amino.Codec
|
||||
logger log.Logger
|
||||
wsConnOptions []func(*wsConnection)
|
||||
}
|
||||
|
||||
// NewWebsocketManager returns a new WebsocketManager that routes according to
|
||||
// the given funcMap and connects to the server with the given connection
|
||||
// options.
|
||||
// NewWebsocketManager returns a new WebsocketManager that passes a map of
|
||||
// functions, connection options and logger to new WS connections.
|
||||
func NewWebsocketManager(funcMap map[string]*RPCFunc, cdc *amino.Codec, wsConnOptions ...func(*wsConnection)) *WebsocketManager {
|
||||
return &WebsocketManager{
|
||||
funcMap: funcMap,
|
||||
@ -718,7 +716,8 @@ func (wm *WebsocketManager) SetLogger(l log.Logger) {
|
||||
wm.logger = l
|
||||
}
|
||||
|
||||
// WebsocketHandler upgrades the request/response (via http.Hijack) and starts the wsConnection.
|
||||
// WebsocketHandler upgrades the request/response (via http.Hijack) and starts
|
||||
// the wsConnection.
|
||||
func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
wsConn, err := wm.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user