diff --git a/src/hub.js b/src/hub.js index cc6ad39c604f508bb1a3863577a3ba040c738aec..608c741514a9d3e3345d9e1c20df9ba2ae912f31 100644 --- a/src/hub.js +++ b/src/hub.js @@ -130,12 +130,7 @@ import registerTelemetry from "./telemetry"; import { getAvailableVREntryTypes, VR_DEVICE_AVAILABILITY } from "./utils/vr-caps-detect.js"; import ConcurrentLoadDetector from "./utils/concurrent-load-detector.js"; - -function qsTruthy(param) { - const val = qs.get(param); - // if the param exists but is not set (e.g. "?foo&bar"), its value is the empty string. - return val === "" || /1|on|true/i.test(val); -} +import qsTruthy from "./utils/qs_truthy"; const isBotMode = qsTruthy("bot"); const isTelemetryDisabled = qsTruthy("disable_telemetry"); diff --git a/src/react-components/2d-hud.js b/src/react-components/2d-hud.js index d017dcad47918a476931237eb453fa5d1971a8a8..8bcec6c7137d1a47f8322610fbf3c4891ee1774b 100644 --- a/src/react-components/2d-hud.js +++ b/src/react-components/2d-hud.js @@ -3,6 +3,7 @@ import PropTypes from "prop-types"; import cx from "classnames"; import styles from "../assets/stylesheets/2d-hud.scss"; +import qsTruthy from "../utils/qs_truthy"; const TopHUD = ({ muted, frozen, spacebubble, onToggleMute, onToggleFreeze, onToggleSpaceBubble }) => ( <div className={cx(styles.container, styles.top)}> @@ -39,7 +40,7 @@ TopHUD.propTypes = { const BottomHUD = ({ onCreateObject }) => ( <div className={cx(styles.container, styles.bottom)}> - {new URLSearchParams(document.location.search).get("mediaTools") === "true" && ( + {qsTruthy("mediaTools") && ( <div className={cx("ui-interactive", styles.iconButton, styles.large, styles.createObject)} title={"Create Object"} diff --git a/src/utils/logging.js b/src/utils/logging.js index 1114f65729fdcbebb063276495031eea532bdcd5..44da14381116618bd8c660664eda95b2efa53a80 100644 --- a/src/utils/logging.js +++ b/src/utils/logging.js @@ -1,15 +1,9 @@ // A-Frame blows away any npm debug log filters so this allow the user to set the log filter // via the query string. import debug from "debug"; +import qsTruthy from "./qs_truthy"; const qs = new URLSearchParams(location.search); - -function qsTruthy(param) { - const val = qs.get(param); - // if the param exists but is not set (e.g. "?foo&bar"), its value is the empty string. - return val === "" || /1|on|true/i.test(val); -} - const isDebug = qsTruthy("debug"); const logFilter = qs.get("log_filter") || (isDebug && "naf-janus-adapter:*"); diff --git a/src/utils/qs_truthy.js b/src/utils/qs_truthy.js new file mode 100644 index 0000000000000000000000000000000000000000..5876ae3713415c7f7fcf2a838194dcfbe6a794b1 --- /dev/null +++ b/src/utils/qs_truthy.js @@ -0,0 +1,7 @@ +const qs = new URLSearchParams(location.search); + +export default function qsTruthy(param) { + const val = qs.get(param); + // if the param exists but is not set (e.g. "?foo&bar"), its value is the empty string. + return val === "" || /1|on|true/i.test(val); +}