Fix SSE Maybe

This commit is contained in:
Michael Nolan 2021-11-07 19:55:35 -06:00
parent 9570287c11
commit 969b4719bd
2 changed files with 9 additions and 9 deletions

View File

@ -20,8 +20,8 @@ namespace youtube_downloader
public class SSE
{
public static SSE ServerSentEventItem = new SSE();
List<StreamWriter> Streams = new List<StreamWriter>();
public void RegisterStreamWriter(StreamWriter rp)
List<HttpListenerResponse> Streams = new List<HttpListenerResponse>();
public void RegisterStreamWriter(HttpListenerResponse rp)
{
Streams.Add(rp);
}
@ -40,11 +40,9 @@ namespace youtube_downloader
{
try
{
if(items.BaseStream != null)
{
items.Write(raw_data);
items.Write("\n\n");
}
var bytes = Encoding.UTF8.GetBytes(raw_data + "\n\n");
await items.OutputStream.WriteAsync(bytes, 0, bytes.Length);
await items.OutputStream.FlushAsync();
}
catch (Exception ex)
{
@ -309,8 +307,10 @@ namespace youtube_downloader
{
rp.AddHeader("Cache-Control", "no-cache");
rp.ContentType = "text/event-stream";
StreamWriter w = new StreamWriter(rp.OutputStream, rp.ContentEncoding);
SSE.ServerSentEventItem.RegisterStreamWriter(w);
rp.WithCode();
rp.ContentEncoding = Encoding.UTF8;
SSE.ServerSentEventItem.RegisterResponse(rp);