From b364b7f1698a7487a873bfe37772f9ffc6d307d7 Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Fri, 23 Mar 2018 17:47:34 -0700 Subject: [PATCH] Use reticulum API to load room environment --- src/hub.js | 43 +++++++++++++++++++++------------ src/react-components/ui-root.js | 8 +++--- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/hub.js b/src/hub.js index 5e37231b0..42b991d48 100644 --- a/src/hub.js +++ b/src/hub.js @@ -87,6 +87,7 @@ AFRAME.registerInputMappings(inputConfig, true); const store = new Store(); const concurrentLoadDetector = new ConcurrentLoadDetector(); + concurrentLoadDetector.start(); // Always layer in any new default profile bits @@ -129,7 +130,7 @@ function setNameTagFromStore() { myNametag.setAttribute("text", "value", store.state.profile.display_name); } -async function enterScene(mediaStream, enterInVR) { +async function enterScene(mediaStream, enterInVR, janusRoomId) { const scene = document.querySelector("a-scene"); document.querySelector("a-scene canvas").classList.remove("blurred") scene.setAttribute("networked-scene", "adapter: janus; audio: true; debug: true; connectOnLoad: false;"); @@ -149,10 +150,7 @@ async function enterScene(mediaStream, enterInVR) { const qs = queryString.parse(location.search); - scene.setAttribute("networked-scene", { - room: qs.room && !isNaN(parseInt(qs.room)) ? parseInt(qs.room) : 1, - serverURL: process.env.JANUS_SERVER - }); + scene.setAttribute("networked-scene", { room: janusRoomId, serverURL: process.env.JANUS_SERVER }); if (!qs.stats || !/off|false|0/.test(qs.stats)) { scene.setAttribute("stats", true); @@ -216,7 +214,6 @@ function onConnect() { } function mountUI(scene) { - const qs = queryString.parse(location.search); const disableAutoExitOnConcurrentLoad = qs.allow_multi === "true" let forcedVREntryType = null; @@ -234,10 +231,7 @@ function mountUI(scene) { store }} />, document.getElementById("ui-root")); - getAvailableVREntryTypes().then(availableVREntryTypes => { - uiRoot.setState({ availableVREntryTypes }); - uiRoot.handleForcedVREntryType(); - }); + return uiRoot; } const onReady = () => { @@ -245,13 +239,32 @@ const onReady = () => { document.querySelector("a-scene canvas").classList.add("blurred"); window.APP.scene = scene; - // If ?room is set, this is `yarn start`, so just use a default environment. Otherwise use Reticulum API. - if (qs.room) { - const environmentRoot = document.querySelector("#environment-root"); + const uiRoot = mountUI(scene); + + getAvailableVREntryTypes().then(availableVREntryTypes => { + uiRoot.setState({ availableVREntryTypes }); + uiRoot.handleForcedVREntryType(); + }); + + const environmentRoot = document.querySelector("#environment-root"); + + if (!qs.room) { + const hubId = document.location.pathname.substring(1); + + const res = fetch(`/api/v1/hubs/${hubId}`).then((res) => { + return res.json(); + }).then((data) => { + const hub = data.hubs[0]; + const defaultSpaceChannel = hub.channels.find(c => c.attributes.find(a => a.length === 1 && a[0] === "default-space")); + const gltfBundleUrl = defaultSpaceChannel.assets.find(a => a.asset_type === "gltf_bundle").src; + uiRoot.setState({ janusRoomId: defaultSpaceChannel.janus_room_id }); + environmentRoot.setAttribute("gltf-bundle", `src: ${gltfBundleUrl}`) + }) + } else { + // If ?room is set, this is `yarn start`, so just use a default environment and query string room. + uiRoot.setState({ janusRoomId: qs.room && !isNaN(parseInt(qs.room)) ? parseInt(qs.room) : 1 }); environmentRoot.setAttribute("gltf-bundle", "src: /assets/environments/cliff_meeting_space/bundle.json") } - - mountUI(scene); }; document.addEventListener("DOMContentLoaded", onReady); diff --git a/src/react-components/ui-root.js b/src/react-components/ui-root.js index e2f4c2a16..7b6cbd27f 100644 --- a/src/react-components/ui-root.js +++ b/src/react-components/ui-root.js @@ -90,7 +90,9 @@ class UIRoot extends Component { sceneLoaded: false, exited: false, - showProfileEntry: false + showProfileEntry: false, + + janusRoomId: null } componentDidMount() { @@ -342,7 +344,7 @@ class UIRoot extends Component { } onAudioReadyButton = () => { - this.props.enterScene(this.state.mediaStream, this.state.enterInVR); + this.props.enterScene(this.state.mediaStream, this.state.enterInVR, this.state.janusRoomId); const mediaStream = this.state.mediaStream; @@ -361,7 +363,7 @@ class UIRoot extends Component { } render() { - if (!this.props.scene.hasLoaded || !this.state.availableVREntryTypes) { + if (!this.props.scene.hasLoaded || !this.state.availableVREntryTypes || !this.state.janusRoomId) { return ( <IntlProvider locale={lang} messages={messages}> <div className="loading-panel"> -- GitLab