radames commited on
Commit
1ea3019
·
1 Parent(s): fe66ec6

toggle fullscreen input video

Browse files
frontend/.gitignore CHANGED
@@ -8,3 +8,4 @@ node_modules
8
  !.env.example
9
  vite.config.js.timestamp-*
10
  vite.config.ts.timestamp-*
 
 
8
  !.env.example
9
  vite.config.js.timestamp-*
10
  vite.config.ts.timestamp-*
11
+ public
frontend/src/lib/components/VideoInput.svelte CHANGED
@@ -10,6 +10,8 @@
10
  mediaDevices
11
  } from '$lib/mediaStream';
12
  import MediaListSwitcher from './MediaListSwitcher.svelte';
 
 
13
 
14
  export let width = 512;
15
  export let height = 512;
@@ -74,13 +76,30 @@
74
  $: if ($mediaStreamStatus == MediaStreamStatusEnum.CONNECTED && videoIsReady) {
75
  videoFrameCallbackId = videoEl.requestVideoFrameCallback(onFrameChange);
76
  }
 
 
 
 
 
 
 
 
 
 
77
  </script>
78
 
79
  <div class="relative mx-auto max-w-lg overflow-hidden rounded-lg border border-slate-300">
80
  <div class="relative z-10 flex aspect-square w-full items-center justify-center object-cover">
81
  {#if $mediaDevices.length > 0}
82
- <div class="absolute bottom-0 right-0 z-10 w-full bg-slate-400 bg-opacity-40">
83
  <MediaListSwitcher />
 
 
 
 
 
 
 
84
  </div>
85
  {/if}
86
  <video
 
10
  mediaDevices
11
  } from '$lib/mediaStream';
12
  import MediaListSwitcher from './MediaListSwitcher.svelte';
13
+ import Button from '$lib/components/Button.svelte';
14
+ import Expand from '$lib/icons/expand.svelte';
15
 
16
  export let width = 512;
17
  export let height = 512;
 
76
  $: if ($mediaStreamStatus == MediaStreamStatusEnum.CONNECTED && videoIsReady) {
77
  videoFrameCallbackId = videoEl.requestVideoFrameCallback(onFrameChange);
78
  }
79
+
80
+ function toggleFullscreen() {
81
+ if (videoIsReady) {
82
+ if (document.fullscreenElement) {
83
+ document.exitFullscreen();
84
+ } else {
85
+ videoEl.requestFullscreen();
86
+ }
87
+ }
88
+ }
89
  </script>
90
 
91
  <div class="relative mx-auto max-w-lg overflow-hidden rounded-lg border border-slate-300">
92
  <div class="relative z-10 flex aspect-square w-full items-center justify-center object-cover">
93
  {#if $mediaDevices.length > 0}
94
+ <div class="absolute bottom-0 right-0 z-10 flex bg-slate-400 bg-opacity-40">
95
  <MediaListSwitcher />
96
+ <Button
97
+ on:click={toggleFullscreen}
98
+ title={'Expand Fullscreen'}
99
+ classList={'text-sm ml-auto text-white p-1 shadow-lg rounded-lg opacity-50'}
100
+ >
101
+ <Expand classList={''} />
102
+ </Button>
103
  </div>
104
  {/if}
105
  <video
frontend/src/lib/utils.ts CHANGED
@@ -6,6 +6,10 @@ interface IImageInfo {
6
  seed?: number;
7
  guidance_scale?: number;
8
  }
 
 
 
 
9
 
10
  export function snapImage(imageEl: HTMLImageElement, info: IImageInfo) {
11
  try {
@@ -39,49 +43,56 @@ export function snapImage(imageEl: HTMLImageElement, info: IImageInfo) {
39
  }
40
  }
41
 
42
- export function expandWindow(streamURL: string): Window {
43
- const html = `
44
- <html>
45
- <head>
46
- <title>Real-Time Latent Consistency Model</title>
47
- <style>
48
- body {
49
- margin: 0;
50
- padding: 0;
51
- background-color: black;
52
- }
53
- </style>
54
- </head>
55
- <body>
56
- <script>
57
- let isFullscreen = false;
58
- window.onkeydown = function(event) {
59
- switch (event.code) {
60
- case "Escape":
61
- window.close();
62
- break;
63
- case "Enter":
64
- if (isFullscreen) {
65
- document.exitFullscreen();
66
- isFullscreen = false;
67
- } else {
68
- document.documentElement.requestFullscreen();
69
- isFullscreen = true;
70
- }
71
- break;
72
- }
73
- }
74
- </script>
75
-
76
- <img src="${streamURL}" style="width: 100%; height: 100%; object-fit: contain;" />
77
- </body>
78
- </html>
79
- `;
80
  const newWindow = window.open(
81
  '',
82
  '_blank',
83
  'width=1024,height=1024,scrollbars=0,resizable=1,toolbar=0,menubar=0,location=0,directories=0,status=0'
84
  ) as Window;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  newWindow.document.write(html);
 
 
 
 
 
 
 
 
86
  return newWindow;
87
  }
 
6
  seed?: number;
7
  guidance_scale?: number;
8
  }
9
+ export enum windowType {
10
+ image = 'image',
11
+ video = 'video'
12
+ }
13
 
14
  export function snapImage(imageEl: HTMLImageElement, info: IImageInfo) {
15
  try {
 
43
  }
44
  }
45
 
46
+ export function expandWindow(streamURL: string, type: windowType = windowType.image) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  const newWindow = window.open(
48
  '',
49
  '_blank',
50
  'width=1024,height=1024,scrollbars=0,resizable=1,toolbar=0,menubar=0,location=0,directories=0,status=0'
51
  ) as Window;
52
+
53
+ const html = `
54
+ <html>
55
+ <head>
56
+ <title>Real-Time Latent Consistency Model</title>
57
+ <style>
58
+ body {
59
+ margin: 0;
60
+ padding: 0;
61
+ background-color: black;
62
+ }
63
+ </style>
64
+ </head>
65
+ <body>
66
+ <script>
67
+ let isFullscreen = false;
68
+ window.onkeydown = function(event) {
69
+ switch (event.code) {
70
+ case "Escape":
71
+ window.close();
72
+ break;
73
+ case "Enter":
74
+ if (isFullscreen) {
75
+ document.exitFullscreen();
76
+ isFullscreen = false;
77
+ } else {
78
+ document.documentElement.requestFullscreen();
79
+ isFullscreen = true;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+ </script>
85
+ </body>
86
+ </html>
87
+ `;
88
  newWindow.document.write(html);
89
+
90
+ const img = newWindow.document.createElement('img');
91
+ img.src = streamURL;
92
+ img.style.width = '100%';
93
+ img.style.height = '100%';
94
+ img.style.objectFit = 'contain';
95
+ newWindow.document.body.appendChild(img);
96
+
97
  return newWindow;
98
  }