Make Upload Threaded
This commit is contained in:
parent
89f4a7debe
commit
eaf7c19138
51
Uploader.cs
51
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<byte> msgList = new List<byte>();
|
||||
|
||||
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<byte> msgList = new List<byte>();
|
||||
|
||||
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) =>
|
||||
|
|
Loading…
Reference in New Issue
Block a user