├── .gitignore ├── Config └── FilterPlugin.ini ├── EasyWebsockets.uplugin ├── LICENSE ├── README.md ├── Resources └── Icon128.png └── Source └── EasyWebsockets ├── EasyWebsockets.Build.cs ├── Private ├── EasyWebsockets.cpp ├── Websocket.cpp └── WebsocketFunctionLibrary.cpp └── Public ├── EasyWebsockets.h ├── Websocket.h └── WebsocketFunctionLibrary.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Visual Studio 2015 user specific files 2 | .vs/ 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | *.ipa 33 | 34 | # These project files can be generated by the engine 35 | *.xcodeproj 36 | *.xcworkspace 37 | *.sln 38 | *.suo 39 | *.opensdf 40 | *.sdf 41 | *.VC.db 42 | *.VC.opendb 43 | 44 | # Precompiled Assets 45 | SourceArt/**/*.png 46 | SourceArt/**/*.tga 47 | 48 | # Binary Files 49 | Binaries/* 50 | Plugins/*/Binaries/* 51 | 52 | # Builds 53 | Build/* 54 | 55 | # Whitelist PakBlacklist-.txt files 56 | !Build/*/ 57 | Build/*/** 58 | !Build/*/PakBlacklist*.txt 59 | 60 | # Don't ignore icon files in Build 61 | !Build/**/*.ico 62 | 63 | # Built data for maps 64 | *_BuiltData.uasset 65 | 66 | # Configuration files generated by the Editor 67 | Saved/* 68 | 69 | # Compiled source files for the engine to use 70 | Intermediate/* 71 | Plugins/*/Intermediate/* 72 | 73 | # Cache files for the editor to use 74 | DerivedDataCache/* -------------------------------------------------------------------------------- /Config/FilterPlugin.ini: -------------------------------------------------------------------------------- 1 | [FilterPlugin] 2 | /Resources/ 3 | LICENSE 4 | README.md -------------------------------------------------------------------------------- /EasyWebsockets.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "BlueprintWebsockets", 6 | "Description": "A lightweight plugin that wraps the IWebSocket interface allowing you to connect to a WebSocket server directly in Blueprint", 7 | "Category": "Other", 8 | "CreatedBy": "Chris Ringenberg", 9 | "CreatedByURL": "https://www.ringenberg.dev/", 10 | "DocsURL": "https://docs.google.com/document/d/1EXeESlA3gbdMkv2n9b5hhK5mhQTMLh-9aGH3XV_pdYs/edit?usp=sharing", 11 | "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/4b5a7cbf6dda4b91878824a47104c596", 12 | "SupportURL": "https://www.ringenberg.dev/contact", 13 | "CanContainContent": false, 14 | "EngineVersion": "5.0", 15 | "IsBetaVersion": false, 16 | "IsExperimentalVersion": false, 17 | "Installed": true, 18 | "Modules": [ 19 | { 20 | "Name": "EasyWebsockets", 21 | "Type": "Runtime", 22 | "LoadingPhase": "Default", 23 | "WhitelistPlatforms": [ 24 | "Win64" 25 | ] 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Chris 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlueprintWebsockets 2 | Simple Blueprint Websocket plugin for Unreal Engine 4 3 | 4 | Unreal Engine 5 support 5 | 6 | ![image](https://user-images.githubusercontent.com/21158549/155652050-8efb4b20-ff9e-4666-bbe8-174ffbcca76c.png) 7 | 8 | 9 | ![image](https://user-images.githubusercontent.com/21158549/155652245-0049aacb-6cd4-47a6-a6cf-ff617f73b854.png) 10 | 11 | Documentation: https://docs.google.com/document/d/1EXeESlA3gbdMkv2n9b5hhK5mhQTMLh-9aGH3XV_pdYs/edit?usp=sharing 12 | 13 | Support Discord: https://discord.com/invite/W36D96gJqX 14 | -------------------------------------------------------------------------------- /Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minimpoun/BlueprintWebsockets/641e09e12d6e97cef756a216a8a6eb6251e85348/Resources/Icon128.png -------------------------------------------------------------------------------- /Source/EasyWebsockets/EasyWebsockets.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | using UnrealBuildTool; 4 | 5 | public class EasyWebsockets : ModuleRules 6 | { 7 | public EasyWebsockets(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange( 12 | new string[] 13 | { 14 | "Core", 15 | "CoreUObject", 16 | "WebSockets" 17 | } 18 | ); 19 | 20 | 21 | PrivateDependencyModuleNames.AddRange( 22 | new string[] 23 | { 24 | "Engine", 25 | "Slate", 26 | "SlateCore" 27 | } 28 | ); 29 | 30 | PublicDefinitions.Add("WITH_WEBSOCKETS=1"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Source/EasyWebsockets/Private/EasyWebsockets.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #include "EasyWebsockets.h" 4 | #include "Modules/ModuleManager.h" 5 | #include "WebSocketsModule.h" 6 | 7 | #define LOCTEXT_NAMESPACE "FEasyWebsocketsModule" 8 | 9 | void FEasyWebsocketsModule::StartupModule() 10 | { 11 | FModuleManager::LoadModuleChecked("WebSockets"); 12 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 13 | } 14 | 15 | void FEasyWebsocketsModule::ShutdownModule() 16 | { 17 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 18 | // we call this function before unloading the module. 19 | } 20 | 21 | #undef LOCTEXT_NAMESPACE 22 | 23 | IMPLEMENT_MODULE(FEasyWebsocketsModule, EasyWebsockets) 24 | -------------------------------------------------------------------------------- /Source/EasyWebsockets/Private/Websocket.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #include "Websocket.h" 4 | #include "IWebSocket.h" 5 | 6 | void UWebSocket::InitWebSocket(TSharedPtr InWebSocket) 7 | { 8 | InternalWebSocket = InWebSocket; 9 | 10 | InternalWebSocket->OnConnected().AddUObject(this, &ThisClass::OnWebSocketConnected_Internal); 11 | InternalWebSocket->OnConnectionError().AddUObject(this, &ThisClass::OnWebSocketConnectionError_Internal); 12 | InternalWebSocket->OnClosed().AddUObject(this, &ThisClass::OnWebSocketClosed_Internal); 13 | InternalWebSocket->OnMessage().AddUObject(this, &ThisClass::OnWebSocketMessageReceived_Internal); 14 | InternalWebSocket->OnMessageSent().AddUObject(this, &ThisClass::OnWebSocketMessageSent_Internal); 15 | } 16 | 17 | void UWebSocket::Connect() 18 | { 19 | InternalWebSocket->Connect(); 20 | } 21 | 22 | void UWebSocket::Close(int32 StatusCode, const FString& Reason) 23 | { 24 | InternalWebSocket->Close(StatusCode, Reason); 25 | } 26 | 27 | bool UWebSocket::IsConnected() const 28 | { 29 | return InternalWebSocket->IsConnected(); 30 | } 31 | 32 | void UWebSocket::SendMessage(const FString& Message) 33 | { 34 | InternalWebSocket->Send(Message); 35 | } 36 | 37 | void UWebSocket::OnWebSocketConnected_Internal() 38 | { 39 | OnWebSocketConnected.Broadcast(); 40 | } 41 | 42 | void UWebSocket::OnWebSocketConnectionError_Internal(const FString& Error) 43 | { 44 | OnWebSocketConnectionError.Broadcast(Error); 45 | } 46 | 47 | void UWebSocket::OnWebSocketClosed_Internal(int32 StatusCode, const FString& Reason, bool bWasClean) 48 | { 49 | OnWebSocketClosed.Broadcast(StatusCode, Reason, bWasClean); 50 | } 51 | 52 | void UWebSocket::OnWebSocketMessageReceived_Internal(const FString& Message) 53 | { 54 | OnWebSocketMessageReceived.Broadcast(Message); 55 | } 56 | 57 | 58 | void UWebSocket::OnWebSocketMessageSent_Internal(const FString& Message) 59 | { 60 | OnWebSocketMessageSent.Broadcast(Message); 61 | } 62 | -------------------------------------------------------------------------------- /Source/EasyWebsockets/Private/WebsocketFunctionLibrary.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #include "WebsocketFunctionLibrary.h" 4 | 5 | #include "IWebSocket.h" 6 | #include "Websocket.h" 7 | #include "WebSocketsModule.h" 8 | 9 | UWebSocket* UWebSocketFunctionLibrary::CreateWebSocket(FString ServerUrl, FString ServerProtocol) 10 | { 11 | return CreateWebSocketWithHeaders(ServerUrl, {}, ServerProtocol); 12 | } 13 | 14 | UWebSocket* UWebSocketFunctionLibrary::CreateWebSocketWithHeaders(FString ServerUrl, TMap UpgradeHeaders, FString ServerProtocol /* = TEXT("ws") */) 15 | { 16 | const TSharedPtr ActualSocket = FModuleManager::LoadModuleChecked(TEXT("WebSockets")).CreateWebSocket(ServerUrl, ServerProtocol, UpgradeHeaders); 17 | UWebSocket* const WrapperSocket = NewObject(); 18 | WrapperSocket->InitWebSocket(ActualSocket); 19 | return WrapperSocket; 20 | } 21 | -------------------------------------------------------------------------------- /Source/EasyWebsockets/Public/EasyWebsockets.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | class FEasyWebsocketsModule : public IModuleInterface 9 | { 10 | public: 11 | 12 | /** IModuleInterface implementation */ 13 | virtual void StartupModule() override; 14 | virtual void ShutdownModule() override; 15 | }; 16 | -------------------------------------------------------------------------------- /Source/EasyWebsockets/Public/Websocket.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UObject/Object.h" 7 | 8 | #include "Websocket.generated.h" 9 | 10 | class IWebSocket; 11 | 12 | DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWebSocketConnected); 13 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWebSocketConnectionError, const FString&, Error); 14 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnWebSocketClosed, int32, StatusCode, const FString&, Reason, bool, bWasClean); 15 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWebSocketMessageReceived, const FString&, Message); 16 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWebSocketMessageSent, const FString&, Message); 17 | 18 | UCLASS(MinimalAPI, BlueprintType) 19 | class UWebSocket final : public UObject 20 | { 21 | GENERATED_BODY() 22 | 23 | public: 24 | 25 | UPROPERTY(BlueprintAssignable) 26 | FOnWebSocketConnected OnWebSocketConnected; 27 | 28 | UPROPERTY(BlueprintAssignable) 29 | FOnWebSocketConnectionError OnWebSocketConnectionError; 30 | 31 | UPROPERTY(BlueprintAssignable) 32 | FOnWebSocketClosed OnWebSocketClosed; 33 | 34 | UPROPERTY(BlueprintAssignable) 35 | FOnWebSocketMessageReceived OnWebSocketMessageReceived; 36 | 37 | UPROPERTY(BlueprintAssignable) 38 | FOnWebSocketMessageSent OnWebSocketMessageSent; 39 | 40 | void InitWebSocket(TSharedPtr InWebSocket); 41 | 42 | UFUNCTION(BlueprintCallable, Category = "Easy WebSockets") 43 | void Connect(); 44 | 45 | UFUNCTION(BlueprintCallable, Category = "Easy WebSockets") 46 | void Close(int32 StatusCode = 1000, const FString& Reason = TEXT("")); 47 | 48 | UFUNCTION(BlueprintPure, Category = "Easy WebSockets") 49 | bool IsConnected() const; 50 | 51 | UFUNCTION(BlueprintCallable, Category = "Easy WebSockets") 52 | void SendMessage(const FString& Message); 53 | 54 | private: 55 | 56 | UFUNCTION() 57 | void OnWebSocketConnected_Internal(); 58 | 59 | UFUNCTION() 60 | void OnWebSocketConnectionError_Internal(const FString& Error); 61 | 62 | UFUNCTION() 63 | void OnWebSocketClosed_Internal(int32 StatusCode, const FString& Reason, bool bWasClean); 64 | 65 | UFUNCTION() 66 | void OnWebSocketMessageReceived_Internal(const FString& Message); 67 | 68 | UFUNCTION() 69 | void OnWebSocketMessageSent_Internal(const FString& Message); 70 | 71 | TSharedPtr InternalWebSocket; 72 | 73 | }; -------------------------------------------------------------------------------- /Source/EasyWebsockets/Public/WebsocketFunctionLibrary.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Chris Ringenberg https://www.ringenberg.dev/ 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Kismet/BlueprintFunctionLibrary.h" 7 | 8 | #include "WebsocketFunctionLibrary.generated.h" 9 | 10 | class UWebSocket; 11 | 12 | UCLASS(MinimalAPI) 13 | class UWebSocketFunctionLibrary final : public UBlueprintFunctionLibrary 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | UFUNCTION(BlueprintCallable, Category = "Easy WebSockets") 20 | static UWebSocket* CreateWebSocket(FString ServerUrl, FString ServerProtocol = TEXT("ws")); 21 | 22 | UFUNCTION(BlueprintCallable, Category = "Easy WebSockets") 23 | static UWebSocket* CreateWebSocketWithHeaders(FString ServerUrl, TMap UpgradeHeaders, FString ServerProtocol = TEXT("ws")); 24 | }; --------------------------------------------------------------------------------