From eb343a26b5de6599e7bec67fa340d2db4e752508 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Wed, 2 Jan 2019 17:16:36 -0800 Subject: [PATCH 01/12] Revert "Remove roles" This reverts commit a711ac4e4eb68cbd1e032439a24877f5e878dacf. --- src/hub.js | 2 +- src/react-components/ui-root.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hub.js b/src/hub.js index 00c1df6d27..45c19c7bf5 100644 --- a/src/hub.js +++ b/src/hub.js @@ -555,7 +555,7 @@ document.addEventListener("DOMContentLoaded", async () => { subscriptions.setHubChannel(hubChannel); subscriptions.setSubscribed(data.subscriptions.web_push); - remountUI({ initialIsSubscribed: subscriptions.isSubscribed() }); + remountUI({ initialIsSubscribed: subscriptions.isSubscribed(), roles: data.roles }); await handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data); }) .receive("error", res => { diff --git a/src/react-components/ui-root.js b/src/react-components/ui-root.js index b9b2c8aae0..bececd8abb 100644 --- a/src/react-components/ui-root.js +++ b/src/react-components/ui-root.js @@ -109,6 +109,7 @@ class UIRoot extends Component { platformUnsupportedReason: PropTypes.string, hubId: PropTypes.string, hubName: PropTypes.string, + roles: PropTypes.object, isSupportAvailable: PropTypes.bool, presenceLogEntries: PropTypes.array, presences: PropTypes.object, @@ -821,7 +822,9 @@ class UIRoot extends Component { return (
-
{this.props.hubName}
+
+ {this.props.hubName} {this.props.roles.is_host ? "(host)" : ""} +
From 53de046af503e0f7082cfa8f29b0bdee9694341d Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 11:30:59 -0800 Subject: [PATCH 02/12] Revert "Remove postWithAuth" This reverts commit c272bb34c9bf97a78de10fcad34cda797b1d0899. --- src/react-components/hub-create-panel.js | 11 ++--------- src/react-components/scene-ui.js | 10 ++-------- src/utils/phoenix-utils.js | 9 +++++++++ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/react-components/hub-create-panel.js b/src/react-components/hub-create-panel.js index 11f846e744..8afc537be7 100644 --- a/src/react-components/hub-create-panel.js +++ b/src/react-components/hub-create-panel.js @@ -6,7 +6,7 @@ import { faAngleLeft } from "@fortawesome/free-solid-svg-icons/faAngleLeft"; import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { resolveURL, extractUrlBase } from "../utils/resolveURL"; -import { getReticulumFetchUrl } from "../utils/phoenix-utils"; +import { postWithAuth } from "../utils/phoenix-utils"; import CreateRoomDialog from "./create-room-dialog.js"; import { WithHoverSound } from "./wrap-with-audio"; @@ -99,14 +99,7 @@ class HubCreatePanel extends Component { payload.hub.default_environment_gltf_bundle_url = sceneUrl; } - const createUrl = getReticulumFetchUrl("/api/v1/hubs"); - - const res = await fetch(createUrl, { - body: JSON.stringify(payload), - headers: { "content-type": "application/json" }, - method: "POST" - }); - + const res = await postWithAuth("/api/v1/hubs", payload); const hub = await res.json(); if (!process.env.RETICULUM_SERVER || document.location.host === process.env.RETICULUM_SERVER) { diff --git a/src/react-components/scene-ui.js b/src/react-components/scene-ui.js index 43cd7df8a9..78d977b602 100644 --- a/src/react-components/scene-ui.js +++ b/src/react-components/scene-ui.js @@ -6,7 +6,7 @@ import en from "react-intl/locale-data/en"; import styles from "../assets/stylesheets/scene-ui.scss"; import hubLogo from "../assets/images/hub-preview-white.png"; import spokeLogo from "../assets/images/spoke_logo_black.png"; -import { getReticulumFetchUrl } from "../utils/phoenix-utils"; +import { postWithAuth } from "../utils/phoenix-utils"; import { generateHubName } from "../utils/name-generation"; import { WithHoverSound } from "./wrap-with-audio"; import CreateRoomDialog from "./create-room-dialog.js"; @@ -54,14 +54,8 @@ class SceneUI extends Component { createRoom = async () => { const payload = { hub: { name: this.state.customRoomName || generateHubName(), scene_id: this.props.sceneId } }; - const createUrl = getReticulumFetchUrl("/api/v1/hubs"); - - const res = await fetch(createUrl, { - body: JSON.stringify(payload), - headers: { "content-type": "application/json" }, - method: "POST" - }); + const res = await postWithAuth("/api/v1/hubs", payload); const hub = await res.json(); if (!process.env.RETICULUM_SERVER || document.location.host === process.env.RETICULUM_SERVER) { diff --git a/src/utils/phoenix-utils.js b/src/utils/phoenix-utils.js index 7cbca9fa04..2a40de8842 100644 --- a/src/utils/phoenix-utils.js +++ b/src/utils/phoenix-utils.js @@ -52,3 +52,12 @@ export function getLandingPageForPhoto(photoUrl) { const parsedUrl = new URL(photoUrl); return getReticulumFetchUrl(parsedUrl.pathname.replace(".png", ".html") + parsedUrl.search, true); } + +export async function postWithAuth(apiEndpoint, payload) { + const headers = { "content-type": "application/json" }; + const store = new Store(); + if (store.state && store.state.credentials.token) { + headers.authorization = `bearer ${store.state.credentials.token}`; + } + return fetch(getReticulumFetchUrl(apiEndpoint), { method: "POST", headers, body: JSON.stringify(payload) }); +} From 1c50edeecc18c09327a6c0471654b3d4b13eac62 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 11:32:59 -0800 Subject: [PATCH 03/12] Revert "Remove sign in UI from home page" This reverts commit c2b2988f79f2f6e5afe18045ec90e72b964d546a. --- src/assets/stylesheets/index.scss | 13 +++++++++ src/index.js | 9 ++++++ src/react-components/home-root.js | 48 ++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/assets/stylesheets/index.scss b/src/assets/stylesheets/index.scss index 6b1d3b5ffe..f1b8517025 100644 --- a/src/assets/stylesheets/index.scss +++ b/src/assets/stylesheets/index.scss @@ -80,6 +80,19 @@ body { } } } + + :local(.sign-in) { + flex: 3; + display: flex; + align-items: center; + justify-content: end; + + a { + text-decoration: underline; + font-weight: bold; + cursor: pointer; + } + } } :local(.video-container) { diff --git a/src/index.js b/src/index.js index f41be85db3..83a92fa483 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,9 @@ import ReactDOM from "react-dom"; import "./assets/stylesheets/index.scss"; import registerTelemetry from "./telemetry"; import HomeRoot from "./react-components/home-root"; +import AuthChannel from "./utils/auth-channel"; +import { connectToReticulum } from "./utils/phoenix-utils"; +import Store from "./storage/store"; const qs = new URLSearchParams(location.search); registerTelemetry(); @@ -11,10 +14,16 @@ registerTelemetry(); const { pathname } = document.location; const sceneId = qs.get("scene_id") || (pathname.startsWith("/scenes/") && pathname.substring(1).split("/")[1]); +const store = new Store(); +const authChannel = new AuthChannel(store); +authChannel.setSocket(connectToReticulum()); + const root = ( { + this.showDialog(SignInDialog, { + message: messages["sign-in.prompt"], + onSignIn: async email => { + const { authComplete } = await this.props.authChannel.startAuthentication(email); + this.showDialog(SignInDialog, { authStarted: true }); + await authComplete; + this.setState({ signedIn: true, email }); + this.closeDialog(); + } + }); + }; + + signOut = () => { + this.props.authChannel.removeCredentials(); + // TODO BP - should randomize avatar and display name on sign out. + this.setState({ signedIn: false }); + }; + loadEnvironmentFromScene = async () => { let sceneUrlBase = "/api/v1/scenes"; if (process.env.RETICULUM_SERVER) { @@ -204,6 +234,22 @@ class HomeRoot extends Component {
+
+ {this.state.signedIn ? ( +
+ + {maskEmail(this.state.email)} + {" "} + + + +
+ ) : ( + + + + )} +
From 3f101428e98dc9291a3bf8b2175cfd946af56021 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 11:33:56 -0800 Subject: [PATCH 04/12] Revert "Remove sign in UI from home page" This reverts commit 0a570be8b3b3ad8108237c7cb57ed128a6ccfc99. --- src/react-components/home-root.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/react-components/home-root.js b/src/react-components/home-root.js index 0a1fd224a5..57c6ac6ee2 100644 --- a/src/react-components/home-root.js +++ b/src/react-components/home-root.js @@ -145,6 +145,25 @@ class HomeRoot extends Component { this.setState({ signedIn: false }); }; + showSignInDialog = () => { + this.showDialog(SignInDialog, { + message: messages["sign-in.prompt"], + onSignIn: async email => { + const { authComplete } = await this.props.authChannel.startAuthentication(email); + this.showDialog(SignInDialog, { authStarted: true }); + await authComplete; + this.setState({ signedIn: true, email }); + this.closeDialog(); + } + }); + }; + + signOut = () => { + this.props.authChannel.removeCredentials(); + // TODO BP - should randomize avatar and display name on sign out. + this.setState({ signedIn: false }); + }; + loadEnvironmentFromScene = async () => { let sceneUrlBase = "/api/v1/scenes"; if (process.env.RETICULUM_SERVER) { From 03550734e8f94a4c1c1ab21bc6020235b120ea0b Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 13:39:22 -0800 Subject: [PATCH 05/12] Fix link click callback --- src/react-components/home-root.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/react-components/home-root.js b/src/react-components/home-root.js index 57c6ac6ee2..065e251081 100644 --- a/src/react-components/home-root.js +++ b/src/react-components/home-root.js @@ -204,7 +204,7 @@ class HomeRoot extends Component { Promise.all(environmentLoads).then(() => this.setState({ environments })); }; - onDialogLinkClicked = trigger => { + onLinkClicked = trigger => { return e => { e.preventDefault(); e.stopPropagation(); @@ -329,7 +329,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onDialogLinkClicked(this.showJoinUsDialog.bind(this))} + onClick={this.onLinkClicked(this.showJoinUsDialog.bind(this))} > @@ -339,7 +339,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onDialogLinkClicked(this.showUpdatesDialog.bind(this))} + onClick={this.onLinkClicked(this.showUpdatesDialog.bind(this))} > @@ -349,7 +349,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onDialogLinkClicked(this.showReportDialog.bind(this))} + onClick={this.onLinkClicked(this.showReportDialog.bind(this))} > From b2ca98ad7fed1a9e0bc147465c2ce3eed19d5040 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 15:31:44 -0800 Subject: [PATCH 06/12] Fix signin/out on home page --- src/react-components/home-root.js | 69 ++++++++++--------------------- src/utils/auth-channel.js | 19 ++++++++- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/react-components/home-root.js b/src/react-components/home-root.js index 065e251081..51fea8bd21 100644 --- a/src/react-components/home-root.js +++ b/src/react-components/home-root.js @@ -53,11 +53,10 @@ class HomeRoot extends Component { constructor(props) { super(props); this.state.signedIn = props.authChannel.authenticated; - this.state.email = props.store.state.credentials.email; + this.state.email = props.authChannel.email; } componentDidMount() { - this.closeDialog = this.closeDialog.bind(this); if (this.props.authVerify) { this.showAuthDialog(true); this.verifyAuth().then(this.showAuthDialog); @@ -88,8 +87,14 @@ class HomeRoot extends Component { channel.push("auth_verified", { token: this.props.authToken }); } + showDialog = (DialogClass, props = {}) => { + this.setState({ + dialog: + }); + }; + showAuthDialog = verifying => { - this.setState({ dialog: }); + this.showDialog(AuthDialog, { closable: false, verifying, authOrigin: this.props.authOrigin }); }; loadHomeVideo = () => { @@ -98,52 +103,22 @@ class HomeRoot extends Component { playVideoWithStopOnBlur(videoEl); }; - closeDialog() { + closeDialog = () => { this.setState({ dialog: null }); - } - - showJoinUsDialog() { - this.setState({ dialog: }); - } - - showReportDialog() { - this.setState({ dialog: }); - } + }; - showUpdatesDialog() { - this.setState({ - dialog: this.showEmailSubmittedDialog()} /> - }); - } + showJoinUsDialog = () => this.showDialog(JoinUsDialog); - showEmailSubmittedDialog() { - this.setState({ - dialog: ( - - Great! Please check your e-mail to confirm your subscription. - - ) - }); - } + showReportDialog = () => this.showDialog(ReportDialog); - showSignInDialog = () => { - this.showDialog(SignInDialog, { - message: messages["sign-in.prompt"], - onSignIn: async email => { - const { authComplete } = await this.props.authChannel.startAuthentication(email); - this.showDialog(SignInDialog, { authStarted: true }); - await authComplete; - this.setState({ signedIn: true, email }); - this.closeDialog(); + showUpdatesDialog = () => + this.showDialog(UpdatesDialog, { + onSubmittedEmail: () => { + this.showDialog( + Great! Please check your e-mail to confirm your subscription. + ); } }); - }; - - signOut = () => { - this.props.authChannel.removeCredentials(); - // TODO BP - should randomize avatar and display name on sign out. - this.setState({ signedIn: false }); - }; showSignInDialog = () => { this.showDialog(SignInDialog, { @@ -159,7 +134,7 @@ class HomeRoot extends Component { }; signOut = () => { - this.props.authChannel.removeCredentials(); + this.props.authChannel.signOut(); // TODO BP - should randomize avatar and display name on sign out. this.setState({ signedIn: false }); }; @@ -329,7 +304,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onLinkClicked(this.showJoinUsDialog.bind(this))} + onClick={this.onLinkClicked(this.showJoinUsDialog)} > @@ -339,7 +314,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onLinkClicked(this.showUpdatesDialog.bind(this))} + onClick={this.onLinkClicked(this.showUpdatesDialog)} > @@ -349,7 +324,7 @@ class HomeRoot extends Component { className={styles.link} rel="noopener noreferrer" href="#" - onClick={this.onLinkClicked(this.showReportDialog.bind(this))} + onClick={this.onLinkClicked(this.showReportDialog)} > diff --git a/src/utils/auth-channel.js b/src/utils/auth-channel.js index b50f7d1fbc..0574c21b9f 100644 --- a/src/utils/auth-channel.js +++ b/src/utils/auth-channel.js @@ -4,15 +4,27 @@ export default class AuthChannel { constructor(store) { this.store = store; this.socket = null; + this._authenticated = !!this.store.state.credentials.token; } setSocket = socket => { this.socket = socket; }; + get email() { + return this.store.state.credentials.email; + } + + get authenticated() { + return this._authenticated; + } + signOut = async hubChannel => { - await hubChannel.signOut(); + if (hubChannel) { + await hubChannel.signOut(); + } this.store.update({ credentials: { token: null, email: null } }); + this._authenticated = false; }; async startAuthentication(email, hubChannel) { @@ -27,7 +39,10 @@ export default class AuthChannel { const authComplete = new Promise(resolve => channel.on("auth_credentials", async ({ credentials: token }) => { this.store.update({ credentials: { email, token } }); - await hubChannel.signIn(token); + if (hubChannel) { + await hubChannel.signIn(token); + } + this._authenticated = true; resolve(); }) ); From 5ea75a8d514adeaf2ce793c167f7e2ec8cfe1024 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Thu, 3 Jan 2019 16:29:54 -0800 Subject: [PATCH 07/12] Send auth token in hub channel join payload --- src/hub.js | 10 ++++------ src/utils/hub-channel.js | 2 +- src/utils/phoenix-utils.js | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hub.js b/src/hub.js index 45c19c7bf5..3e1481f32f 100644 --- a/src/hub.js +++ b/src/hub.js @@ -519,6 +519,10 @@ document.addEventListener("DOMContentLoaded", async () => { const pushSubscriptionEndpoint = await subscriptions.getCurrentEndpoint(); const joinPayload = { profile: store.state.profile, push_subscription_endpoint: pushSubscriptionEndpoint, context }; + const { token } = store.state.credentials; + if (token) { + joinPayload.token = token; + } const hubPhxChannel = socket.channel(`hub:${hubId}`, joinPayload); const presenceLogEntries = []; @@ -547,12 +551,6 @@ document.addEventListener("DOMContentLoaded", async () => { .join() .receive("ok", async data => { hubChannel.setPhoenixChannel(hubPhxChannel); - - const { token } = store.state.credentials; - if (token) { - await hubChannel.signIn(token); - } - subscriptions.setHubChannel(hubChannel); subscriptions.setSubscribed(data.subscriptions.web_push); remountUI({ initialIsSubscribed: subscriptions.isSubscribed(), roles: data.roles }); diff --git a/src/utils/hub-channel.js b/src/utils/hub-channel.js index c3b0e31546..e9064cc117 100644 --- a/src/utils/hub-channel.js +++ b/src/utils/hub-channel.js @@ -12,7 +12,7 @@ function isSameDay(da, db) { export default class HubChannel { constructor(store) { this.store = store; - this._signedIn = false; + this._signedIn = this.store.state.credentials.token; } get signedIn() { diff --git a/src/utils/phoenix-utils.js b/src/utils/phoenix-utils.js index 2a40de8842..255ee69679 100644 --- a/src/utils/phoenix-utils.js +++ b/src/utils/phoenix-utils.js @@ -1,6 +1,8 @@ import uuid from "uuid/v4"; import { Socket } from "phoenix"; +import Store from "../storage/store"; + export function connectToReticulum(debug = false) { const qs = new URLSearchParams(location.search); From ae8784fc5a7dbbb74aba5325faa77868dee57440 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Mon, 7 Jan 2019 18:59:52 -0800 Subject: [PATCH 08/12] isOwner instead of roles --- src/hub.js | 2 +- src/react-components/ui-root.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hub.js b/src/hub.js index 3e1481f32f..3da2924a89 100644 --- a/src/hub.js +++ b/src/hub.js @@ -553,7 +553,7 @@ document.addEventListener("DOMContentLoaded", async () => { hubChannel.setPhoenixChannel(hubPhxChannel); subscriptions.setHubChannel(hubChannel); subscriptions.setSubscribed(data.subscriptions.web_push); - remountUI({ initialIsSubscribed: subscriptions.isSubscribed(), roles: data.roles }); + remountUI({ initialIsSubscribed: subscriptions.isSubscribed(), isOwner: data.is_owner }); await handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data); }) .receive("error", res => { diff --git a/src/react-components/ui-root.js b/src/react-components/ui-root.js index bececd8abb..a89d7c60e9 100644 --- a/src/react-components/ui-root.js +++ b/src/react-components/ui-root.js @@ -109,7 +109,7 @@ class UIRoot extends Component { platformUnsupportedReason: PropTypes.string, hubId: PropTypes.string, hubName: PropTypes.string, - roles: PropTypes.object, + isOwner: PropTypes.bool, isSupportAvailable: PropTypes.bool, presenceLogEntries: PropTypes.array, presences: PropTypes.object, @@ -823,7 +823,7 @@ class UIRoot extends Component { return (
- {this.props.hubName} {this.props.roles.is_host ? "(host)" : ""} + {this.props.hubName} {this.props.isOwner ? "(host)" : ""}
From 502cffb414cd46a0347bb889e604b9caf332ecdd Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Fri, 11 Jan 2019 13:09:43 -0800 Subject: [PATCH 09/12] Fix signedIn boolean --- src/utils/hub-channel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/hub-channel.js b/src/utils/hub-channel.js index e9064cc117..64b73132eb 100644 --- a/src/utils/hub-channel.js +++ b/src/utils/hub-channel.js @@ -12,7 +12,7 @@ function isSameDay(da, db) { export default class HubChannel { constructor(store) { this.store = store; - this._signedIn = this.store.state.credentials.token; + this._signedIn = !!this.store.state.credentials.token; } get signedIn() { From 8cdfd0673e5649faa45c587444b93b9afcbf9f87 Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Fri, 11 Jan 2019 13:30:32 -0800 Subject: [PATCH 10/12] Remove todo --- src/react-components/home-root.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/react-components/home-root.js b/src/react-components/home-root.js index 51fea8bd21..2e475d6762 100644 --- a/src/react-components/home-root.js +++ b/src/react-components/home-root.js @@ -135,7 +135,6 @@ class HomeRoot extends Component { signOut = () => { this.props.authChannel.signOut(); - // TODO BP - should randomize avatar and display name on sign out. this.setState({ signedIn: false }); }; From fd430000867499ab0a4ae9f0c239d8f28e8e5bcc Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Fri, 11 Jan 2019 13:39:43 -0800 Subject: [PATCH 11/12] Remove postWithAuth --- src/react-components/hub-create-panel.js | 2 +- src/react-components/scene-ui.js | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/react-components/hub-create-panel.js b/src/react-components/hub-create-panel.js index 5cf6a7d7a5..22876dad7c 100644 --- a/src/react-components/hub-create-panel.js +++ b/src/react-components/hub-create-panel.js @@ -6,7 +6,7 @@ import { faAngleLeft } from "@fortawesome/free-solid-svg-icons/faAngleLeft"; import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { resolveURL, extractUrlBase } from "../utils/resolveURL"; -import { postWithAuth, createAndRedirectToNewHub } from "../utils/phoenix-utils"; +import { createAndRedirectToNewHub } from "../utils/phoenix-utils"; import CreateRoomDialog from "./create-room-dialog.js"; import { WithHoverSound } from "./wrap-with-audio"; diff --git a/src/react-components/scene-ui.js b/src/react-components/scene-ui.js index 16dc740c2a..822be821d3 100644 --- a/src/react-components/scene-ui.js +++ b/src/react-components/scene-ui.js @@ -6,8 +6,7 @@ import en from "react-intl/locale-data/en"; import styles from "../assets/stylesheets/scene-ui.scss"; import hubLogo from "../assets/images/hub-preview-white.png"; import spokeLogo from "../assets/images/spoke_logo_black.png"; -import { postWithAuth } from "../utils/phoenix-utils"; -import { generateHubName } from "../utils/name-generation"; +import { createAndRedirectToNewHub } from "../utils/phoenix-utils"; import { WithHoverSound } from "./wrap-with-audio"; import CreateRoomDialog from "./create-room-dialog.js"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -52,17 +51,8 @@ class SceneUI extends Component { this.props.scene.removeEventListener("loaded", this.onSceneLoaded); } - createRoom = async () => { - const payload = { hub: { name: this.state.customRoomName || generateHubName(), scene_id: this.props.sceneId } }; - - const res = await postWithAuth("/api/v1/hubs", payload); - const hub = await res.json(); - - if (!process.env.RETICULUM_SERVER || document.location.host === process.env.RETICULUM_SERVER) { - document.location = hub.url; - } else { - document.location = `/hub.html?hub_id=${hub.hub_id}`; - } + createRoom = () => { + createAndRedirectToNewHub(this.state.customRoomName, this.props.sceneId); }; render() { From 60bd1c0e4a53b1186213184b3b2e0513181d6f3c Mon Sep 17 00:00:00 2001 From: Brian Peiris Date: Mon, 14 Jan 2019 12:40:15 -0800 Subject: [PATCH 12/12] Rename token to auth_token --- src/hub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hub.js b/src/hub.js index 3c8bad7050..c85e2454f3 100644 --- a/src/hub.js +++ b/src/hub.js @@ -533,7 +533,7 @@ document.addEventListener("DOMContentLoaded", async () => { const joinPayload = { profile: store.state.profile, push_subscription_endpoint: pushSubscriptionEndpoint, context }; const { token } = store.state.credentials; if (token) { - joinPayload.token = token; + joinPayload.auth_token = token; } const hubPhxChannel = socket.channel(`hub:${hubId}`, joinPayload);