2025-05-07 21:34:39 +00:00
|
|
|
using BotSharp.Abstraction.Realtime.Models.Session;
|
2025-04-14 06:25:16 +00:00
|
|
|
using System.ClientModel;
|
2025-05-07 21:34:39 +00:00
|
|
|
using System.Net.WebSockets;
|
2025-04-14 06:25:16 +00:00
|
|
|
|
2025-05-07 21:34:39 +00:00
|
|
|
namespace BotSharp.Core.Infrastructures.Websocket;
|
2025-04-14 06:25:16 +00:00
|
|
|
|
2025-05-01 17:47:30 +00:00
|
|
|
internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult<ClientResult>
|
2025-04-14 06:25:16 +00:00
|
|
|
{
|
|
|
|
|
private readonly WebSocket _webSocket;
|
2025-05-01 17:47:30 +00:00
|
|
|
private readonly ChatSessionOptions? _sessionOptions;
|
2025-04-14 15:13:05 +00:00
|
|
|
private readonly CancellationToken _cancellationToken;
|
2025-04-14 06:25:16 +00:00
|
|
|
|
2025-04-14 15:13:05 +00:00
|
|
|
public AsyncWebsocketDataCollectionResult(
|
|
|
|
|
WebSocket webSocket,
|
2025-05-01 17:47:30 +00:00
|
|
|
ChatSessionOptions? sessionOptions,
|
2025-04-14 15:13:05 +00:00
|
|
|
CancellationToken cancellationToken)
|
2025-04-14 06:25:16 +00:00
|
|
|
{
|
|
|
|
|
_webSocket = webSocket;
|
2025-05-01 17:47:30 +00:00
|
|
|
_sessionOptions = sessionOptions;
|
2025-04-14 15:13:05 +00:00
|
|
|
_cancellationToken = cancellationToken;
|
2025-04-14 06:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ContinuationToken? GetContinuationToken(ClientResult page)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
|
|
|
|
|
{
|
2025-05-01 17:47:30 +00:00
|
|
|
await using var enumerator = new AsyncWebsocketDataResultEnumerator(_webSocket, _sessionOptions, _cancellationToken);
|
2025-04-14 06:25:16 +00:00
|
|
|
while (await enumerator.MoveNextAsync().ConfigureAwait(false))
|
|
|
|
|
{
|
|
|
|
|
yield return enumerator.Current;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async IAsyncEnumerable<ClientResult> GetValuesFromPageAsync(ClientResult page)
|
|
|
|
|
{
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
yield return page;
|
|
|
|
|
}
|
|
|
|
|
}
|