Websocket ping message for notifications and vault

This commit is contained in:
nicolas.dorier 2021-10-05 14:14:22 +09:00
parent 6674d76d6d
commit 5c8e62bd90
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 5 additions and 1 deletions

View File

@ -207,6 +207,8 @@
try {
socket = new WebSocket(ws_uri);
socket.onmessage = function (e) {
if (e.data === "ping")
return;
$.get(newDataEndpoint, function (data) {
$("#notifications-nav-item").replaceWith($(data));
});

View File

@ -37,7 +37,7 @@ namespace BTCPayServer
var newSize = _Buffer.Array.Length;
while (true)
{
var message = await Socket.ReceiveAsync(buffer, cancellation);
var message = await Socket.ReceiveAndPingAsync(buffer, cancellation);
if (message.MessageType == WebSocketMessageType.Close)
{
await CloseSocketAndThrow(WebSocketCloseStatus.NormalClosure, "Close message received from the peer", cancellation);

View File

@ -20,6 +20,8 @@ var vault = (function () {
};
this.socket.onmessage = function (event) {
if (typeof event.data === "string") {
if (event.data === "ping")
return;
var jsonObject = JSON.parse(event.data);
if (jsonObject.hasOwnProperty("params")) {
var request = new XMLHttpRequest();