Add "ping" message to the websocket interface #238
This commit is contained in:
parent
8b9fe50677
commit
4ba0769433
@ -579,6 +579,7 @@ The websocket interface provides the following requests:
|
|||||||
- getTransactionSpecific
|
- getTransactionSpecific
|
||||||
- estimateFee
|
- estimateFee
|
||||||
- sendTransaction
|
- sendTransaction
|
||||||
|
- ping
|
||||||
|
|
||||||
The client can subscribe to the following events:
|
The client can subscribe to the following events:
|
||||||
|
|
||||||
|
|||||||
@ -949,6 +949,13 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||||||
},
|
},
|
||||||
want: `{"id":"15","data":{"subscribed":false}}`,
|
want: `{"id":"15","data":{"subscribed":false}}`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "websocket ping",
|
||||||
|
req: websocketReq{
|
||||||
|
Method: "ping",
|
||||||
|
},
|
||||||
|
want: `{"id":"16","data":{}}`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// send all requests at once
|
// send all requests at once
|
||||||
|
|||||||
@ -298,6 +298,10 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *webs
|
|||||||
"unsubscribeAddresses": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
|
"unsubscribeAddresses": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
|
||||||
return s.unsubscribeAddresses(c)
|
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{}) {
|
func sendResponse(c *websocketChannel, req *websocketReq, data interface{}) {
|
||||||
|
|||||||
@ -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() {
|
function getBlockHash() {
|
||||||
const method = 'getBlockHash';
|
const method = 'getBlockHash';
|
||||||
const height = parseInt(document.getElementById("getBlockHashHeight").value);
|
const height = parseInt(document.getElementById("getBlockHashHeight").value);
|
||||||
@ -296,6 +305,13 @@
|
|||||||
<div class="col-10" id="getInfoResult">
|
<div class="col-10" id="getInfoResult">
|
||||||
</div>
|
</div>
|
||||||
</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="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<input class="btn btn-secondary" type="button" value="getBlockHash" onclick="getBlockHash()">
|
<input class="btn btn-secondary" type="button" value="getBlockHash" onclick="getBlockHash()">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user