Skip to content
Snippets Groups Projects
Commit 3af54c4e authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Fixed global pathElems map (now per room connection)

parent 52f2594e
No related branches found
No related tags found
1 merge request!28Rooms and frontend
Pipeline #101755 passed
...@@ -20,9 +20,7 @@ const STROKECOLOUR = "blue" ...@@ -20,9 +20,7 @@ const STROKECOLOUR = "blue"
const STROKERADIUS = 2 const STROKERADIUS = 2
const ERASERRADIUS = STROKERADIUS * 2 const ERASERRADIUS = STROKERADIUS * 2
const pathElems = new Map() const addOrUpdatePathElem = (pathElems, id, points) => {
const addOrUpdatePathElem = (id, points) => {
let pathElem = pathElems.get(id) let pathElem = pathElems.get(id)
if (pathElem == null) { if (pathElem == null) {
...@@ -129,6 +127,8 @@ function handleRoomConnectionEstablished(room) { ...@@ -129,6 +127,8 @@ function handleRoomConnectionEstablished(room) {
let userInput = false let userInput = false
let currentTool = tools.PEN let currentTool = tools.PEN
let pathElems = new Map()
let currentPathID = null let currentPathID = null
HTML.userIDElem.value = room.ownID || "" HTML.userIDElem.value = room.ownID || ""
...@@ -159,7 +159,7 @@ function handleRoomConnectionEstablished(room) { ...@@ -159,7 +159,7 @@ function handleRoomConnectionEstablished(room) {
}) })
room.addEventListener("addOrUpdatePath", ({ detail: { id, points } }) => { room.addEventListener("addOrUpdatePath", ({ detail: { id, points } }) => {
addOrUpdatePathElem(id, points) addOrUpdatePathElem(pathElems, id, points)
}) })
const canvasOnMouseDown = (e) => { const canvasOnMouseDown = (e) => {
...@@ -265,6 +265,9 @@ function handleRoomConnectionEstablished(room) { ...@@ -265,6 +265,9 @@ function handleRoomConnectionEstablished(room) {
HTML.roomConnectButton.removeEventListener("click", handleRoomConnectClick) HTML.roomConnectButton.removeEventListener("click", handleRoomConnectClick)
const roomConnectButtonOnClick = () => { const roomConnectButtonOnClick = () => {
const selectedRoomID = HTML.roomIDElem.value
if (!selectedRoomID || selectedRoomID === room.name) return
HTML.canvas.removeEventListener("mousedown", canvasOnMouseDown) HTML.canvas.removeEventListener("mousedown", canvasOnMouseDown)
HTML.canvas.removeEventListener("mouseleave", canvasOnMouseLeave) HTML.canvas.removeEventListener("mouseleave", canvasOnMouseLeave)
HTML.canvas.removeEventListener("mouseenter", canvasOnMouseEnter) HTML.canvas.removeEventListener("mouseenter", canvasOnMouseEnter)
...@@ -273,15 +276,17 @@ function handleRoomConnectionEstablished(room) { ...@@ -273,15 +276,17 @@ function handleRoomConnectionEstablished(room) {
HTML.peerButton.removeEventListener("click", peerButtonOnClick) HTML.peerButton.removeEventListener("click", peerButtonOnClick)
HTML.penButton.removeEventListener("click", penButtonOnClick) HTML.penButton.removeEventListener("click", penButtonOnClick)
HTML.eraserButton.removeEventListener("click", eraserButtonOnClick) HTML.eraserButton.removeEventListener("click", eraserButtonOnClick)
HTML.roomConnectButton.removeEventListener(
"click",
roomConnectButtonOnClick,
)
room.disconnect() room.disconnect()
room = undefined room = undefined
handleRoomConnectClick() handleRoomConnectClick()
} }
HTML.roomConnectButton.addEventListener("click", roomConnectButtonOnClick, { HTML.roomConnectButton.addEventListener("click", roomConnectButtonOnClick)
once: true,
})
} }
function handleRoomConnectionError(err) { function handleRoomConnectionError(err) {
......
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