-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add embedded login support (#3972) #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+2.15 KB
(100%)
Content/BlueprintSampleContent/ImtblAuthenticatedWidget4_26.uasset
Binary file not shown.
Binary file modified
BIN
+732 Bytes
(100%)
Content/BlueprintSampleContent/ImtblUnauthenticatedLevel.umap
Binary file not shown.
Binary file modified
BIN
+59 KB
(120%)
Content/BlueprintSampleContent/ImtblUnauthenticatedWidget4_26.uasset
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
Source/Immutable/Private/Immutable/Actions/ImtblEmbeddedLoginAsyncAction.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #include "Immutable/Actions/ImtblEmbeddedLoginAsyncAction.h" | ||
|
|
||
| #include "Immutable/Actions/ImtblConnectImxAsyncAction.h" | ||
| #include "Immutable/Browser/ImmutableJSConnectorBrowserWidget.h" | ||
|
|
||
| UImtblEmbeddedLoginAsyncAction* UImtblEmbeddedLoginAsyncAction::Login(UObject* WorldContextObject, UImmutableJSConnectorBrowserWidget* JSConnectorBrowserWidget) | ||
| { | ||
| ThisClass* Action = NewObject<ThisClass>(); | ||
|
|
||
| if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull)) | ||
| { | ||
| Action->BindedWorld = World; | ||
| Action->BindedJSConnectorBrowserWidget = JSConnectorBrowserWidget; | ||
| Action->RegisterWithGameInstance(WorldContextObject); | ||
| } | ||
|
|
||
| return Action; | ||
| } | ||
|
|
||
| void UImtblEmbeddedLoginAsyncAction::Activate() | ||
| { | ||
| Super::Activate(); | ||
|
|
||
| if (UWorld* World = BindedWorld.Get()) | ||
| { | ||
| if (UImmutableJSConnectorBrowserWidget* JSConnectorBrowserWidget = BindedJSConnectorBrowserWidget.Get()) | ||
| { | ||
| JSConnectorBrowserWidget->GetJSConnector()->MulticastDelegate_OnEventToGame()->AddWeakLambda(this, [this, World, JSConnectorBrowserWidget](const FString& Event, const FString& Message, const TOptional<FImtblJSResponse>& Response) | ||
| { | ||
| if (Event == TEXT("HandleLoginData") && Response.IsSet()) | ||
| { | ||
| FImmutableDirectLoginOptions DirectLoginOptions; | ||
| if (UImmutableDirectLoginOptionsStatics::FromJSResponse(Response.GetValue(), DirectLoginOptions)) | ||
| { | ||
| if ((LoginAsyncAction = UImtblConnectionAsyncActions::Login(World, DirectLoginOptions))) | ||
| { | ||
| LoginAsyncAction->DynamicMulticastDelegate_OnSuccess()->AddDynamic(this, &ThisClass::LoginAsyncAction_DynamicMulticastDelegate_OnSuccess); | ||
| LoginAsyncAction->DynamicMulticastDelegate_OnFailed()->AddDynamic(this, &ThisClass::LoginAsyncAction_DynamicMulticastDelegate_OnFailed); | ||
| LoginAsyncAction->Activate(); | ||
| } | ||
| else | ||
| { | ||
| SetReadyToDestroy(); | ||
| } | ||
| } | ||
| } | ||
| else if (Event == TEXT("HandleClose")) | ||
| { | ||
| JSConnectorBrowserWidget->LoadURL(TEXT("about:blank")); | ||
| Internal_Closed_MulticastDelegate.Broadcast(); | ||
| Internal_Closed_DynamicMulticastDelegate.Broadcast(); | ||
| SetReadyToDestroy(); | ||
| } | ||
| }); | ||
| JSConnectorBrowserWidget->LoadURL(TEXT("https://auth.immutable.com/im-embedded-login-prompt?isWebView=true")); | ||
| } | ||
| else | ||
| { | ||
| SetReadyToDestroy(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| SetReadyToDestroy(); | ||
| } | ||
| } | ||
|
|
||
| void UImtblEmbeddedLoginAsyncAction::SetReadyToDestroy() | ||
| { | ||
| if (LoginAsyncAction) | ||
| { | ||
| LoginAsyncAction->DynamicMulticastDelegate_OnSuccess()->RemoveAll(this); | ||
| LoginAsyncAction->DynamicMulticastDelegate_OnFailed()->RemoveAll(this); | ||
| LoginAsyncAction->SetReadyToDestroy(); | ||
| LoginAsyncAction = nullptr; | ||
| } | ||
| if (UImmutableJSConnectorBrowserWidget* JSConnectorBrowserWidget = BindedJSConnectorBrowserWidget.Get()) | ||
| { | ||
| JSConnectorBrowserWidget->GetJSConnector()->MulticastDelegate_OnEventToGame()->RemoveAll(this); | ||
| } | ||
| Super::SetReadyToDestroy(); | ||
| } | ||
|
|
||
| UImtblConnectionAsyncActions* UImtblEmbeddedLoginAsyncAction::GetLoginAsyncAction() const | ||
| { | ||
| return LoginAsyncAction; | ||
| } | ||
|
|
||
| FImmutableMessageMulticastDelegate* UImtblEmbeddedLoginAsyncAction::LoginFailed_MulticastDelegate() | ||
| { | ||
| return &Internal_LoginFailed_MulticastDelegate; | ||
| } | ||
|
|
||
| FImmutableMessageDynamicMulticastDelegate* UImtblEmbeddedLoginAsyncAction::LoginFailed_DynamicMulticastDelegate() | ||
| { | ||
| return &Internal_LoginFailed_DynamicMulticastDelegate; | ||
| } | ||
|
|
||
| FSimpleMulticastDelegate* UImtblEmbeddedLoginAsyncAction::LoginSuccess_MulticastDelegate() | ||
| { | ||
| return &Internal_LoginSuccess_MulticastDelegate; | ||
| } | ||
|
|
||
| FImmutableSimpleDynamicMulticastDelegate* UImtblEmbeddedLoginAsyncAction::LoginSuccess_DynamicMulticastDelegate() | ||
| { | ||
| return &Internal_LoginSuccess_DynamicMulticastDelegate; | ||
| } | ||
|
|
||
| FSimpleMulticastDelegate* UImtblEmbeddedLoginAsyncAction::Closed_MulticastDelegate() | ||
| { | ||
| return &Internal_Closed_MulticastDelegate; | ||
| } | ||
|
|
||
| FImmutableSimpleDynamicMulticastDelegate* UImtblEmbeddedLoginAsyncAction::Closed_DynamicMulticastDelegate() | ||
| { | ||
| return &Internal_Closed_DynamicMulticastDelegate; | ||
| } | ||
|
|
||
| void UImtblEmbeddedLoginAsyncAction::LoginAsyncAction_DynamicMulticastDelegate_OnSuccess(FString String) | ||
| { | ||
| Internal_LoginSuccess_MulticastDelegate.Broadcast(); | ||
| Internal_LoginSuccess_DynamicMulticastDelegate.Broadcast(); | ||
| SetReadyToDestroy(); | ||
| } | ||
|
|
||
| void UImtblEmbeddedLoginAsyncAction::LoginAsyncAction_DynamicMulticastDelegate_OnFailed(FString String) | ||
| { | ||
| Internal_LoginFailed_MulticastDelegate.Broadcast(String); | ||
| Internal_LoginFailed_DynamicMulticastDelegate.Broadcast(String); | ||
| SetReadyToDestroy(); | ||
| } |
142 changes: 142 additions & 0 deletions
142
Source/Immutable/Private/Immutable/Browser/ImmutableBaseBrowserWidget.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #include "Immutable/Browser/ImmutableBaseBrowserWidget.h" | ||
|
|
||
| #include "Immutable/Misc/ImtblLogging.h" | ||
|
|
||
| #define LOCTEXT_NAMESPACE "BaseBrowserWidget" | ||
|
|
||
| void UImmutableBaseBrowserWidget::ReleaseSlateResources(bool bReleaseChildren) | ||
| { | ||
| Super::ReleaseSlateResources(bReleaseChildren); | ||
|
|
||
| #if USING_BUNDLED_CEF | ||
| WebBrowserWidget.Reset(); | ||
| #endif | ||
| } | ||
|
|
||
| bool UImmutableBaseBrowserWidget::IsPageLoaded() const | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| return WebBrowserWidget.IsValid() && WebBrowserWidget->IsLoaded(); | ||
| #endif | ||
| return false; | ||
| } | ||
|
|
||
| void UImmutableBaseBrowserWidget::LoadURL(FString NewURL) const | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| if (WebBrowserWidget.IsValid()) | ||
| { | ||
| return WebBrowserWidget->LoadURL(NewURL); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| void UImmutableBaseBrowserWidget::LoadString(FString Contents, FString DummyURL) | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| if (WebBrowserWidget.IsValid()) | ||
| { | ||
| WebBrowserWidget->LoadString(Contents, DummyURL); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| FImmutableBrowserConsoleMessageDynamicMulticastDelegate* UImmutableBaseBrowserWidget::DynamicMulticastDelegate_OnConsoleMessage() | ||
| { | ||
| return &Internal_DynamicMulticastDelegate_OnConsoleMessage; | ||
| } | ||
|
|
||
| FSimpleMulticastDelegate UImmutableBaseBrowserWidget::MulticastDelegate_OnLoadCompleted() | ||
| { | ||
| return Internal_MulticastDelegate_OnLoadCompleted; | ||
| } | ||
|
|
||
| FSimpleMulticastDelegate* UImmutableBaseBrowserWidget::MulticastDelegate_OnBrowserCreated() | ||
| { | ||
| return &Internal_MulticastDelegate_OnBrowserCreated; | ||
| } | ||
|
|
||
| TSharedRef<SWidget> UImmutableBaseBrowserWidget::RebuildWidget() | ||
| { | ||
| if (IsDesignTime()) | ||
| { | ||
| // Show placeholder in editor | ||
| return SNew(SBox) | ||
| .HAlign(HAlign_Center) | ||
| .VAlign(VAlign_Center) | ||
| [ | ||
| SNew(STextBlock) | ||
| .Text(LOCTEXT("BrowserPlaceholder", "Browser Widget")) | ||
| ]; | ||
| } | ||
| else | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| // Create the web browser widget | ||
| WebBrowserWidget = SNew(SWebBrowser) | ||
| .InitialURL(InitialURL) | ||
| .ShowControls(false) | ||
| .SupportsTransparency(bSupportsTransparency) | ||
| .ShowInitialThrobber(bShowInitialThrobber) | ||
| #if PLATFORM_ANDROID || PLATFORM_IOS | ||
| .OnLoadCompleted(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandleOnLoadCompleted)) | ||
| #endif | ||
| #if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1 | ||
| .OnConsoleMessage(BIND_UOBJECT_DELEGATE(FOnConsoleMessageDelegate, HandleOnConsoleMessage)) | ||
| #endif | ||
| ; | ||
|
|
||
| return WebBrowserWidget.ToSharedRef(); | ||
| #else | ||
| // Fallback for non-CEF builds | ||
| return | ||
| SNew(SBox) | ||
| .HAlign(HAlign_Center) | ||
| .VAlign(VAlign_Center) | ||
| [ | ||
| SNew(STextBlock) | ||
| .Text(LOCTEXT("NoCEF", "Browser Not Available")) | ||
| ]; | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| void UImmutableBaseBrowserWidget::OnWidgetRebuilt() | ||
| { | ||
| Super::OnWidgetRebuilt(); | ||
|
|
||
| OnBrowserCreated(); | ||
| } | ||
|
|
||
| #if PLATFORM_ANDROID || PLATFORM_IOS | ||
| void UImmutableBaseBrowserWidget::HandleOnLoadCompleted() | ||
| { | ||
| // Default mobile load handling | ||
| HandleLoadCompleted(); | ||
| } | ||
| #endif | ||
|
|
||
| #if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1 | ||
| void UImmutableBaseBrowserWidget::HandleOnConsoleMessage(const FString& Message, const FString& Source, int32 Line, EWebBrowserConsoleLogSeverity Severity) | ||
| { | ||
| UE_LOG(LogImmutable, Log, TEXT("Browser console message: %s, Source: %s, Line: %d, Severity: %d"), *Message, *Source, Line, Severity); | ||
| HandleConsoleMessage(Message, Source, Line, static_cast<int32>(Severity)); | ||
| } | ||
| #endif | ||
|
|
||
| void UImmutableBaseBrowserWidget::HandleLoadCompleted() | ||
| { | ||
| Internal_MulticastDelegate_OnLoadCompleted.Broadcast(); | ||
| } | ||
|
|
||
| void UImmutableBaseBrowserWidget::HandleConsoleMessage(const FString& Message, const FString& Source, int32 Line, int32 Severity) | ||
| { | ||
| Internal_DynamicMulticastDelegate_OnConsoleMessage.Broadcast(Message, Source, Line, Severity); | ||
| } | ||
|
|
||
| void UImmutableBaseBrowserWidget::OnBrowserCreated() | ||
| { | ||
| Internal_MulticastDelegate_OnBrowserCreated.Broadcast(); | ||
| } | ||
|
|
||
| #undef LOCTEXT_NAMESPACE |
67 changes: 67 additions & 0 deletions
67
Source/Immutable/Private/Immutable/Browser/ImmutableJSConnectorBrowserWidget.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #include "Immutable/Browser/ImmutableJSConnectorBrowserWidget.h" | ||
|
|
||
| #include "Immutable/ImtblJSConnector.h" | ||
|
|
||
| void UImmutableJSConnectorBrowserWidget::PostInitProperties() | ||
| { | ||
| Super::PostInitProperties(); | ||
|
|
||
| if (!IsTemplate()) | ||
| { | ||
| JSConnector = NewObject<UImtblJSConnector>(this); | ||
| JSConnector->ExecuteJs.BindUObject(this, &ThisClass::ExecuteJavaScript); | ||
| } | ||
| } | ||
|
|
||
| UImtblJSConnector* UImmutableJSConnectorBrowserWidget::GetJSConnector() const | ||
| { | ||
| return JSConnector; | ||
| } | ||
|
|
||
| void UImmutableJSConnectorBrowserWidget::ExecuteJavaScript(const FString& ScriptText) const | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| if (WebBrowserWidget.IsValid()) | ||
| { | ||
| WebBrowserWidget->ExecuteJavascript(ScriptText); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| bool UImmutableJSConnectorBrowserWidget::BindUObject(const FString& Name, UObject* Object, bool bIsPermanent) const | ||
| { | ||
| #if USING_BUNDLED_CEF | ||
| if (!WebBrowserWidget.IsValid() || !Object) | ||
| { | ||
| UE_LOG(LogImmutable, Warning, TEXT("Could not bind UObject '%s' to browser, WebBrowserWidget is null"), *Object->GetName()); | ||
| return false; | ||
| } | ||
|
|
||
| WebBrowserWidget->BindUObject(Name, Object, bIsPermanent); | ||
| return true; | ||
| #endif | ||
| return false; | ||
| } | ||
|
|
||
| void UImmutableJSConnectorBrowserWidget::OnBrowserCreated() | ||
| { | ||
| Super::OnBrowserCreated(); | ||
|
|
||
| SetupJavaScriptBindings(); | ||
| } | ||
|
|
||
| void UImmutableJSConnectorBrowserWidget::SetupJavaScriptBindings() | ||
| { | ||
| if (JSConnector && JSConnector->IsBound()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (JSConnector) | ||
| { | ||
| if (BindUObject(UImtblJSConnector::JSObjectName(), JSConnector)) | ||
| { | ||
| JSConnector->Init(IsPageLoaded()); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.