-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .asset_data import AdminAssetDataView | ||
from .configure_live_clients import AdminConfigureLiveClientsView | ||
|
||
|
||
extra_views = (AdminAssetDataView,) | ||
extra_views = (AdminAssetDataView, AdminConfigureLiveClientsView) | ||
|
||
|
||
__all__ = (extra_views,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
import logging | ||
|
||
from websockets.sync.client import connect as websocket_connect | ||
|
||
from django.conf import settings | ||
from django.contrib import messages | ||
from django.shortcuts import redirect | ||
from django.views.generic import TemplateView | ||
|
||
from ...constants import PROTOCOL_VERSION | ||
from .base import AdminViewMixin | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AdminConfigureLiveClientsView(AdminViewMixin, TemplateView): | ||
name = "configure_live_clients" | ||
perms = ("tomato.immediate_play_asset",) | ||
title = "Configure live clients" | ||
|
||
def post(self, request, *args, **kwargs): | ||
# Probably needs a refactor but okay for now | ||
try: | ||
with websocket_connect("ws://api:8000/api") as ws: | ||
ws.send( | ||
json.dumps({ | ||
"user_id": request.user.id, | ||
"tomato": "radio-automation", | ||
"protocol_version": PROTOCOL_VERSION, | ||
"admin_mode": True, | ||
"method": "secret-key", | ||
"key": settings.SECRET_KEY, | ||
}) | ||
) | ||
response = json.loads(ws.recv()) | ||
if not response["success"]: | ||
raise Exception(f"Error connecting: {response}") | ||
|
||
response = json.loads(ws.recv()) | ||
if not response["type"] == "hello": | ||
raise Exception(f"Invalid hello response type: {response}") | ||
num_connected_users = response["data"]["num_connected_users"] | ||
|
||
ws.send(json.dumps({"type": "reload-playlist"})) | ||
response = json.loads(ws.recv()) | ||
if not response["type"] == "reload-playlist": | ||
raise Exception(f"Invalid reload-playlist response type: {response}") | ||
if not response["data"]["success"]: | ||
raise Exception(f"Failure reloading playlist: {response}") | ||
|
||
except Exception: | ||
logger.exception("Error while connecting to api") | ||
self.message_user( | ||
"An error occurred while connecting to the server. Check logs for more information.", messages.ERROR | ||
) | ||
else: | ||
self.message_user(f"Reloaded the playlist of {num_connected_users} connected desktop client(s)!") | ||
|
||
return redirect("admin:extra_configure_live_clients") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
server/tomato/templates/admin/extra/configure_live_clients.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends 'admin/extra/base.html' %} | ||
|
||
{% block content %} | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<fieldset class="module aligned"> | ||
<h2>Reload all connected clients</h2> | ||
<input type="hidden" name="action" value="export"> | ||
<div class="form-row"> | ||
<p>Click the button below to reload the plalists in all connected clients.</p> | ||
</div> | ||
</fieldset> | ||
<div class="submit-row"> | ||
<input type="submit" class="default" value="Reload playlists of all connected desktop clients"> | ||
</div> | ||
</form> | ||
{% endblock %} |