Skip to content
Snippets Groups Projects
Commit 64b7d66c authored by Nayeem Rahman's avatar Nayeem Rahman
Browse files

Navigate search params on room change

Redirect when room isn't given.
parent 3954983f
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,17 @@ import * as humanhash from "humanhash"
import jdenticon from "jdenticon"
const DEFAULT_ROOM = "imperial"
const initialRoom =
new URLSearchParams(location.search).get("room") || DEFAULT_ROOM
const navigateToRoom = (roomID) => {
const url = new URL(location.href)
url.searchParams.set("room", roomID)
location.href = url
}
const initialRoom = new URLSearchParams(location.search).get("room")
if (initialRoom == null) {
navigateToRoom(DEFAULT_ROOM)
}
const MIN_PRESSURE_FACTOR = 0.1
const MAX_PRESSURE_FACTOR = 1.5
......@@ -362,22 +371,7 @@ HTML.peerButton.addEventListener("click", () => {
})
const onRoomJoinEnter = () => {
const selectedRoomID = HTML.roomIDElem.value
if (!selectedRoomID || selectedRoomID == room.name) {
return
}
if (room != null) {
room.disconnect()
room = null
}
canvas.clear()
HTML.connectedPeers.innerHTML = "No peers are connected"
HTML.fastUndoButton.classList.add("disabled")
HTML.undoButton.classList.add("disabled")
tryRoomConnect(selectedRoomID)
navigateToRoom(HTML.roomIDElem.value)
}
HTML.roomConnectButton.addEventListener("click", onRoomJoinEnter)
......
......@@ -45,6 +45,17 @@ app.use((request, response, next) => {
next()
})
app.get("/", (request, response, next) => {
if (request.query.room == null) {
const url = new URL(
`${request.protocol}://${request.get("host")}${request.originalUrl}`,
)
url.searchParams.set("room", "imperial")
return response.redirect(url)
}
next()
})
app.use("/", express.static("public"))
server.listen(port, host, () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment