[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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await HandleSocketMessageAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task HandleSocketMessageAsync(StreamingRequestMessage message)
|
||||||
|
{
|
||||||
switch (message.Type)
|
switch (message.Type)
|
||||||
{
|
{
|
||||||
case "subscribe":
|
case "subscribe":
|
||||||
|
|
|
@ -9,7 +9,7 @@ public static class WebSocketHandler
|
||||||
{
|
{
|
||||||
public static async Task HandleConnectionAsync(
|
public static async Task HandleConnectionAsync(
|
||||||
WebSocket socket, OauthToken token, EventService eventSvc, IServiceScopeFactory scopeFactory,
|
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);
|
using var connection = new WebSocketConnection(socket, token, eventSvc, scopeFactory, ct);
|
||||||
|
@ -19,6 +19,17 @@ public static class WebSocketHandler
|
||||||
|
|
||||||
connection.InitializeStreamingWorker();
|
connection.InitializeStreamingWorker();
|
||||||
|
|
||||||
|
if (stream != null)
|
||||||
|
{
|
||||||
|
await connection.HandleSocketMessageAsync(new StreamingRequestMessage
|
||||||
|
{
|
||||||
|
Type = "subscribe",
|
||||||
|
Stream = stream,
|
||||||
|
List = list,
|
||||||
|
Tag = tag
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
while ((!res?.CloseStatus.HasValue ?? true) &&
|
while ((!res?.CloseStatus.HasValue ?? true) &&
|
||||||
!ct.IsCancellationRequested &&
|
!ct.IsCancellationRequested &&
|
||||||
socket.State is WebSocketState.Open)
|
socket.State is WebSocketState.Open)
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class WebSocketController(
|
||||||
{
|
{
|
||||||
[Route("/api/v1/streaming")]
|
[Route("/api/v1/streaming")]
|
||||||
[ApiExplorerSettings(IgnoreApi = true)]
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
public async Task GetStreamingSocket()
|
public async Task GetStreamingSocket([FromQuery] string? stream, [FromQuery] string? list, [FromQuery] string? tag)
|
||||||
{
|
{
|
||||||
if (!HttpContext.WebSockets.IsWebSocketRequest)
|
if (!HttpContext.WebSockets.IsWebSocketRequest)
|
||||||
throw GracefulException.BadRequest("Not a WebSocket request");
|
throw GracefulException.BadRequest("Not a WebSocket request");
|
||||||
|
@ -34,7 +34,8 @@ public class WebSocketController(
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var token = await Authenticate(accessToken);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue