Skip to content

Commit

Permalink
Display Group : show display name in the error on XMR send action
Browse files Browse the repository at this point in the history
xibo/xibosignage#3080
  • Loading branch information
PeterMis committed Aug 15, 2023
1 parent fe74b12 commit fb956c6
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions lib/Service/PlayerActionService.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* Copyright (C) 2022 Xibo Signage Ltd
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand All @@ -23,7 +23,6 @@

namespace Xibo\Service;


use Xibo\Entity\Display;
use Xibo\Helper\Environment;
use Xibo\Support\Exception\ConfigurationException;
Expand Down Expand Up @@ -78,35 +77,56 @@ private function getConfig()
*/
public function sendAction($displays, $action)
{
if (!$this->triggerPlayerActions)
if (!$this->triggerPlayerActions) {
return;
}

// XMR network address
if ($this->xmrAddress == null)
if ($this->xmrAddress == null) {
$this->xmrAddress = $this->getConfig()->getSetting('XMR_ADDRESS');
}

if (!is_array($displays))
if (!is_array($displays)) {
$displays = [$displays];
}

// Check ZMQ
if (!Environment::checkZmq())
throw new ConfigurationException(__('ZeroMQ is required to send Player Actions. Please check your configuration.'));
if (!Environment::checkZmq()) {
throw new ConfigurationException(
__('ZeroMQ is required to send Player Actions. Please check your configuration.')
);
}

if ($this->xmrAddress == '')
if ($this->xmrAddress == '') {
throw new InvalidArgumentException(__('XMR address is not set'), 'xmrAddress');
}

// Send a message to all displays
foreach ($displays as $display) {
/* @var Display $display */
if ($display->xmrChannel == '' || $display->xmrPubKey == '')
throw new InvalidArgumentException(__('This Player is not configured or ready to receive push commands over XMR. Please contact your administrator.'), 'xmrRegistered');
if ($display->xmrChannel == '' || $display->xmrPubKey == '') {
throw new InvalidArgumentException(
__(sprintf(
'%s is not configured or ready to receive push commands over XMR.
Please contact your administrator.',
$display->display
)),
'xmrRegistered'
);
}

$displayAction = clone $action;

try {
$displayAction->setIdentity($display->xmrChannel, $display->xmrPubKey);
} catch (\Exception $exception) {
throw new InvalidArgumentException(__('Invalid XMR registration'), 'xmrPubKey');
throw new InvalidArgumentException(
__(sprintf(
'%s Invalid XMR registration',
$display->display
)),
'xmrPubKey'
);
}

// Add to collection
Expand All @@ -125,15 +145,16 @@ public function getQueue(): array
*/
public function processQueue()
{
if (count($this->actions) > 0)
if (count($this->actions) > 0) {
$this->log->debug('Player Action Service is looking to send %d actions', count($this->actions));
else
} else {
return;
}

// XMR network address
if ($this->xmrAddress == null)
if ($this->xmrAddress == null) {
$this->xmrAddress = $this->getConfig()->getSetting('XMR_ADDRESS');

}
$failures = 0;

foreach ($this->actions as $action) {
Expand All @@ -144,14 +165,20 @@ public function processQueue()
$this->log->error('Player action refused by XMR (connected but XMR returned false).');
$failures++;
}

} catch (PlayerActionException $sockEx) {
$this->log->error('Player action connection failed. E = ' . $sockEx->getMessage());
$failures++;
}
}

if ($failures > 0)
throw new ConfigurationException(sprintf(__('%d of %d player actions failed'), $failures, count($this->actions)));
if ($failures > 0) {
throw new ConfigurationException(
sprintf(
__('%d of %d player actions failed'),
$failures,
count($this->actions)
)
);
}
}
}

0 comments on commit fb956c6

Please sign in to comment.