Skip to content
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

feat(chromecast)!: Fork receiver app v1 #94

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions backends/chromecast/receiver-v1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!DOCTYPE html>
<!--
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html>
<head>
<title>Chromecast WebDriver Receiver v1</title>
<!--

This is an archived version of the receiver from v1 releases.
In v2, we break compatibility and register a new default app ID that has new
capabilities.

This version only took a URL as a parameter, and could only host content in an
iframe. It is registered to receiver app ID B602D163, the v1 default app ID.

-->
<script src="https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>
<style>

html, body, iframe {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
background: white;
}

iframe {
border: none;
}

</style>
<script>

// Expose cast.__platform__ asynchronously through postMessage.
// Cannot be used to proxy synchronous calls, but could be used for debugging
// or with an async shim and `await` on all calls from the client.
window.addEventListener('message', (event) => {
const data = event.data;
console.log('Top window received message:', data);

if (data.type == 'cast.__platform__') {
const platform = cast.__platform__;
const command = platform[data.command];

const args = data.args;
try {
const result = command.apply(platform, args);

const message = {
id: data.id,
type: data.type + ':result',
result: result,
};

console.log('Top window sending result:', message);
event.source.postMessage(message, '*');
} catch (error) {
console.log('Failed:', error);

const message = {
id: data.id,
type: data.type + ':error',
error: error.message,
};

console.log('Top window sending error:', message);
event.source.postMessage(message, '*');
}
}
});

window.addEventListener('DOMContentLoaded', () => {
// Ignore the leading '?'. The rest is the URL.
const frameUrl = (location.search + location.hash).substr(1);

const statusText = 'URL: ' + frameUrl;

const context = cast.framework.CastReceiverContext.getInstance();
context.start({
statusText,
disableIdleTimeout: true,
});

// Some features must be explicitly allowed for an iframe.
// These are needed for media-related testing.
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
const allowedFeatures = [
'autoplay',
'encrypted-media',
'fullscreen',
'picture-in-picture',
'sync-xhr',
];

window.frame.allow = allowedFeatures.join('; ');
window.frame.src = frameUrl;
});

</script>
</head>
<body>
<iframe id="frame"></iframe>
</body>
</html>
Loading