send_message over Redis for OMXPlayer plugin

This commit is contained in:
Fabio Manganiello 2018-06-14 21:13:01 +02:00
parent b7181085f3
commit 2d6994c057
2 changed files with 14 additions and 1 deletions

View file

@ -191,7 +191,7 @@ class Backend(Thread):
backend is configured then it will try to deliver the message to backend is configured then it will try to deliver the message to
other consumers through the configured Redis main queue. other consumers through the configured Redis main queue.
Param: Params:
msg -- The message msg -- The message
""" """
try: try:

View file

@ -10,6 +10,7 @@ import urllib.parse
from dbus.exceptions import DBusException from dbus.exceptions import DBusException
from omxplayer import OMXPlayer from omxplayer import OMXPlayer
from platypush.context import get_backend
from platypush.plugins.media import PlayerState from platypush.plugins.media import PlayerState
from platypush.message.response import Response from platypush.message.response import Response
from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \ from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \
@ -195,6 +196,18 @@ class VideoOmxplayerPlugin(Plugin):
'state': PlayerState.STOP.value 'state': PlayerState.STOP.value
})) }))
def send_message(self, msg):
try:
redis = get_backend('redis')
if not redis:
raise KeyError()
except KeyError:
self.logger.warning("Backend {} does not implement send_message " +
"and the fallback Redis backend isn't configured")
return
redis.send_message(msg)
def on_play(self): def on_play(self):
def _f(player): def _f(player):
self.send_message(VideoPlayEvent(video=self.player.get_source())) self.send_message(VideoPlayEvent(video=self.player.get_source()))