Skip to content

Commit

Permalink
Merge pull request jupyterhub#104 from consideRatio/pr/small-refactor
Browse files Browse the repository at this point in the history
refactor: a few smaller details
  • Loading branch information
consideRatio authored Mar 30, 2024
2 parents bc39ad7 + 7797912 commit 203e123
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions jupyter_remote_desktop_proxy/setup_websockify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@


def setup_websockify():
# make a secure temporary directory for sockets
# This is only readable, writeable & searchable by our uid
sockets_dir = tempfile.mkdtemp()
sockets_path = os.path.join(sockets_dir, 'vnc-socket')
vncserver = which('vncserver')

if not vncserver:
raise RuntimeError(
"vncserver executable not found, please install a VNC server"
)

# TigerVNC provides the option to connect a Unix socket. TurboVNC does not.
# TurboVNC and TigerVNC share the same origin and both use a Perl script
# as the executable vncserver. We can determine if vncserver is TigerVNC
# by searching tigervnc string in the Perl script.
Expand All @@ -34,11 +28,17 @@ def setup_websockify():
is_tigervnc = "tigervnc" in vncserver_file.read().casefold()

if is_tigervnc:
# Make a secure temporary directory for sockets that is only readable,
# writeable, and searchable by our uid - TigerVNC can listen to a Unix
# socket!
sockets_dir = tempfile.mkdtemp()
sockets_path = os.path.join(sockets_dir, 'vnc-socket')

websockify_args = ['--unix-target', sockets_path]
vnc_args = [vncserver, '-rfbunixpath', sockets_path]
socket_args = ['--unix-target', sockets_path]
else:
vnc_args = [vncserver, '-rfbport', '{port}']
socket_args = []
websockify_args = []
vnc_args = [vncserver, '-localhost', '-rfbport', '{port}']

if not os.path.exists(os.path.expanduser('~/.vnc/xstartup')):
vnc_args.extend(['-xstartup', os.path.join(HERE, 'share/xstartup')])
Expand All @@ -47,23 +47,22 @@ def setup_websockify():
vnc_args
+ [
'-verbose',
'-fg',
'-geometry',
'1680x1050',
'-SecurityTypes',
'None',
'-fg',
]
)

return {
'command': [
'websockify',
'-v',
'--heartbeat',
'30',
'--verbose',
'--heartbeat=30',
'{port}',
]
+ socket_args
+ websockify_args
+ ['--', '/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'],
'timeout': 30,
'new_browser_window': True,
Expand Down

0 comments on commit 203e123

Please sign in to comment.