-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
App.tsx
79 lines (68 loc) · 2.26 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useRef, useState } from 'react';
import './App.css';
import { VncScreen } from './lib';
function App() {
const [vncUrl, setVncUrl] = useState('');
const [inputUrl, setInputUrl] = useState('');
const vncScreenRef = useRef<React.ElementRef<typeof VncScreen>>(null);
const isValid = (vncUrl: string) => {
if (!vncUrl.startsWith('ws://') && !vncUrl.startsWith('wss://')) {
return false;
}
return true;
};
const Spacer = () => <div style={{ width: '2rem', display: 'inline-block' }} />;
return (
<>
<div style={{ margin: '1rem' }}>
<label htmlFor="url">URL for VNC Stream</label>
<Spacer />
<input type="text" onChange={({ target: { value } }) => {
setInputUrl(value);
}} name="url" placeholder="wss://your-vnc-url" />
<Spacer />
<button onClick={() => setVncUrl(inputUrl)}>Go!</button>
</div>
<div style={{ opacity: 0.5, margin: '1rem' }}>
Since the site is loaded over HTTPS, only `wss://` URLs (SSL encrypted websockets URLs) are supported.
<br />
To test a `ws://` URL, clone the application and run it on http://localhost:3000, or <a href="https://experienceleague.adobe.com/docs/target/using/experiences/vec/troubleshoot-composer/mixed-content.html?lang=en#task_5448763B8DC941FD80F84041AEF0A14D">enable Mixed Content on your browser</a>.
</div>
<div style={{ margin: '1rem' }}>
<button
onClick={() => {
const { connect, connected, disconnect } = vncScreenRef.current ?? {};
if (connected) {
disconnect?.();
return;
}
connect?.();
}}
>
Connect / Disconnect
</button>
</div>
<div style={{ margin: '1rem' }}>
{
isValid(vncUrl)
?
(
<VncScreen
url={vncUrl}
scaleViewport
background="#000000"
style={{
width: '75vw',
height: '75vh',
}}
debug
ref={vncScreenRef}
/>
)
: <div>VNC URL not provided.</div>
}
</div>
</>
);
}
export default App;