// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "ServerBase.h" #include "WebSocketProbe.h" #include "WebSocketServerWrapper.h" #include "Templates/UniquePtr.h" #include "Templates/SharedPointer.h" #include "Dom/JsonObject.h" namespace UE::PixelStreaming2Servers { /** * A native C++ implementation of a Pixel Streaming signalling server (similar to cirrus.js). * This implementation is missing some features such as SFU and Webserver support. * The purpose of this implementation is to have signalling server callable from UE, without bundling Cirrus itself. **/ class FSignallingServer : public FServerBase { public: FSignallingServer(); virtual ~FSignallingServer() = default; // Begin FServerBase virtual void Stop() override; virtual bool TestConnection() override; virtual bool LaunchImpl(FLaunchArgs& InLaunchArgs, TMap& OutEndpoints) override; virtual FString GetPathOnDisk() override; virtual void GetNumStreamers(TFunction OnNumStreamersReceived) override; // End FServerBase protected: TArray GenerateDirectoriesToServe() const; TSharedRef CreateConfigJSON() const; TSharedPtr ParseMessage(const FString& InMessage, FString& OutMessageType) const; void SubscribePlayer(uint16 PlayerConnectionId, const FString& StreamerName); void UnsubscribePlayer(uint16 PlayerConnectionId); virtual void SendPlayerMessage(uint16 PlayerId, TSharedPtr JSONObj); virtual void SendStreamerMessage(uint16 StreamerId, TSharedPtr JSONObj); // event handlers virtual void OnStreamerConnected(uint16 ConnectionId); virtual void OnStreamerDisconnected(uint16 ConnectionId); virtual void OnStreamerMessage(uint16 ConnectionId, TArrayView Message); virtual void OnPlayerConnected(uint16 ConnectionId); virtual void OnPlayerDisconnected(uint16 ConnectionId); virtual void OnPlayerMessage(uint16 ConnectionId, TArrayView Message); // message handlers void OnStreamerIdMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnStreamerPingMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnStreamerDisconnectMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnPlayerPingMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnPlayerListStreamersMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnPlayerSubscribeMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnPlayerUnsubscribeMessage(uint16 ConnectionId, TSharedPtr JSONObj); void OnPlayerStatsMessage(uint16 ConnectionId, TSharedPtr JSONObj); protected: TUniquePtr Probe; TUniquePtr StreamersWS; TUniquePtr PlayersWS; TMap PlayerSubscriptions; DECLARE_DELEGATE_TwoParams(FMessageHandler, uint16, TSharedPtr); TMap StreamerMessageHandlers; TMap PlayerMessageHandlers; }; } // namespace UE::PixelStreaming2Servers