2025-04-14 06:25:16 +00:00
|
|
|
using System.ClientModel;
|
|
|
|
|
using System.Net.WebSockets;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Plugin.OpenAI.Providers.Realtime.Session;
|
|
|
|
|
|
2025-04-25 14:58:04 +00:00
|
|
|
internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult<ClientResult>
|
2025-04-14 06:25:16 +00:00
|
|
|
{
|
|
|
|
|
private readonly WebSocket _webSocket;
|
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,
|
|
|
|
|
CancellationToken cancellationToken)
|
2025-04-14 06:25:16 +00:00
|
|
|
{
|
|
|
|
|
_webSocket = webSocket;
|
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-04-14 15:13:05 +00:00
|
|
|
await using var enumerator = new AsyncWebsocketDataResultEnumerator(_webSocket, _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;
|
|
|
|
|
}
|
|
|
|
|
}
|