internal static async Task WriteSseEventAsync(this HttpResponse response, RawServerSentEvent serverSentEvent)
        {
            if (serverSentEvent.Id != null)
            {
                await response.WriteSseEventFieldAsync(_sseIdField, serverSentEvent.Id);
            }

            if (serverSentEvent.Type != null)
            {
                await response.WriteSseEventFieldAsync(_sseEventField, serverSentEvent.Type);
            }

            if (serverSentEvent.Data != null)
            {
                for (int i = 0; i < serverSentEvent.Data.Count; i++)
                {
                    await response.WriteSseEventFieldAsync(_sseDataField, serverSentEvent.Data[i]);
                }
            }

            await response.WriteSseEventBoundaryAsync();
        }
Ejemplo n.º 2
0
        internal Task SendEventAsync(RawServerSentEvent serverSentEvent)
        {
            CheckIsConnected();

            return(_response.WriteSseEventAsync(serverSentEvent));
        }