|
3 | 3 | #include "HTTP/Curl/CurlProvider.h" |
4 | 4 | #include "HTTP/WinHttp/winhttp_provider.h" |
5 | 5 |
|
| 6 | +#if HC_PLATFORM == HC_PLATFORM_GDK |
| 7 | +#include "XSystem.h" |
| 8 | +#endif |
| 9 | + |
6 | 10 | NAMESPACE_XBOX_HTTP_CLIENT_BEGIN |
7 | 11 |
|
| 12 | +// Helper function to detect if running on Xbox console hardware |
| 13 | +static bool IsRunningOnXboxConsole() |
| 14 | +{ |
| 15 | +#if HC_PLATFORM == HC_PLATFORM_GDK |
| 16 | + auto deviceType = XSystemGetDeviceType(); |
| 17 | + // Explicitly list all Xbox console device types |
| 18 | + return deviceType == XSystemDeviceType::XboxOne || |
| 19 | + deviceType == XSystemDeviceType::XboxOneS || |
| 20 | + deviceType == XSystemDeviceType::XboxOneX || |
| 21 | + deviceType == XSystemDeviceType::XboxScarlettLockhart || // Xbox Series S |
| 22 | + deviceType == XSystemDeviceType::XboxScarlettAnaconda; // Xbox Series X |
| 23 | +#else |
| 24 | + return false; |
| 25 | +#endif |
| 26 | +} |
| 27 | + |
8 | 28 | HRESULT PlatformInitialize(PlatformComponents& components, HCInitArgs* initArgs) |
9 | 29 | { |
10 | 30 | // We don't expect initArgs on GDK |
11 | 31 | RETURN_HR_IF(E_INVALIDARG, initArgs); |
12 | 32 |
|
13 | | - // XCurl will be used for HTTP |
14 | | - auto initXCurlResult = CurlProvider::Initialize(); |
15 | | - RETURN_IF_FAILED(initXCurlResult.hr); |
| 33 | + // Detect runtime platform to choose appropriate HTTP provider |
| 34 | + if (IsRunningOnXboxConsole()) |
| 35 | + { |
| 36 | + HC_TRACE_INFORMATION(HTTPCLIENT, "PlatformInitialize: Detected Xbox console, using XCurl for HTTP"); |
| 37 | + |
| 38 | + // Use XCurl for Xbox console with full PLM support |
| 39 | + auto initXCurlResult = CurlProvider::Initialize(); |
| 40 | + RETURN_IF_FAILED(initXCurlResult.hr); |
16 | 41 |
|
17 | | - components.HttpProvider = initXCurlResult.ExtractPayload(); |
| 42 | + components.HttpProvider = initXCurlResult.ExtractPayload(); |
18 | 43 |
|
19 | 44 | #ifndef HC_NOWEBSOCKETS |
20 | | - // WinHttp will be used for WebSockets |
21 | | - auto initWinHttpResult = WinHttpProvider::Initialize(); |
22 | | - RETURN_IF_FAILED(initWinHttpResult.hr); |
| 45 | + // For Xbox consoles with XCurl HTTP, still use WinHttp for WebSockets |
| 46 | + auto initWinHttpResult = WinHttpProvider::Initialize(); |
| 47 | + RETURN_IF_FAILED(initWinHttpResult.hr); |
23 | 48 |
|
24 | | - auto winHttpProvider = initWinHttpResult.ExtractPayload(); |
25 | | - components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} }); |
| 49 | + auto winHttpProvider = initWinHttpResult.ExtractPayload(); |
| 50 | + components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} }); |
| 51 | +#endif |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + HC_TRACE_INFORMATION(HTTPCLIENT, "PlatformInitialize: Detected non-console platform (e.g., Steam Deck), using WinHTTP for HTTP"); |
| 56 | + |
| 57 | + // Use WinHTTP for Steam Deck and other non-console platforms |
| 58 | + auto initWinHttpResult = WinHttpProvider::Initialize(); |
| 59 | + RETURN_IF_FAILED(initWinHttpResult.hr); |
| 60 | + |
| 61 | + auto winHttpProvider = initWinHttpResult.ExtractPayload(); |
| 62 | + |
| 63 | + // Use the same WinHttpProvider instance for both HTTP and WebSocket |
| 64 | + auto sharedWinHttpProvider = SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} }; |
| 65 | + |
| 66 | + components.HttpProvider = http_allocate_unique<WinHttp_HttpProvider>(sharedWinHttpProvider); |
| 67 | + |
| 68 | +#ifndef HC_NOWEBSOCKETS |
| 69 | + components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(sharedWinHttpProvider); |
26 | 70 | #endif |
| 71 | + } |
27 | 72 |
|
28 | 73 | return S_OK; |
29 | 74 | } |
30 | 75 |
|
31 | 76 | // Test hooks for GDK Suspend/Resume testing |
| 77 | +// Note: These hooks assume WinHttp WebSocket provider is available. |
| 78 | +// They will work correctly on both Xbox consoles and non-console platforms |
| 79 | +// since both configurations use WinHttp for WebSockets. |
32 | 80 | STDAPI_(void) HCWinHttpSuspend() |
33 | 81 | { |
34 | 82 | auto httpSingleton = get_http_singleton(); |
|
0 commit comments