Skip to content

Commit

Permalink
[OneBot] Fixed Heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 27, 2023
1 parent a4078b8 commit 0a88ad9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Lagrange.OneBot/Core/Network/Service/ForwardWSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ForwardWSService(IConfiguration config, ILogger<LagrangeApp> logger) : ba
RestartAfterListenError = true
};

_timer = new Timer(OnHeartbeat, null, int.MaxValue, ws.GetValue<int>("HeartBeatInterval"));
_timer = new Timer(OnHeartbeat, null, 1, ws.GetValue<int>("HeartBeatInterval"));
}

public override Task StartAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -58,6 +58,13 @@ public override Task StartAsync(CancellationToken cancellationToken)

var lifecycle = new OneBotLifecycle(Config.GetValue<uint>("Account:Uin"), "connect");
SendJsonAsync(lifecycle, cancellationToken).GetAwaiter().GetResult();

_timer.Change(0, Config.GetValue<int>("Implementation:ForwardWebSocket:HeartBeatInterval"));
};

conn.OnClose = () =>
{
Logger.LogWarning($"[{Tag}: Disconnected]");
};
});
}, cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion Lagrange.OneBot/Core/Network/Service/ReverseWSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ReverseWSService(IConfiguration config, ILogger<LagrangeApp> logger) : ba
return socket;
});

_timer = new Timer(OnHeartbeat, null, int.MaxValue, ws.GetValue<int>("HeartBeatInterval"));
_timer = new Timer(OnHeartbeat, null, -1, ws.GetValue<int>("HeartBeatInterval"));
_socket.MessageReceived.Subscribe(resp =>
{
Logger.LogTrace($"[{Tag}] Receive: {resp.Text}");
Expand Down

0 comments on commit 0a88ad9

Please sign in to comment.