Documentation for the Unreal C++ Library
Loading...
Searching...
No Matches
MultiplayerWebSocket.h
Go to the documentation of this file.
1// Copyright(c) 2023 PixoVR, LLC. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "IWebSocket.h"
7
13
15{
16 uint8_t RequestType;
17 FString Json;
18};
19
21{
22public:
23
26
28 FSocketConnected& OnWebSocketConnected() { return SocketConnectedEvent; }
29
30 DECLARE_EVENT_OneParam(MultiplayerWebSocket, FSocketConnectFailed, const FString&);
31 FSocketConnectFailed& OnWebSocketConnectFailed() { return SocketConnectFailedEvent; }
32
33 DECLARE_EVENT_ThreeParams(MultiplayerWebSocket, FSocketDisconnected, int32 StatusCode, const FString& Reason, bool bWasClean);
34 FSocketDisconnected& OnWebSocketDisconnected() { return SocketDisconnectedEvent; }
35
36 DECLARE_EVENT_OneParam(MultiplayerWebSocket, FSocketMessageReceived, const FString&);
37 FSocketMessageReceived& OnWebSocketMessageReceived() { return SocketMessageReceivedEvent; }
38
39 bool AttemptConnect(FString Uri, FString Protocol = "wss");
40 void Disconnect();
42 void RequestMatchMake(int OrgId, int ModuleId);
43
44private:
45 void SetupSocket(TSharedPtr<IWebSocket>& Socket, FString Uri, FString Protocol);
46 void ProcessNextRequest();
47 void CleanUpRequests();
48
49 void SendData(FString Data);
50
51public:
52 // Bad Closes are when the underlying implementation of WebSockets cause new sockets
53 // to close when a Read or Send occurs. The error code is 1006 and only happens in the editor.
56
57private:
58 TSharedPtr<IWebSocket> WebSocket;
59 TArray<MultiplayerRequestData> PendingWebsocketRequests;
61
62 FSocketConnected SocketConnectedEvent;
63 FSocketConnectFailed SocketConnectFailedEvent;
64 FSocketDisconnected SocketDisconnectedEvent;
65 FSocketMessageReceived SocketMessageReceivedEvent;
66
67 FString SocketUri;
69};
MultiplayerWebSocketRequestType
DECLARE_EVENT(MultiplayerWebSocket, FSocketConnected)
DECLARE_EVENT_OneParam(MultiplayerWebSocket, FSocketMessageReceived, const FString &)
DECLARE_EVENT_OneParam(MultiplayerWebSocket, FSocketConnectFailed, const FString &)
MultiplayerRequestData LastWebSocketRequest
FSocketMessageReceived & OnWebSocketMessageReceived()
FSocketDisconnected SocketDisconnectedEvent
DECLARE_EVENT_ThreeParams(MultiplayerWebSocket, FSocketDisconnected, int32 StatusCode, const FString &Reason, bool bWasClean)
FSocketDisconnected & OnWebSocketDisconnected()
TSharedPtr< IWebSocket > WebSocket
FSocketConnected SocketConnectedEvent
FSocketConnectFailed SocketConnectFailedEvent
void SetupSocket(TSharedPtr< IWebSocket > &Socket, FString Uri, FString Protocol)
TArray< MultiplayerRequestData > PendingWebsocketRequests
FSocketMessageReceived SocketMessageReceivedEvent
FSocketConnected & OnWebSocketConnected()
void RequestMatchMake(int OrgId, int ModuleId)
FSocketConnectFailed & OnWebSocketConnectFailed()
bool AttemptConnect(FString Uri, FString Protocol="wss")