From 536354f5ed3748cc8af7c7ad52f47026d6f1c19a Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Tue, 14 Nov 2017 17:07:40 -0800 Subject: [PATCH] Cleanup from PR notes --- public/room.html | 4 ++-- src/index.js | 62 ++++++++++++++++++++++++++---------------------- src/lobby.js | 2 +- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/public/room.html b/public/room.html index 3f722f831..a8c44617f 100644 --- a/public/room.html +++ b/public/room.html @@ -25,7 +25,7 @@ networked-scene="adapter: janus; audio: true; debug: true; - onConnect: onConnect; + onConnect: App.onConnect; connectOnLoad: false;" mute-mic="eventSrc: a-scene; toggleEvents: action_mute"> @@ -89,7 +89,7 @@ </a-entity> </a-scene> <script> - document.querySelector('a-scene').addEventListener('loaded', onSceneLoad) + document.querySelector('a-scene').addEventListener('loaded', App.onSceneLoad) </script> </body> diff --git a/src/index.js b/src/index.js index 9485e8251..9cc589523 100644 --- a/src/index.js +++ b/src/index.js @@ -26,37 +26,41 @@ import Config from "./config"; registerNetworkScheams(); registerInputMappings(); -window.onSceneLoad = function() { - const qs = queryString.parse(location.search); - const scene = document.querySelector("a-scene"); - - scene.setAttribute("networked-scene", { - room: - qs.room && !isNaN(parseInt(qs.room)) - ? parseInt(qs.room) - : Config.default_room, - serverURL: Config.janus_server_url - }); - - if (!qs.stats || !/off|false|0/.test(qs.stats)) { - scene.setAttribute("stats", true); - } +window.App = { + onSceneLoad() { + const qs = queryString.parse(location.search); + const scene = document.querySelector("a-scene"); - if (AFRAME.utils.device.isMobile() || qs.gamepad) { - const playerRig = document.querySelector("#player-rig"); - playerRig.setAttribute("virtual-gamepad-controls", {}); - } + scene.setAttribute("networked-scene", { + room: + qs.room && !isNaN(parseInt(qs.room)) + ? parseInt(qs.room) + : Config.default_room, + serverURL: Config.janus_server_url + }); - let username = qs.name; - if (!username) { - username = promptForName(username); // promptForName is blocking - } - const myNametag = document.querySelector("#player-rig .nametag"); - myNametag.setAttribute("text", "value", username); + if (!qs.stats || !/off|false|0/.test(qs.stats)) { + scene.setAttribute("stats", true); + } - scene.components["networked-scene"].connect(); -}; + if (AFRAME.utils.device.isMobile() || qs.gamepad) { + const playerRig = document.querySelector("#player-rig"); + playerRig.setAttribute("virtual-gamepad-controls", {}); + } -window.onConnect = function() { - document.getElementById("loader").style.display = "none"; + let username = qs.name; + if (!username) { + username = promptForName(username); // promptForName is blocking + } + const myNametag = document.querySelector("#player-rig .nametag"); + myNametag.setAttribute("text", "value", username); + + document.body.addEventListener("connected", App.onConnect); + + scene.components["networked-scene"].connect(); + }, + + onConnect() { + document.getElementById("loader").style.display = "none"; + } }; diff --git a/src/lobby.js b/src/lobby.js index e4bb869b0..dc84a820f 100644 --- a/src/lobby.js +++ b/src/lobby.js @@ -77,7 +77,7 @@ class Lobby extends React.Component { } const goToRoom = roomId => { - window.open(`room.html?room=${roomId}`, "_blank"); + window.open(`room.html?room=${roomId}`, "_self"); }; const goToNewRoom = () => { -- GitLab