[backend/masto-client] Handle query parameters for streaming API WebSocket connections
This commit is contained in:
parent
65136beef6
commit
18af329ba6
3 changed files with 20 additions and 3 deletions
|
@ -60,6 +60,11 @@ public sealed class WebSocketConnection(
|
|||
return;
|
||||
}
|
||||
|
||||
await HandleSocketMessageAsync(message);
|
||||
}
|
||||
|
||||
public async Task HandleSocketMessageAsync(StreamingRequestMessage message)
|
||||
{
|
||||
switch (message.Type)
|
||||
{
|
||||
case "subscribe":
|
||||
|
|
|
@ -9,7 +9,7 @@ public static class WebSocketHandler
|
|||
{
|
||||
public static async Task HandleConnectionAsync(
|
||||
WebSocket socket, OauthToken token, EventService eventSvc, IServiceScopeFactory scopeFactory,
|
||||
CancellationToken ct
|
||||
string? stream, string? list, string? tag, CancellationToken ct
|
||||
)
|
||||
{
|
||||
using var connection = new WebSocketConnection(socket, token, eventSvc, scopeFactory, ct);
|
||||
|
@ -19,6 +19,17 @@ public static class WebSocketHandler
|
|||
|
||||
connection.InitializeStreamingWorker();
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
await connection.HandleSocketMessageAsync(new StreamingRequestMessage
|
||||
{
|
||||
Type = "subscribe",
|
||||
Stream = stream,
|
||||
List = list,
|
||||
Tag = tag
|
||||
});
|
||||
}
|
||||
|
||||
while ((!res?.CloseStatus.HasValue ?? true) &&
|
||||
!ct.IsCancellationRequested &&
|
||||
socket.State is WebSocketState.Open)
|
||||
|
|
|
@ -21,7 +21,7 @@ public class WebSocketController(
|
|||
{
|
||||
[Route("/api/v1/streaming")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public async Task GetStreamingSocket()
|
||||
public async Task GetStreamingSocket([FromQuery] string? stream, [FromQuery] string? list, [FromQuery] string? tag)
|
||||
{
|
||||
if (!HttpContext.WebSockets.IsWebSocketRequest)
|
||||
throw GracefulException.BadRequest("Not a WebSocket request");
|
||||
|
@ -34,7 +34,8 @@ public class WebSocketController(
|
|||
try
|
||||
{
|
||||
var token = await Authenticate(accessToken);
|
||||
await WebSocketHandler.HandleConnectionAsync(webSocket, token, eventSvc, scopeFactory, ct);
|
||||
await WebSocketHandler.HandleConnectionAsync(webSocket, token, eventSvc, scopeFactory,
|
||||
stream, list, tag, ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue