reregister users on roll
All checks were successful
CI / deploy (push) Successful in 5m48s
CI / deploy (pull_request) Successful in 6m0s

This commit is contained in:
Arindy 2025-02-22 12:16:22 +01:00
parent 8a4032756e
commit d030eda0e9
2 changed files with 30 additions and 29 deletions

View File

@ -14,6 +14,17 @@ function url() {
return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : ''); return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : '');
} }
function register() {
let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + '/register')
httpRequest.setRequestHeader('Content-Type', 'application/json')
httpRequest.send(JSON.stringify({
name: document.getElementById('name').value,
overlay: document.getElementById('overlayId').value,
id: document.getElementById('room').value + ':' + localStorage.getItem('userId')
}))
}
function start(event = undefined) { function start(event = undefined) {
if ((!event || event.keyCode === 13) && document.getElementById('name').value.length > 0 && document.getElementById('room').value.length > 0) { if ((!event || event.keyCode === 13) && document.getElementById('name').value.length > 0 && document.getElementById('room').value.length > 0) {
document.getElementById('overlayId').value = url() + '/overlay/' + document.getElementById('room').value + ':' + localStorage.getItem('userId') + '?scale=10&clearAfter=30'; document.getElementById('overlayId').value = url() + '/overlay/' + document.getElementById('room').value + ':' + localStorage.getItem('userId') + '?scale=10&clearAfter=30';
@ -61,14 +72,7 @@ function start(event = undefined) {
localStorage.setItem(document.getElementById('name').value + '-started', "true") localStorage.setItem(document.getElementById('name').value + '-started', "true")
let httpRequest = new XMLHttpRequest(); register();
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + '/register')
httpRequest.setRequestHeader('Content-Type', 'application/json')
httpRequest.send(JSON.stringify({
name: document.getElementById('name').value,
overlay: document.getElementById('overlayId').value,
id: document.getElementById('room').value + ':' + localStorage.getItem('userId')
}))
if (document.getElementById('gm').checked) { if (document.getElementById('gm').checked) {
document.getElementById('resultSwitch').checked = true; document.getElementById('resultSwitch').checked = true;
document.getElementById('resultFrame').src = document.getElementById('resultsId').value; document.getElementById('resultFrame').src = document.getElementById('resultsId').value;
@ -98,18 +102,21 @@ function start(event = undefined) {
newOverlay.appendChild(newInput); newOverlay.appendChild(newInput);
overlays.appendChild(newOverlay); overlays.appendChild(newOverlay);
let dice = document.createElement('iframe'); if (!document.getElementById(data.id + '-diceFrame')) {
dice.id = data.id + '-diceFrame' let dice = document.createElement('iframe');
dice.style.width = "50%"; dice.id = data.id + '-diceFrame'
dice.style.height = "100%"; dice.style.width = "50%";
dice.style.overflow = "hidden"; dice.style.height = "100%";
dice.style.border = "0"; dice.style.overflow = "hidden";
dice.style.zIndex = "4"; dice.style.border = "0";
dice.style.position = "absolute"; dice.style.zIndex = "4";
dice.style.top = "0"; dice.style.position = "absolute";
dice.style.left = "50%"; dice.style.top = "0";
dice.src = data.overlay; dice.style.left = "50%";
document.getElementById('results-dice').appendChild(dice) dice.src = data.overlay;
document.getElementById('results-dice').appendChild(dice)
}
} }
configurePopover(); configurePopover();
@ -125,6 +132,7 @@ function rollEasy(dice) {
function roll(event) { function roll(event) {
if ((!event || event.keyCode === 13) && document.getElementById('command').value?.length > 0) { if ((!event || event.keyCode === 13) && document.getElementById('command').value?.length > 0) {
register()
let httpRequest = new XMLHttpRequest(); let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + ':' + localStorage.getItem(`userId`)) httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + ':' + localStorage.getItem(`userId`))
httpRequest.setRequestHeader('Content-Type', 'application/json') httpRequest.setRequestHeader('Content-Type', 'application/json')
@ -207,11 +215,7 @@ document.addEventListener("DOMContentLoaded", async () => {
}) })
document.getElementById('resultDiceSwitch').addEventListener('change', function () { document.getElementById('resultDiceSwitch').addEventListener('change', function () {
if (!this.checked) { document.getElementById('results-dice').hidden = !this.checked;
document.getElementById('results-dice').hidden = true
} else {
document.getElementById('results-dice').hidden = false
}
}) })
document.getElementById('chatOverlayLink').href = url() + '/chatoverlay' document.getElementById('chatOverlayLink').href = url() + '/chatoverlay'

View File

@ -202,11 +202,8 @@
<h2 style="text-align: center">How-To</h2> <h2 style="text-align: center">How-To</h2>
<ul> <ul>
<li> <li>
Join a room by entering your character name and the name of the room.<br/> Join a room by entering your character name and the name of the room
<strong>If you are a GM, make sure to join the room first or let all other players rejoin to get all
Overlay-URLs.</strong>
</li> </li>
<li>Open your Dice-Overlay either in a new Tab or as a browser source in OBS</li> <li>Open your Dice-Overlay either in a new Tab or as a browser source in OBS</li>
<ul> <ul>
<li>You can configure your Overlay with query parameters (for more information hover over the link) <li>You can configure your Overlay with query parameters (for more information hover over the link)