diff --git a/docs/api.md b/docs/api.md index 8f34fa1c..393816d1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -579,6 +579,7 @@ The websocket interface provides the following requests: - getTransactionSpecific - estimateFee - sendTransaction +- ping The client can subscribe to the following events: diff --git a/server/public_test.go b/server/public_test.go index 1b838a61..96a54939 100644 --- a/server/public_test.go +++ b/server/public_test.go @@ -949,6 +949,13 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) { }, want: `{"id":"15","data":{"subscribed":false}}`, }, + { + name: "websocket ping", + req: websocketReq{ + Method: "ping", + }, + want: `{"id":"16","data":{}}`, + }, } // send all requests at once diff --git a/server/websocket.go b/server/websocket.go index 3155a05e..1e4ea3e6 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -298,6 +298,10 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *webs "unsubscribeAddresses": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { return s.unsubscribeAddresses(c) }, + "ping": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { + r := struct{}{} + return r, nil + }, } func sendResponse(c *websocketChannel, req *websocketReq, data interface{}) { diff --git a/static/test-websocket.html b/static/test-websocket.html index 06ce15d1..523ae86c 100644 --- a/static/test-websocket.html +++ b/static/test-websocket.html @@ -104,6 +104,15 @@ }); } + function ping() { + const method = 'ping'; + const params = { + }; + send(method, params, function (result) { + document.getElementById('pingResult').innerText = JSON.stringify(result).replace(/,/g, ", "); + }); + } + function getBlockHash() { const method = 'getBlockHash'; const height = parseInt(document.getElementById("getBlockHashHeight").value); @@ -296,6 +305,13 @@