Skip to content

Commit

Permalink
Notify user if playlist is refreshed from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Aug 1, 2024
1 parent 86b42f8 commit cde2c67
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Changes for 2024 based on real world usage in 2023 and feedback
- [x] Rudimentary stopset editor, in the form of "skip/queue", regenerate asset, and swap asset
- [ ] Ability to "audition" assets on a second audio output?
- [x] ~~Stop playing at end of current asset. (Stop playing in 3s with fadeout as well?)~~ (Covered by skip)
- [ ] A way to send a custom text notification to all connected clients from backend UI


Other things
Expand Down
8 changes: 6 additions & 2 deletions client/src/stores/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { persisted } from "svelte-local-storage-store"
import { noop } from "svelte/internal"
import { derived, get, writable } from "svelte/store"
import { protocol_version } from "../../../server/constants.json"
import { alert } from "./alerts"
import { acknowledgeLog, log, sendPendingLogs } from "./client-logs"
import { resetUserConfig, setServerConfig } from "./config"
import { clearAssetsDB, clearAssetState, syncAssetsDB } from "./db"
Expand Down Expand Up @@ -102,8 +103,11 @@ const handleMessages = {
acknowledgeLog(id)
}
},
"reload-playlist": () => {
console.log("Backend requested a playlist reload")
"reload-playlist": (data) => {
const { notify } = data
if (notify) {
alert("An administrator forced a playlist refresh!", "info", 4000)
}
get(reloadPlaylistCallback)()
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/api/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def hello(self, connection: Connection):

async def process_reload_playlist(self, connection: Connection, data):
logger.info("Reloading all playlist via admin request")
await users.broadcast(OutgoingAdminMessageTypes.RELOAD_PLAYLIST)
await users.broadcast(OutgoingUserMessageTypes.RELOAD_PLAYLIST, {"notify": True})
await connection.message(OutgoingAdminMessageTypes.RELOAD_PLAYLIST, {"success": True})


Expand All @@ -44,7 +44,7 @@ async def broadcast_data_change(self, force=False):
if force or serialized_data != self.last_serialized_data:
await self.broadcast(OutgoingUserMessageTypes.DATA, serialized_data)
if await get_config_async("RELOAD_PLAYLIST_AFTER_DATA_CHANGES"):
await self.broadcast(OutgoingUserMessageTypes.RELOAD_PLAYLIST)
await self.broadcast(OutgoingUserMessageTypes.RELOAD_PLAYLIST, {"notify": False})
self.last_serialized_data = serialized_data
else:
logger.debug("No change to DB data. Not broadcasting.")
Expand Down
7 changes: 4 additions & 3 deletions server/api/server_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async def disconnect(reason, admin_only=False):

if password_change:
await disconnect(reason="password change")

else:
try:
user = await User.objects.aget(id=user_id)
Expand Down Expand Up @@ -73,12 +74,12 @@ async def process_db_changes_force(self, message):
logger.info("Forcing broadcast of data message")
await self.process_db_changes(message, force_broadcast=True)

async def process_reload_playlist(self, message):
async def process_reload_playlist(self, message, notify=False):
user_id = message.get("user_id") if message else None
if user_id is None:
await users.broadcast(OutgoingUserMessageTypes.RELOAD_PLAYLIST)
await users.broadcast(OutgoingUserMessageTypes.RELOAD_PLAYLIST, {"notify": notify})
else:
await users.message(user_id, OutgoingUserMessageTypes.RELOAD_PLAYLIST)
await users.message(user_id, OutgoingUserMessageTypes.RELOAD_PLAYLIST, {"notify": notify})

@task
async def consume_db_notifications_debouncer(self):
Expand Down

0 comments on commit cde2c67

Please sign in to comment.