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