// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Subsystems/EngineSubsystem.h"
#include "ServerAutoStart.generated.h"

UCLASS()
class PIXELSTREAMCONTROLLER_API UServerAutoStart : public UEngineSubsystem
{
	GENERATED_BODY()
	
public:	
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;
	virtual void Deinitialize() override;

protected:

	void StartSignallingServer();
	void StartTURNServer();

	void CloseSignallingServer();
	void CloseTURNServer();

	bool IsSignallingServerRunning() const;
	bool IsTURNServerRunning() const;

	FProcHandle StartPowershellProcess(const FString& File, const FString& AdditionalArg) const;
	static bool IsProcessRunning(const FString& Process);

	FString BatScript;
	FString ScriptFolder;
	FProcHandle SignallingProcHandle;
	FProcHandle TURNProcHandle;
};
