Skip to content

Commit

Permalink
Fix local room with scene creation
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 15, 2023
1 parent 63798b1 commit 3d0a6df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions addons/io_hubs_addon/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ def draw(self, context):


class HubsCreateSceneOperator(bpy.types.Operator):
bl_idname = "hubs_scene.create_scene"
bl_label = "Create Room"
bl_idname = "hubs_scene.create_room_with_scene"
bl_label = "Create Room With Scene"
bl_description = "Create a room with the selected scene"
bl_options = {'REGISTER', 'UNDO'}

Expand Down Expand Up @@ -705,7 +705,16 @@ def execute(self, context):

was_alive = hubs_session.init(context)

hubs_session.load(f'{response["url"]}?new&{hubs_session.url_params_string_from_prefs(context)}')
params = hubs_session.url_params_string_from_prefs(context)
if hubs_session.is_local_instance():
from urllib.parse import urlparse
parsed = urlparse(hubs_session.client_url)
port = str(parsed.port)
url = f'{parsed.scheme}://{parsed.hostname}{":"+port if port else ""}/hub.html?hub_id={response["hub_id"]}&{params}'
else:
url = f'{response["url"]}?{params}'

hubs_session.load(url)

if was_alive:
hubs_session.bring_to_front(context)
Expand Down Expand Up @@ -1020,7 +1029,6 @@ def load_post(dummy):
@persistent
def update_session():
if hubs_session.is_alive():
print("XXX")
hubs_session.update_session_state()

return 2.0
Expand Down
10 changes: 10 additions & 0 deletions addons/io_hubs_addon/hubs_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HubsSession:
_room_name = ""
_room_params = {}
_reticulum_url = ""
_client_url = ""

def init(self, context):
browser = get_addon_pref(context).browser
Expand Down Expand Up @@ -143,6 +144,8 @@ def update_session_state(self):
params = parse_qs(parsed.query, keep_blank_values=True)
self._room_params = {k: v for k, v in params.items() if k != "hub_id"}

self._client_url = f'{parsed.scheme}://{parsed.hostname}:{parsed.port}'

params = self._web_driver.execute_script(JS_STATE_UPDATE)
self._user_logged_in = params["signedIn"]
self._user_in_room = params["entered"]
Expand Down Expand Up @@ -283,6 +286,9 @@ def set_creator_assignment_token(self, hub_id, creator_token, embed_token):
def load(self, url):
self._web_driver.get(url)

def is_local_instance(self):
return "hub_id" in self._web_driver.current_url

@property
def user_logged_in(self):
return self._user_logged_in
Expand All @@ -302,3 +308,7 @@ def room_params(self):
@property
def reticulum_url(self):
return self._reticulum_url

@property
def client_url(self):
return self._client_url

0 comments on commit 3d0a6df

Please sign in to comment.