Skip to content

Commit

Permalink
fix #38
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jan 23, 2025
1 parent 3727321 commit 7721946
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/vm/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Docker extends VMManager {
`
#!/bin/bash
set -e
PORT=$(comm -23 <(seq 5000 5063 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
PORT=$(comm -23 <(seq 5000 5063 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | head -n 1)
INDEX=$(($PORT - 5000))
UDP_START=$((59000+$INDEX*100))
UDP_END=$((59099+$INDEX*100))
Expand Down
24 changes: 13 additions & 11 deletions server/vm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ function createVMManager(poolConfig: PoolConfig): VMManager {
}

export function getVMManagerConfig(): PoolConfig[] {
return config.VM_MANAGER_CONFIG.split(',').map((c) => {
const split = c.split(':');
return {
provider: split[0],
isLarge: split[1] === 'large',
region: split[2] as PoolRegion,
minSize: Number(split[3]),
limitSize: Number(split[4]),
hostname: split[5],
};
});
return config.VM_MANAGER_CONFIG.split(',')
.filter(Boolean)
.map((c) => {
const split = c.split(':');
return {
provider: split[0],
isLarge: split[1] === 'large',
region: split[2] as PoolRegion,
minSize: Number(split[3]),
limitSize: Number(split[4]),
hostname: split[5],
};
});
}

export function getBgVMManagers(): { [key: string]: VMManager } {
Expand Down
2 changes: 1 addition & 1 deletion server/vmWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ app.get('/isFreePoolFull', async (req, res) => {
return isFull;
}),
);
const isFull = fullResult.every(Boolean);
const isFull = freePools.length && fullResult.every(Boolean);
res.json({ isFull });
});

Expand Down
19 changes: 19 additions & 0 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,25 @@ export default class App extends React.Component<AppProps, AppState> {
]}
></Dropdown>
)}
{this.playingVBrowser() &&
isMobile() &&
this.state.controller === this.socket.id && (
<Button
fluid
className="toolButton"
icon
labelPosition="left"
color="blue"
disabled={!this.haveLock()}
onClick={() => {
const dummy = document.getElementById('dummy');
dummy?.focus();
}}
>
<Icon name="keyboard" />
Keyboard
</Button>
)}
{this.playingVBrowser() && (
<Button
fluid
Expand Down
75 changes: 75 additions & 0 deletions src/components/VBrowser/VBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class VBrowser extends React.Component<{
setQuality: (quality: string) => void;
doPlay: () => Promise<void>;
}> {
state = { dummyValue: '' };
// private observer = new ResizeObserver(this.onResize);
private keyboard = GuacamoleKeyboard();
private focused = false;
Expand Down Expand Up @@ -374,6 +375,80 @@ export default class VBrowser extends React.Component<{
style={{ width: '100%' }}
/>
<audio id="iPhoneAudio" />
<input
type="text"
id="dummy"
value={this.state.dummyValue}
style={{
position: 'absolute',
left: 0,
top: 0,
height: 0,
opacity: 0,
}}
onFocus={() => {
this.focused = true;
this.setState({ dummyValue: '' });
}}
onBlur={() => {
this.focused = false;
this.setState({ dummyValue: '' });
}}
onKeyDown={(e) => {
if (e.keyCode !== 229) {
document
.getElementById('leftOverlay')
?.dispatchEvent(new KeyboardEvent('keydown', { key: e.key }));
}
}}
onKeyUp={(e) => {
if (e.keyCode !== 229) {
document
.getElementById('leftOverlay')
?.dispatchEvent(new KeyboardEvent('keyup', { key: e.key }));
}
}}
onChange={(e) => {
const oldVal = this.state.dummyValue;
const newVal = e.target.value;
if (newVal.length > oldVal.length) {
//keyup/keydown don't work on Chrome mobile for alphanumeric chars
// see https://stackoverflow.com/questions/36753548/keycode-on-android-is-always-229
// grab the last value out of the textfield instead and send that event
document
.getElementById('leftOverlay')
?.dispatchEvent(
new KeyboardEvent('keydown', {
key: newVal.slice(-1).toLowerCase(),
}),
);
document
.getElementById('leftOverlay')
?.dispatchEvent(
new KeyboardEvent('keyup', {
key: newVal.slice(-1).toLowerCase(),
}),
);
// this.$client.sendData('keydown', { key: newVal.slice(-1).charCodeAt(0) });
// this.$client.sendData('keyup', { key: newVal.slice(-1).charCodeAt(0) });
} else {
document
.getElementById('leftOverlay')
?.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Backspace' }),
);
document
.getElementById('leftOverlay')
?.dispatchEvent(
new KeyboardEvent('keyup', { key: 'Backspace' }),
);
// Backspace is 65288?
// this.$client.sendData('keydown', { key: 65288 });
// this.$client.sendData('keyup', { key: 65288 });
}
this.setState({ dummyValue: newVal });
}}
/>
<div
ref={this._overlay}
id={'leftOverlay'}
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export default {
cert: fs.readFileSync(process.env.SSL_CRT_FILE),
}
: null,
allowedHosts: true,
},
};

0 comments on commit 7721946

Please sign in to comment.