using BotSharp.Abstraction.Realtime.Models.Session; using System.ClientModel; using System.Net.WebSockets; namespace BotSharp.Core.Infrastructures.Websocket; internal class AsyncWebsocketDataCollectionResult : AsyncCollectionResult { private readonly WebSocket _webSocket; private readonly ChatSessionOptions? _sessionOptions; private readonly CancellationToken _cancellationToken; public AsyncWebsocketDataCollectionResult( WebSocket webSocket, ChatSessionOptions? sessionOptions, CancellationToken cancellationToken) { _webSocket = webSocket; _sessionOptions = sessionOptions; _cancellationToken = cancellationToken; } public override ContinuationToken? GetContinuationToken(ClientResult page) { return null; } public override async IAsyncEnumerable GetRawPagesAsync() { await using var enumerator = new AsyncWebsocketDataResultEnumerator(_webSocket, _sessionOptions, _cancellationToken); while (await enumerator.MoveNextAsync().ConfigureAwait(false)) { yield return enumerator.Current; } } protected override async IAsyncEnumerable GetValuesFromPageAsync(ClientResult page) { await Task.CompletedTask; yield return page; } }