2022-06-04 18:34:11 -05:00
|
|
|
<script lang="ts">
|
|
|
|
import { session } from '$app/stores';
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
import LoadingSpinner from '../shared/loading-spinner.svelte';
|
2022-07-10 21:41:45 -05:00
|
|
|
import { api, AssetResponseDto } from '@api';
|
2022-06-04 18:34:11 -05:00
|
|
|
|
|
|
|
export let assetId: string;
|
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
let asset: AssetResponseDto;
|
2022-06-04 18:34:11 -05:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
let videoPlayerNode: HTMLVideoElement;
|
|
|
|
let isVideoLoading = true;
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if ($session.user) {
|
2022-07-10 21:41:45 -05:00
|
|
|
const { data: assetInfo } = await api.assetApi.getAssetById(assetId);
|
|
|
|
|
|
|
|
asset = assetInfo;
|
2022-06-04 18:34:11 -05:00
|
|
|
|
|
|
|
await loadVideoData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const loadVideoData = async () => {
|
|
|
|
isVideoLoading = true;
|
2022-07-10 21:41:45 -05:00
|
|
|
|
2022-06-04 18:34:11 -05:00
|
|
|
if ($session.user) {
|
|
|
|
try {
|
2022-07-10 21:41:45 -05:00
|
|
|
const { data } = await api.assetApi.serveFile(asset.deviceAssetId, asset.deviceId, false, true, {
|
|
|
|
responseType: 'blob',
|
2022-06-04 18:34:11 -05:00
|
|
|
});
|
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
if (!(data instanceof Blob)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const videoData = URL.createObjectURL(data);
|
2022-06-04 18:34:11 -05:00
|
|
|
videoPlayerNode.src = videoData;
|
|
|
|
|
|
|
|
videoPlayerNode.load();
|
|
|
|
|
|
|
|
videoPlayerNode.oncanplay = () => {
|
|
|
|
videoPlayerNode.muted = true;
|
|
|
|
videoPlayerNode.play();
|
|
|
|
videoPlayerNode.muted = false;
|
|
|
|
|
|
|
|
isVideoLoading = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
return videoData;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div transition:fade={{ duration: 150 }} class="flex place-items-center place-content-center h-full select-none">
|
|
|
|
{#if asset}
|
|
|
|
<video controls class="h-full object-contain" bind:this={videoPlayerNode}>
|
|
|
|
<track kind="captions" />
|
|
|
|
</video>
|
|
|
|
|
|
|
|
{#if isVideoLoading}
|
2022-06-11 16:12:06 -05:00
|
|
|
<div class="absolute flex place-items-center place-content-center">
|
2022-06-04 18:34:11 -05:00
|
|
|
<LoadingSpinner />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
</div>
|