From 840aed63f69ca4a709242eb9e58d96745b53db7f Mon Sep 17 00:00:00 2001 From: Rodrigo Fournier Date: Thu, 29 Jan 2026 13:21:43 +1100 Subject: [PATCH] Revert "feat: windows game bridge server" --- .../Runtime/Scripts/Private/Uwb/UwbWebView.cs | 10 +- .../ImmutableBrowserCore/GameBridge.cs | 10 -- .../ImmutableBrowserCore/GameBridgeServer.cs | 167 ------------------ .../GameBridgeServer.cs.meta | 11 -- .../WindowsWebBrowserClientAdapter.cs | 11 +- 5 files changed, 5 insertions(+), 204 deletions(-) delete mode 100644 src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs delete mode 100644 src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs.meta diff --git a/src/Packages/Passport/Runtime/Scripts/Private/Uwb/UwbWebView.cs b/src/Packages/Passport/Runtime/Scripts/Private/Uwb/UwbWebView.cs index d1f8d77d5..4307d4421 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/Uwb/UwbWebView.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/Uwb/UwbWebView.cs @@ -1,4 +1,4 @@ -#if UWB_WEBVIEW && !IMMUTABLE_CUSTOM_BROWSER && (UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)) +#if UWB_WEBVIEW && !IMMUTABLE_CUSTOM_BROWSER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)) using System; using System.IO; @@ -32,7 +32,6 @@ public class UwbWebView : MonoBehaviour, IWebBrowserClient #endif private WebBrowserClient? webBrowserClient; - private GameBridgeServer? gameBridgeServer; public async UniTask Init(int engineStartupTimeoutMs, bool redactTokensInLogs, Func redactionHandler) { @@ -67,9 +66,8 @@ public async UniTask Init(int engineStartupTimeoutMs, bool redactTokensInLogs, F var browserEngineMainDir = WebBrowserUtils.GetAdditionFilesDirectory(); browserClient.CachePath = new FileInfo(Path.Combine(browserEngineMainDir, "ImmutableSDK/UWBCache")); - // Start local HTTP server to serve index.html - gameBridgeServer = new GameBridgeServer(GameBridge.GetFileSystemPath()); - browserClient.initialUrl = gameBridgeServer.Start(); + // Game bridge path + browserClient.initialUrl = GameBridge.GetFilePath(); // Set up engine from standard UWB configuration asset var engineConfigAsset = Resources.Load("Cef Engine Configuration"); @@ -147,8 +145,6 @@ public void Dispose() if (webBrowserClient?.HasDisposed == true) return; webBrowserClient?.Dispose(); - gameBridgeServer?.Dispose(); - gameBridgeServer = null; } #endif } diff --git a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridge.cs b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridge.cs index 3fd11fab6..3e948812c 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridge.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridge.cs @@ -41,15 +41,5 @@ public static string GetFilePath() filePath = filePath.Replace(" ", "%20"); return filePath; } - - /// - /// Gets the file system path to index.html (without file:// scheme or URL encoding). - /// - public static string GetFileSystemPath() - { - return GetFilePath() - .Replace(SCHEME_FILE, "") - .Replace("%20", " "); - } } } \ No newline at end of file diff --git a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs deleted file mode 100644 index e0bb53c6b..000000000 --- a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs +++ /dev/null @@ -1,167 +0,0 @@ -#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) - -using System; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using UnityEngine; - -namespace Immutable.Browser.Core -{ - /// - /// Local HTTP server for index.html to provide a proper origin instead of null from file:// URLs. - /// - public class GameBridgeServer : IDisposable - { - private const string TAG = "[Game Bridge Server]"; - - // Fixed port to maintain consistent origin for localStorage/IndexedDB persistence - private const int PORT = 51990; - private static readonly string URL = "http://localhost:" + PORT + "/"; - - private HttpListener? _listener; - private Thread? _listenerThread; - private byte[]? _indexHtmlContent; - private readonly CancellationTokenSource _cts = new CancellationTokenSource(); - private bool _disposed; - - /// - /// Creates a new GameBridgeServer instance. - /// - /// The file system path to the index.html file. - public GameBridgeServer(string indexHtmlPath) - { - if (string.IsNullOrEmpty(indexHtmlPath)) - throw new ArgumentNullException(nameof(indexHtmlPath)); - - if (!File.Exists(indexHtmlPath)) - throw new FileNotFoundException($"{TAG} index.html not found: {indexHtmlPath}"); - - _indexHtmlContent = File.ReadAllBytes(indexHtmlPath); - Debug.Log($"{TAG} Loaded index.html ({_indexHtmlContent.Length} bytes)"); - } - - /// - /// Starts the game bridge server. - /// - /// The URL to the index.html file. - public string Start() - { - if (_disposed) - throw new ObjectDisposedException(nameof(GameBridgeServer)); - - if (_listener?.IsListening == true) - return URL; - - EnsurePortAvailable(); - - _listener = new HttpListener(); - _listener.Prefixes.Add(URL); - _listener.Start(); - - Debug.Log($"{TAG} Started on {URL}"); - - _listenerThread = new Thread(ListenerLoop) - { - Name = "GameBridgeServer", - IsBackground = true - }; - _listenerThread.Start(); - - return URL; - } - - private void ListenerLoop() - { - while (!_cts.Token.IsCancellationRequested && _listener?.IsListening == true) - { - try - { - var context = _listener.GetContext(); - HandleRequest(context); - } - catch (HttpListenerException) when (_cts.Token.IsCancellationRequested) - { - break; - } - catch (ObjectDisposedException) - { - break; - } - catch (Exception ex) - { - if (!_cts.Token.IsCancellationRequested) - Debug.LogError($"{TAG} Error: {ex.Message}"); - } - } - } - - private void HandleRequest(HttpListenerContext context) - { - var response = context.Response; - try - { - response.StatusCode = 200; - response.ContentType = "text/html; charset=utf-8"; - response.ContentLength64 = _indexHtmlContent!.Length; - response.OutputStream.Write(_indexHtmlContent, 0, _indexHtmlContent.Length); - } - catch (Exception ex) - { - Debug.LogError($"{TAG} Error handling request: {ex.Message}"); - } - finally - { - try { response.Close(); } catch { } - } - } - - private void EnsurePortAvailable() - { - if (!IsPortAvailable(PORT)) - { - throw new InvalidOperationException( - $"{TAG} Port {PORT} is already in use. " + - "Please close any application using this port to ensure localStorage/IndexedDB data persists correctly."); - } - } - - private bool IsPortAvailable(int port) - { - try - { - var listener = new TcpListener(IPAddress.Loopback, port); - listener.Start(); - listener.Stop(); - return true; - } - catch - { - return false; - } - } - - public void Dispose() - { - if (_disposed) return; - _disposed = true; - - _cts.Cancel(); - try - { - _listener?.Stop(); - _listener?.Close(); - } - catch { } - - _listenerThread?.Join(TimeSpan.FromSeconds(1)); - _cts.Dispose(); - _indexHtmlContent = null; - - Debug.Log($"{TAG} Stopped"); - } - } -} - -#endif diff --git a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs.meta b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs.meta deleted file mode 100644 index eaf5251c1..000000000 --- a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ab2317c6b7a6cea4391c77dae3a5deb7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClientAdapter.cs b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClientAdapter.cs index 5501b0572..efa949343 100644 --- a/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClientAdapter.cs +++ b/src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClientAdapter.cs @@ -1,9 +1,8 @@ #if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) -using System.Net.Sockets; +using System.IO; using UnityEngine; using Immutable.Browser.Core; -using Immutable.Passport; using Immutable.Passport.Core.Logging; using Cysharp.Threading.Tasks; @@ -14,7 +13,6 @@ public class WindowsWebBrowserClientAdapter : IWebBrowserClient public event OnUnityPostMessageDelegate OnUnityPostMessage; private readonly IWindowsWebBrowserClient webBrowserClient; - private GameBridgeServer? gameBridgeServer; public WindowsWebBrowserClientAdapter(IWindowsWebBrowserClient windowsWebBrowserClient) { @@ -35,11 +33,8 @@ public async UniTask Init() // Initialise the web browser client asynchronously await webBrowserClient.Init(); - // Start local HTTP server to serve index.html - gameBridgeServer = new GameBridgeServer(GameBridge.GetFileSystemPath()); - // Load the game bridge file into the web browser client - webBrowserClient.LoadUrl(gameBridgeServer.Start()); + webBrowserClient.LoadUrl(GameBridge.GetFilePath()); // Get the JavaScript API call for posting messages from the web page to the Unity application string postMessageApiCall = webBrowserClient.GetPostMessageApiCall(); @@ -64,8 +59,6 @@ public void LaunchAuthURL(string url, string? redirectUri) public void Dispose() { webBrowserClient.Dispose(); - gameBridgeServer?.Dispose(); - gameBridgeServer = null; } } }