Skip to content

Commit

Permalink
Merge pull request #18 from Carifio24/serve-ngrok
Browse files Browse the repository at this point in the history
Allow using ngrok for QR code sharing
  • Loading branch information
Carifio24 authored Jan 5, 2024
2 parents 06abeb0 + 4ed0535 commit 2005310
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion glue_ar/qr_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ def __init__(self, parent=None, img=None):
self.pix = QPixmap.fromImage(self.img)
self.ui = load_ui("qr_dialog.ui", self, directory=dirname(__file__))
self.ui.label_image.setPixmap(self.pix)
self.setFixedSize(300, 325)
width, height = img.size
self.setFixedSize(width, height + 25)
14 changes: 12 additions & 2 deletions glue_ar/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from glue_vispy_viewers.scatter.scatter_viewer import Vispy3DScatterViewerState
from glue_vispy_viewers.volume.layer_state import VolumeLayerState

import ngrok
import pyvista as pv

from qtpy import compat
Expand Down Expand Up @@ -119,19 +120,28 @@ def activate(self):
_, gltf_base = split(gltf_tmp.name)
export_modelviewer(html_tmp.name, gltf_base, self.viewer.state.title)


port = 4000
directory, filename = split(html_tmp.name)
server = run_ar_server(port, directory)
use_ngrok = os.getenv("NGROK_AUTHTOKEN", None) is not None

try:
thread = Thread(target=server.serve_forever)
thread.start()

ip = get_local_ip()
url = f"http://{ip}:{port}/{filename}"
if use_ngrok:
listener = ngrok.forward(port, authtoken_from_env=True)
url = f"{listener.url()}/{filename}"
else:
ip = get_local_ip()
url = f"http://{ip}:{port}/{filename}"
img = create_qr(url)
dialog = QRDialog(parent=self.viewer, img=img)
dialog.exec_()

finally:
server.shutdown()
if use_ngrok:
listener.close()

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ gltflib
glue-core
glue-qt
glue-vispy-viewers
ngrok
pillow
pyvista
segno
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install_requires =
glue-core
glue-qt
glue-vispy-viewers
ngrok
pillow
pyvista
segno
Expand Down

0 comments on commit 2005310

Please sign in to comment.