send text messages to playout
This commit is contained in:
parent
1883fb733f
commit
3fdfa20f05
@ -6,6 +6,8 @@ from time import sleep
|
||||
|
||||
import psutil
|
||||
import yaml
|
||||
import zmq
|
||||
from django.conf import settings
|
||||
from pymediainfo import MediaInfo
|
||||
|
||||
from api.models import GuiSettings
|
||||
@ -56,6 +58,47 @@ def read_log(type):
|
||||
return log.read().strip()
|
||||
|
||||
|
||||
def send_message(data):
|
||||
config = read_yaml()
|
||||
address, port = config['text']['bind_address'].split(':')
|
||||
|
||||
context = zmq.Context(1)
|
||||
client = context.socket(zmq.REQ)
|
||||
client.connect('tcp://{}:{}'.format(address, port))
|
||||
|
||||
poll = zmq.Poller()
|
||||
poll.register(client, zmq.POLLIN)
|
||||
|
||||
request = ''
|
||||
reply_msg = ''
|
||||
|
||||
for key, value in data.items():
|
||||
request += "{}='{}':".format(key, value)
|
||||
|
||||
request = "{} reinit {}".format(settings.DRAW_TEXT_NODE, request.rstrip(':'))
|
||||
|
||||
client.send_string(request)
|
||||
|
||||
socks = dict(poll.poll(settings.REQUEST_TIMEOUT))
|
||||
|
||||
if socks.get(client) == zmq.POLLIN:
|
||||
reply = client.recv()
|
||||
|
||||
if reply and reply.decode() == '0 Success':
|
||||
reply_msg = reply.decode()
|
||||
else:
|
||||
reply_msg = reply.decode()
|
||||
else:
|
||||
reply_msg = 'No response from server'
|
||||
|
||||
client.setsockopt(zmq.LINGER, 0)
|
||||
client.close()
|
||||
poll.unregister(client)
|
||||
|
||||
context.term()
|
||||
return {'Success': reply_msg}
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix='B'):
|
||||
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
|
||||
if abs(num) < 1024.0:
|
||||
|
@ -13,7 +13,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from .utils import (PlayoutService, SystemStats, get_media_path, read_json,
|
||||
read_yaml, write_json, write_yaml, read_log)
|
||||
read_yaml, write_json, write_yaml, read_log, send_message)
|
||||
|
||||
|
||||
class CurrentUserView(APIView):
|
||||
@ -58,6 +58,16 @@ class MessengerViewSet(viewsets.ModelViewSet):
|
||||
filterset_class = MessengerFilter
|
||||
|
||||
|
||||
class MessegeSender(APIView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'data' in request.data:
|
||||
response = send_message(request.data['data'])
|
||||
return Response({"success": True, 'status': response})
|
||||
|
||||
return Response({"success": False})
|
||||
|
||||
|
||||
class Config(APIView):
|
||||
"""
|
||||
read and write config from ffplayout engine
|
||||
|
@ -148,3 +148,9 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# ffmpeg filter node, needs to be edit only when the filter chain changes
|
||||
DRAW_TEXT_NODE = 'Parsed_drawtext_2'
|
||||
|
||||
# zmq settings
|
||||
REQUEST_TIMEOUT = 1000
|
||||
|
@ -39,6 +39,7 @@ urlpatterns = [
|
||||
path('api/log/', views.LogReader.as_view()),
|
||||
path('api/current/user/', views.CurrentUserView.as_view()),
|
||||
path('api/media/', views.Media.as_view()),
|
||||
path('api/send/', views.MessegeSender.as_view()),
|
||||
re_path(r'^api/media/upload/(?P<filename>[^/]+)$', views.FileUpload.as_view()),
|
||||
path('api/media/op/', views.FileOperations.as_view()),
|
||||
path('api-auth/', include(
|
||||
|
@ -189,10 +189,10 @@
|
||||
</b-button>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-alert variant="success" :show="success" dismissible>
|
||||
<b-alert variant="success" :show="success" dismissible @dismissed="success=false">
|
||||
Sending success...
|
||||
</b-alert>
|
||||
<b-alert variant="warning" :show="failed" dismissible>
|
||||
<b-alert variant="warning" :show="failed" dismissible @dismissed="success=failed">
|
||||
Sending failed...
|
||||
</b-alert>
|
||||
</b-col>
|
||||
@ -403,7 +403,8 @@ export default {
|
||||
this.getPreset('')
|
||||
},
|
||||
|
||||
submitMessage () {
|
||||
async submitMessage () {
|
||||
await this.$store.dispatch('auth/inspectToken')
|
||||
function aToHex (num) {
|
||||
return '0x' + Math.round(num * 255).toString(16)
|
||||
}
|
||||
@ -420,7 +421,18 @@ export default {
|
||||
boxcolor: this.form.boxColor + '@' + aToHex(this.form.boxAlpha),
|
||||
boxborderw: this.form.border
|
||||
}
|
||||
console.log(obj)
|
||||
|
||||
const response = await this.$axios.post(
|
||||
'api/send/',
|
||||
{ data: obj },
|
||||
{ headers: { Authorization: 'Bearer ' + this.$store.state.auth.jwtToken } }
|
||||
)
|
||||
|
||||
if (response.data && response.data.status.Success && response.data.status.Success === '0 Success') {
|
||||
this.success = true
|
||||
} else {
|
||||
this.failed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user