3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (PlayerActionHelper.php)
9
namespace Xibo\Service;
12
use Xibo\Entity\Display;
13
use Xibo\Exception\ConfigurationException;
14
use Xibo\Exception\InvalidArgumentException;
15
use Xibo\Helper\Environment;
16
use Xibo\XMR\PlayerAction;
17
use Xibo\XMR\PlayerActionException;
20
* Class PlayerActionService
21
* @package Xibo\Service
23
class PlayerActionService implements PlayerActionServiceInterface
26
* @var ConfigServiceInterface
30
/** @var LogServiceInterface */
34
private $triggerPlayerActions = true;
39
/** @var array[PlayerAction] */
40
private $actions = [];
45
public function __construct($config, $log, $triggerPlayerActions)
47
$this->config = $config;
49
$this->triggerPlayerActions = $triggerPlayerActions;
54
* @return ConfigServiceInterface
56
private function getConfig()
64
public function sendAction($displays, $action)
66
if (!$this->triggerPlayerActions)
69
// XMR network address
70
if ($this->xmrAddress == null)
71
$this->xmrAddress = $this->getConfig()->GetSetting('XMR_ADDRESS');
73
if (!is_array($displays))
74
$displays = [$displays];
77
if (!Environment::checkZmq())
78
throw new ConfigurationException(__('ZeroMQ is required to send Player Actions. Please check your configuration.'));
80
if ($this->xmrAddress == '')
81
throw new InvalidArgumentException(__('XMR address is not set'), 'xmrAddress');
83
// Send a message to all displays
84
foreach ($displays as $display) {
85
/* @var Display $display */
86
if ($display->xmrChannel == '' || $display->xmrPubKey == '')
87
throw new InvalidArgumentException(__('This Player is not configured or ready to receive push commands over XMR. Please contact your administrator.'), 'xmrRegistered');
89
$displayAction = clone $action;
92
$displayAction->setIdentity($display->xmrChannel, $display->xmrPubKey);
93
} catch (\Exception $exception) {
94
throw new InvalidArgumentException(__('Invalid XMR registration'), 'xmrPubKey');
98
$this->actions[] = $displayAction;
105
public function processQueue()
107
if (count($this->actions) > 0)
108
$this->log->debug('Player Action Service is looking to send %d actions', count($this->actions));
112
// XMR network address
113
if ($this->xmrAddress == null)
114
$this->xmrAddress = $this->getConfig()->GetSetting('XMR_ADDRESS');
118
foreach ($this->actions as $action) {
119
/** @var PlayerAction $action */
122
if ($action->send($this->xmrAddress) === false) {
123
$this->log->error('Player action refused by XMR (connected but XMR returned false).');
127
} catch (PlayerActionException $sockEx) {
128
$this->log->error('Player action connection failed. E = ' . $sockEx->getMessage());
134
throw new ConfigurationException(sprintf(__('%d of %d player actions failed'), $failures, count($this->actions)));
b'\\ No newline at end of file'