Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Nov 11, 2024
1 parent 3bdbf04 commit a287cf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
12 changes: 9 additions & 3 deletions web/src/lib/components/cast/cast-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import Button from '$lib/components/elements/buttons/button.svelte';
import { onMount } from 'svelte';
onMount(async () => {
await loadCastFramework();
CastPlayer.getInstance();
onMount(() => {
loadCastFramework();
});
window['__onGCastApiAvailable'] = function (isAvailable) {
// The cast sender can't be initialized until the API is available
if (isAvailable) {
CastPlayer.getInstance();
}
};
</script>

<Button size="icon" color="transparent-primary" rounded="lg" on:click>
Expand Down
23 changes: 7 additions & 16 deletions web/src/lib/utils/cast-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,10 @@ class CastPlayer {

export default CastPlayer;

export const loadCastFramework = (() => {
let promise: Promise<typeof cast> | undefined;

return async () => {
if (promise === undefined) {
promise = new Promise(() => {
const script = document.createElement('script');
script.src = FRAMEWORK_LINK;

document.body.append(script);
console.debug('Cast framework loaded');
});
}
return promise;
};
})();
export const loadCastFramework = function () {
if (!document.querySelector(`script[src="${FRAMEWORK_LINK}"]`)) {
const script = document.createElement('script');
script.src = FRAMEWORK_LINK;
document.body.append(script);
}
};

0 comments on commit a287cf9

Please sign in to comment.