27#include "CoreMinimal.h"
28#include "IWebSocket.h"
29#include "Interfaces/IHttpRequest.h"
36class SIGNALR_API
FConnection :
public TSharedFromThis<FConnection>
45 FConnection(
const FString& InHost,
const TMap<FString, FString>& InHeaders);
75 void Send(
const FString& Data);
83 void Close(int32 Code = 1000,
const FString& Reason = FString());
99 IWebSocket::FWebSocketConnectedEvent&
OnConnected();
113 IWebSocket::FWebSocketClosedEvent&
OnClosed();
120 IWebSocket::FWebSocketMessageEvent&
OnMessage();
124 void OnNegotiateResponse(FHttpRequestPtr InRequest, FHttpResponsePtr InResponse,
bool bConnectedSuccessfully);
125 void StartWebSocket();
127 TSharedPtr<IWebSocket> Connection;
129 TMap<FString, FString> Headers;
131 FConnectionFailedEvent OnConnectionFailedEvent;
132 IWebSocket::FWebSocketConnectedEvent OnConnectedEvent;
133 IWebSocket::FWebSocketConnectionErrorEvent OnConnectionErrorEvent;
134 IWebSocket::FWebSocketClosedEvent OnClosedEvent;
135 IWebSocket::FWebSocketMessageEvent OnMessageEvent;
137 FString ConnectionToken;
138 FString ConnectionId;
140 static FString ConvertToWebsocketUrl(
const FString& Url);
@ Close
Definition MessageType.h:41
void Send(const FString &Data)
Sends data over the connection.
Definition Connection.cpp:60
IWebSocket::FWebSocketMessageEvent & OnMessage()
Gets the event that is triggered when a message is received.
Definition Connection.cpp:105
FConnection & operator=(const FConnection &)=delete
IWebSocket::FWebSocketClosedEvent & OnClosed()
Gets the event that is triggered when the connection is closed.
Definition Connection.cpp:100
DECLARE_EVENT(FConnection, FConnectionFailedEvent)
FConnection(const FString &InHost, const TMap< FString, FString > &InHeaders)
Creates a new connection to a SignalR server.
Definition Connection.cpp:36
FConnection(const FConnection &)=delete
bool IsConnected() const
Checks if the connection is currently established.
Definition Connection.cpp:55
FConnectionFailedEvent & OnConnectionFailed()
Gets the event that is triggered when the connection fails to establish.
Definition Connection.cpp:85
IWebSocket::FWebSocketConnectionErrorEvent & OnConnectionError()
Gets the event that is triggered when a connection error occurs.
Definition Connection.cpp:95
void Connect()
Initiates the connection process by starting the negotiation with the server.
Definition Connection.cpp:50
IWebSocket::FWebSocketConnectedEvent & OnConnected()
Gets the event that is triggered when the connection is established.
Definition Connection.cpp:90
FConnection(FConnection &&)=delete
FConnection & operator=(FConnection &&)=delete