From 1030068db059e0a30bc7220f201986bc810a7deb Mon Sep 17 00:00:00 2001 From: Syco Date: Thu, 2 Nov 2017 17:22:25 +0000 Subject: [PATCH 1/4] Add format and mix parameters to MonitorAction.php Signed-off-by: Syco --- src/PAMI/Message/Action/MonitorAction.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/PAMI/Message/Action/MonitorAction.php b/src/PAMI/Message/Action/MonitorAction.php index c819cb8dd..6d72a7380 100644 --- a/src/PAMI/Message/Action/MonitorAction.php +++ b/src/PAMI/Message/Action/MonitorAction.php @@ -56,15 +56,17 @@ class MonitorAction extends ActionMessage * * @param string $channel Channel to monitor. * @param string $filename Absolute path to target filename. + * @param string $format Recording format, default 'wav'. + * @param string $mix Mix channels, default 'true'. * * @return void */ - public function __construct($channel, $filename) + public function __construct($channel, $filename, $format = 'wav', $mix = 'true') { parent::__construct('Monitor'); $this->setKey('Channel', $channel); - $this->setKey('Mix', 'true'); - $this->setKey('Format', 'wav'); + $this->setKey('Mix', $mix); + $this->setKey('Format', $format); $this->setKey('File', $filename); } } From cfcea77a175b9d88fa71cd3160f22e0f3884ce38 Mon Sep 17 00:00:00 2001 From: Syco Date: Wed, 21 Nov 2018 13:37:13 +0000 Subject: [PATCH 2/4] add Variables to StatusAction Signed-off-by: Syco --- src/PAMI/Message/Action/StatusAction.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PAMI/Message/Action/StatusAction.php b/src/PAMI/Message/Action/StatusAction.php index fe7d33bf9..9139322ab 100644 --- a/src/PAMI/Message/Action/StatusAction.php +++ b/src/PAMI/Message/Action/StatusAction.php @@ -57,4 +57,18 @@ public function __construct($channel = false) $this->setKey('Channel', $channel); } } + + /** + * Sets Variables key. + * + * @param array $variables Variables to use. + * + * @return void + */ + public function setVariables($variables = array()) + { + if (!empty($variables)) { + $this->setKey('Variables', implode(',', $variables)); + } + } } From 783f3dd4e4e5c749d5c22ebd7eacbffc5a85bbc5 Mon Sep 17 00:00:00 2001 From: Syco Date: Thu, 22 Nov 2018 14:40:21 +0000 Subject: [PATCH 3/4] add status variables to IncomingMessage.php Signed-off-by: Syco --- src/PAMI/Message/IncomingMessage.php | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/PAMI/Message/IncomingMessage.php b/src/PAMI/Message/IncomingMessage.php index 896df6601..3fc41fc00 100644 --- a/src/PAMI/Message/IncomingMessage.php +++ b/src/PAMI/Message/IncomingMessage.php @@ -53,6 +53,12 @@ abstract class IncomingMessage extends Message */ protected $channelVariables; + /** + * Metadata. Specific channel variables. + * @var string[] + */ + protected $statusVariables; + /** * Serialize function. * @@ -125,6 +131,45 @@ public function getChannelVariables($channel = null) } } + /** + * Returns the channel variables for all reported channels. + * https://github.com/marcelog/PAMI/issues/85 + * + * The channel names will be lowercased. + * + * @return array + */ + public function getAllStatusVariables() + { + return $this->statusVariables; + } + + /** + * Returns the channel variables for the given channel. + * https://github.com/marcelog/PAMI/issues/85 + * + * @param string $channel Channel name. If not given, will return variables + * for the "current" channel. + * + * @return array + */ + public function getStatusVariables($channel = null) + { + if (is_null($channel)) { + if (!isset($this->keys['channel'])) { + return $this->getChannelVariables('default'); + } else { + return $this->getChannelVariables($this->keys['channel']); + } + } else { + $channel = strtolower($channel); + if (!isset($this->statusVariables[$channel])) { + return null; + } + return $this->statusVariables[$channel]; + } + } + /** * Constructor. * @@ -136,6 +181,7 @@ public function __construct($rawContent) { parent::__construct(); $this->channelVariables = array('default' => array()); + $this->statusVariables = array('default' => array()); $this->rawContent = $rawContent; $lines = explode(Message::EOL, $rawContent); foreach ($lines as $line) { @@ -155,6 +201,18 @@ public function __construct($rawContent) unset($content[0]); $value = isset($content[1]) ? trim(implode(':', $content)) : ''; $this->channelVariables[$chanName][$name] = $value; + } else if (!strncmp($name, 'variable', 8)) { + // https://github.com/marcelog/PAMI/issues/85 + $matches = preg_match("/\(([^\)]*)\)/", $name, $captures); + $chanName = 'default'; + if ($matches > 0) { + $chanName = $captures[1]; + } + $content = explode('=', $value); + $name = strtolower(trim($content[0])); + unset($content[0]); + $value = isset($content[1]) ? trim(implode(':', $content)) : ''; + $this->statusVariables[$chanName][$name] = $value; } else { $this->setKey($name, $value); } @@ -162,6 +220,7 @@ public function __construct($rawContent) // https://github.com/marcelog/PAMI/issues/85 if (isset($this->keys['channel'])) { $channel = strtolower($this->keys['channel']); + if (isset($this->channelVariables[$channel])) { $this->channelVariables[$channel] = array_merge( $this->channelVariables[$channel], @@ -171,6 +230,16 @@ public function __construct($rawContent) $this->channelVariables[$channel] = $this->channelVariables['default']; } unset($this->channelVariables['default']); + + if (isset($this->statusVariables[$channel])) { + $this->statusVariables[$channel] = array_merge( + $this->statusVariables[$channel], + $this->statusVariables['default'] + ); + } else { + $this->statusVariables[$channel] = $this->statusVariables['default']; + } + unset($this->statusVariables['default']); } } } From f6593072ed1248c9c8c935c72626f30db325b766 Mon Sep 17 00:00:00 2001 From: Syco Date: Thu, 22 Nov 2018 14:45:36 +0000 Subject: [PATCH 4/4] fix typo on previous commit Signed-off-by: Syco --- src/PAMI/Message/IncomingMessage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PAMI/Message/IncomingMessage.php b/src/PAMI/Message/IncomingMessage.php index 3fc41fc00..970ac06f2 100644 --- a/src/PAMI/Message/IncomingMessage.php +++ b/src/PAMI/Message/IncomingMessage.php @@ -157,9 +157,9 @@ public function getStatusVariables($channel = null) { if (is_null($channel)) { if (!isset($this->keys['channel'])) { - return $this->getChannelVariables('default'); + return $this->getStatusVariables('default'); } else { - return $this->getChannelVariables($this->keys['channel']); + return $this->getStatusVariables($this->keys['channel']); } } else { $channel = strtolower($channel);