Skip to content

Commit

Permalink
fix(Xbox): Support screen resolution detection on Xbox when using Web…
Browse files Browse the repository at this point in the history
…View2 (#7144)

Resolves #7141
  • Loading branch information
massicottem authored and avelad committed Aug 19, 2024
1 parent 1694f8a commit afdf7c6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Martin Stark <[email protected]>
Mariano Facundo Scigliano <[email protected]>
Matias Russitto <[email protected]>
Mathieu Côté <[email protected]>
Mathieu Massicotte <[email protected]>
Matthias Van Parijs <[email protected]>
Mattias Wadman <[email protected]>
Mehmet Guney <[email protected]>
Expand Down
18 changes: 18 additions & 0 deletions docs/tutorials/screen-resolution-detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ Note: in order to use this feature in a UWP app, you must add the URI of your
web app in the ContentURIs section of the Package.appxmanifest file and set
the `WinRT access` field to `All`.

### WebView2

When using a WebView2 control in a UWP app, additional steps are required in
order to enable the screen resolution detection. First, the WebView2's user-agent
is the same as Edge Chromium and does not contain the term "Xbox One", so it has
to be manually added like this when initializing your WebView2:

```CSharp
webView.CoreWebView2.Settings.UserAgent += " Xbox One";
```

Also, you will need to add a special project called WinRTAdapter in your project's
solution. This project allows WinRT APIs to be exposed in the WebView2 control.
You will find more information on this [here](https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js).
Make sure you put `Windows.Media.Protection.ProtectionCapabilities`
and `Windows.Media.Protection.ProtectionCapabilityResult` in the WinRTAdapter
_Include filters_ configuration.

## Hisense

We can detect if the device supports 3840x2160 (4K).
Expand Down
20 changes: 20 additions & 0 deletions externs/xbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ Windows.Media.Protection.ProtectionCapabilityResult = {
maybe: 'Maybe',
probably: 'Probably',
};


/** @const */
var chrome = {};


/** @const */
chrome.webview = {};


/** @const */
chrome.webview.hostObjects = {};


/** @const */
chrome.webview.hostObjects.sync = {};


/** @const */
chrome.webview.hostObjects.sync.Windows = Windows;
15 changes: 13 additions & 2 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,21 @@ shaka.util.Platform = class {
maxResolution.width = 1920;
maxResolution.height = 1080;
try {
let winRT = undefined;

// Try to access to WinRT for WebView, if it's not defined,
// try to access to WinRT for WebView2, if it's not defined either,
// let it throw.
if (typeof Windows !== 'undefined') {
winRT = Windows;
} else {
winRT = chrome.webview.hostObjects.sync.Windows;
}

const protectionCapabilities =
new Windows.Media.Protection.ProtectionCapabilities();
new winRT.Media.Protection.ProtectionCapabilities();
const protectionResult =
Windows.Media.Protection.ProtectionCapabilityResult;
winRT.Media.Protection.ProtectionCapabilityResult;
// isTypeSupported may return "maybe", which means the operation is not
// completed. This means we need to retry
// https://learn.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilityresult?view=winrt-22621
Expand Down

0 comments on commit afdf7c6

Please sign in to comment.