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 9dbf075
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
11 changes: 8 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,15 @@
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) {
if (isAvailable) {
CastPlayer.getInstance();
}
};
</script>

<Button size="icon" color="transparent-primary" rounded="lg" on:click>
Expand Down
24 changes: 8 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,11 @@ 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);
console.debug('Loaded cast framework');
}
};

0 comments on commit 9dbf075

Please sign in to comment.