Skip to content

Commit

Permalink
updated live user handling method
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-488 committed Jun 11, 2024
1 parent 5bb09c9 commit 0580f09
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,6 @@ Edrys.onReady(() => {
}
});

function getShortPeerID(id) {
const ids = id.split('_');

if (ids.length == 2) {
return ids[0].slice(6)
}

return id
}
let peerID;
// get user short id from edrys
window.addEventListener("message", (message) => {
if (message.origin !== "http://localhost:6999") {
return;
}

if (message.data.username) {
peerID = getShortPeerID(message.data.username);
}
});

// Functions to handle editor state
const clearEditor = () => {
Expand Down Expand Up @@ -267,12 +247,12 @@ Edrys.onMessage(({ from, subject, body, module }) => {
clearEditor();

disableEditor();
} else if (subject === "player-turn" && body === peerID) {
} else if (subject === "player-turn" && body === Edrys.liveUser.displayName) {
clearEditor();

// change the editor to writable when it's the player's turn
enableEditor();
} else if (subject === "player-turn" && body !== peerID) {
} else if (subject === "player-turn" && body !== Edrys.liveUser.displayName) {
disableEditor();
}
}, (promiscuous = true));
Expand Down

0 comments on commit 0580f09

Please sign in to comment.