Add "ping" message to the websocket interface #238

This commit is contained in:
Martin Boehm 2019-07-19 14:59:03 +02:00
parent 8b9fe50677
commit 4ba0769433
4 changed files with 28 additions and 0 deletions

View File

@ -579,6 +579,7 @@ The websocket interface provides the following requests:
- getTransactionSpecific
- estimateFee
- sendTransaction
- ping
The client can subscribe to the following events:

View File

@ -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

View File

@ -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{}) {

View File

@ -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 @@
<div class="col-10" id="getInfoResult">
</div>
</div>
<div class="row">
<div class="col">
<input class="btn btn-secondary" type="button" value="ping" onclick="ping()">
</div>
<div class="col-10" id="pingResult">
</div>
</div>
<div class="row">
<div class="col">
<input class="btn btn-secondary" type="button" value="getBlockHash" onclick="getBlockHash()">