Sockets allowing for live updates rather than complete rebuilds #7
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: KristyF/PartyJukebox#7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "timerChanges"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request overview
Adds Socket.IO-based push updates so clients can stay in sync with the server (playlist changes, playback timer, and settings) without full page/playlist rebuilds.
Changes:
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 14 comments.
Show a summary per file
songAdd/timeUpdate/skipSong/settingsChange, updates some API responses.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The label’s
forattribute doesn’t match the checkbox id (duplicateallowsettingcheckvsduplicateallowesettingcheckbox), so clicking the label won’t toggle the checkbox. Update theforto match the input id for proper accessibility and UX.@ -98,15 +111,22 @@ function getCookie(cname) {// also someone who likes things not being dumb more than me would have separated the client and server buttonselse if (buttonType = "pm")assigns instead of comparing, so this branch will always execute and also mutatesbuttonType. Change this to a comparison (===) so only the intended button triggers the party mode toggle.@ -98,15 +111,22 @@ function getCookie(cname) {// also someone who likes things not being dumb more than me would have separated the client and server buttonsasync function controlButton(buttonType) {if (buttonType == "pp") { // Play-Pause buttonIn the non-OK response branch,
throw new Error(data.error)makes the subsequentalertText(...)line unreachable, and also forces callers into the catch path even though you already have the server-provided error payload. Consider either removing the throw and returning the structured{ ok/status/error }response, or moving the alert before throwing and ensuring callers handle anullreturn without crashing.controlButtonnow dereferencesresult["data"]["playingState"]without checking for anullreturn fromgetFromServer(which happens on network errors). This will throw and break UI interaction when the server is unreachable; add a null/ok check before usingresult.data.Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).
In
addToPlaylist,iis assigned withoutlet/const, creating an implicit global. Alsoimage.id = String(songObject[newItem.id]) + " image"will usually become "[object Object] image" and won’t be unique/meaningful. Declareilocally and base the image id on the filename (newItem.id) like the rest of the file does.@ -441,2 +591,4 @@let clickedBox = e.srcElement;clickedBox.checked = !clickedBox.checked;} else {justChangedSetting = true;skipInPlaylist()assumesplaylistChildren[1]exists and callsdisplayElapsedPlaylistTime()even when the playlist DOM (andelapsed-time-display) may not exist (e.g., when not in playlist mode or the playlist was cleared). This can throw on socket-drivenskipSongevents. Add guards for playlist-mode visibility/child existence and updateplaylistSongLength/playliststate when advancing to the next song so the timer stays correct.Variable playlist is used like a local variable, but is missing a declaration.
Leftover debug logging (
console.log(e)) in the volume slider handler will spam the console on every change. Remove this (or gate it behind a debug flag) before merging.The
settingsChangesocket handler still logs to console (console.log(data)/console.log("working")). These debug statements will be noisy for all clients; remove them once behavior is validated.Socket initialization uses an undeclared
socketvariable (implicit global) and the option name is misspelled (reconnectionAttemps). Declare withconst/letand use the correct Socket.IO option name (reconnectionAttempts) so reconnection behavior works as intended.The Socket.IO event handlers (
songAdd,skipSong) update the playlist DOM unconditionally. When the user is in search/settings mode, the code clears#playlistand these handlers can throw (e.g.,skipInPlaylistindexing children). Gate these updates behindplaylist-modevisibility or ensure the playlist DOM has the expected structure before mutating it.@ -71,0 +74,4 @@socketio.emit("songAdd",getSongInfo(song))def getSongInfo(song):fileofDB = sql.connect("songDatabase.db")cors_allowed_origins="*"enables any website to open a socket connection to this server and receive real-time events (playlist/time/settings). If this is intended only for the hosted client, consider making allowed origins configurable (e.g., via.env) and defaulting to the client origin instead of*.Spelling: "seperate" should be "separate".