diff --git a/Uploader.cs b/Uploader.cs index aa586f1..ce39fe4 100644 --- a/Uploader.cs +++ b/Uploader.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data.Common; using System.IO; using System.Linq; +using System.Threading; using HarmonyLib; using Photon.Pun; using Steamworks; @@ -16,6 +17,30 @@ namespace SpookTubeEX; class SpookedUploader { + void UploadThread(MessageEventArgs evt, WebSocket ws, string path, string uuid) + { + // Begin Upload + byte[] byteArray = File.ReadAllBytes(path); + + int offset = 0; + const int chunkSize = 512000; + + while (byteArray.Length > offset * chunkSize) + { + byte[] buffer = byteArray.Skip(offset * chunkSize).Take(chunkSize).ToArray(); + offset += 1; + + ws.Send($"Bytes: {buffer.Length}"); + + List msgList = new List(); + + msgList.AddRange(new byte[1] { 36 }); + msgList.AddRange(buffer); + + ws.Send(msgList.ToArray()); + } + } + WebSocket ws; public void Upload(IPlayableVideo cameraRecording, int views, CommentUI[] comments, Action onUpload) { @@ -52,31 +77,13 @@ class SpookedUploader { ws.Send(evt.Data); + Plugin.Logger.LogInfo("WS MESSAGE: " + evt.Data); + if (evt.Data.StartsWith("url:")) viewableUrl = evt.Data.Substring(4); if (evt.Data.StartsWith("uuid:")) { uuid = evt.Data.Substring(5); - - // Begin Upload - byte[] byteArray = File.ReadAllBytes(path); - - int offset = 0; - const int chunkSize = 512000; - - while (byteArray.Length > offset * chunkSize) - { - byte[] buffer = byteArray.Skip(offset * chunkSize).Take(chunkSize).ToArray(); - offset += 1; - - ws.Send($"Bytes: {buffer.Length}"); - - List msgList = new List(); - - msgList.AddRange(new byte[1] { 36 }); - msgList.AddRange(buffer); - - ws.Send(msgList.ToArray()); - } + new Thread(new ThreadStart(() => UploadThread(evt, ws, path, uuid))).Start(); } if (evt.Data.StartsWith("fin")) @@ -96,7 +103,7 @@ class SpookedUploader ws.OnError += (sender, evt) => { - UnityEngine.Debug.LogError(evt.Message); + Plugin.Logger.LogError(evt.Message); }; ws.OnOpen += (sender, evt) =>