From 1fc92f5ec112d31d524946bd7b67535cf269dd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Tr=C3=B6ger?= Date: Tue, 8 Aug 2023 10:57:09 +0200 Subject: [PATCH] no message --- ONVIF Configurator/module.php | 25 +++--- ONVIF Digital Input/module.php | 12 +-- ONVIF Digital Output/module.php | 18 ++-- ONVIF Discovery/module.php | 28 +++--- ONVIF Events/module.php | 8 +- ONVIF IO/module.php | 2 +- ONVIF Image Grabber/module.php | 46 +++++----- ONVIF Media Stream/module.php | 152 ++++++++++++++++---------------- libs/ONVIFModuleBase.php | 28 +++--- libs/wsdl.php | 124 ++++++++++++++++++-------- 10 files changed, 245 insertions(+), 198 deletions(-) diff --git a/ONVIF Configurator/module.php b/ONVIF Configurator/module.php index e47fc28..bd27a44 100644 --- a/ONVIF Configurator/module.php +++ b/ONVIF Configurator/module.php @@ -7,11 +7,6 @@ class ONVIFConfigurator extends ONVIFModuleBase { public const wsdl = \ONVIF\WSDL::Management; - public const GUID_ONVIF_DIGITAL_INPUT = '{73097230-1ECC-FEEB-5969-C85148DFA76E}'; - public const GUID_ONVIF_DIGITAL_OUTPUT = '{A44B3114-1F72-1FD1-96FB-D7E970BD8614}'; - public const GUID_ONVIF_MEDIA_STREAM = '{FA889450-38B6-7E20-D4DC-F2C6D0B074FB}'; - public const GUID_ONVIF_IMAGE_GRABBER = '{18EA97C1-3CEC-80B7-4CAA-D91F8A2A0599}'; - public const GUID_ONVIF_EVENT = '{62584C2E-4542-4EBF-1E92-299F4CF364E4}'; public function GetConfigurationForm(): string { @@ -70,7 +65,7 @@ public function GetConfigurationForm(): string } } $EventValues = []; - $IPSEventInstances = $this->GetInstanceList(self::GUID_ONVIF_EVENT, ['EventTopic']); + $IPSEventInstances = $this->GetInstanceList(\ONVIF\GUID::Event, ['EventTopic']); foreach ($Events as $Topic) { $Device = [ @@ -89,7 +84,7 @@ public function GetConfigurationForm(): string } $Device['create'] = [ - 'moduleID' => self::GUID_ONVIF_EVENT, + 'moduleID' => \ONVIF\GUID::Event, 'configuration' => [ 'EventTopic' => $Topic ], @@ -114,7 +109,7 @@ public function GetConfigurationForm(): string $InputTopics = []; foreach (array_keys($InputEvents) as $Topic) { $InputTopics[$Topic] = [ - 'moduleID' => self::GUID_ONVIF_DIGITAL_INPUT, + 'moduleID' => \ONVIF\GUID::Input, 'configuration' => [ 'EventTopic' => $Topic ], @@ -124,7 +119,7 @@ public function GetConfigurationForm(): string if (count($InputTopics) == 1) { $InputTopics = array_shift($InputTopics); } - $InputValues = $this->GetConfigurationArray(self::GUID_ONVIF_DIGITAL_INPUT, $Capabilities['NbrOfInputs'] > 0, $InputTopics); + $InputValues = $this->GetConfigurationArray(\ONVIF\GUID::Input, $Capabilities['NbrOfInputs'] > 0, $InputTopics); // Outputs $OutputEvents = $this->GetEvents('relay', 0); @@ -134,7 +129,7 @@ public function GetConfigurationForm(): string $OutputTopics = []; foreach (array_keys($OutputEvents) as $Topic) { $OutputTopics[$Topic] = [ - 'moduleID' => self::GUID_ONVIF_DIGITAL_OUTPUT, + 'moduleID' => \ONVIF\GUID::Output, 'configuration' => [ 'EventTopic' => $Topic ], @@ -144,16 +139,16 @@ public function GetConfigurationForm(): string if (count($OutputTopics) == 1) { $OutputTopics = array_shift($OutputTopics); } - $OutputValues = $this->GetConfigurationArray(self::GUID_ONVIF_DIGITAL_OUTPUT, $Capabilities['NbrOfOutputs'] > 0, $OutputTopics); + $OutputValues = $this->GetConfigurationArray(\ONVIF\GUID::Output, $Capabilities['NbrOfOutputs'] > 0, $OutputTopics); // Stream H264 $StreamCreateParams = [ - 'moduleID' => self::GUID_ONVIF_MEDIA_STREAM, + 'moduleID' => \ONVIF\GUID::Stream, 'configuration' => [], 'location' => [$this->Translate('ONVIF Devices'), IPS_GetName($this->InstanceID)] ]; $StreamValues = []; - $IPSStreamInstances = $this->GetInstanceList(self::GUID_ONVIF_MEDIA_STREAM, ['Profile', 'VideoSource']); + $IPSStreamInstances = $this->GetInstanceList(\ONVIF\GUID::Stream, ['Profile', 'VideoSource']); foreach ($Capabilities['VideoSources'] as $VideoSource) { foreach ($VideoSource['Profile'] as $ProfileIndex => $Profile) { $InstanceID = array_search($Profile['token'] . ':' . $VideoSource['VideoSourceToken'], $IPSStreamInstances); @@ -211,12 +206,12 @@ public function GetConfigurationForm(): string } // Stream JPEG $StreamJPEGCreateParams = [ - 'moduleID' => self::GUID_ONVIF_IMAGE_GRABBER, + 'moduleID' => \ONVIF\GUID::ImageGrabber, 'configuration' => [], 'location' => [$this->Translate('ONVIF Devices'), IPS_GetName($this->InstanceID)] ]; $StreamJPEGValues = []; - $IPSStreamJPEGInstances = $this->GetInstanceList(self::GUID_ONVIF_IMAGE_GRABBER, ['Profile', 'VideoSource']); + $IPSStreamJPEGInstances = $this->GetInstanceList(\ONVIF\GUID::ImageGrabber, ['Profile', 'VideoSource']); if ($Capabilities['HasSnapshotUri']) { foreach ($Capabilities['VideoSourcesJPEG'] as $VideoSourceJPEG) { foreach ($VideoSourceJPEG['Profile'] as $ProfileIndex =>$Profile) { diff --git a/ONVIF Digital Input/module.php b/ONVIF Digital Input/module.php index d8a260f..838392d 100644 --- a/ONVIF Digital Input/module.php +++ b/ONVIF Digital Input/module.php @@ -12,7 +12,7 @@ public function Create(): void { //Never delete this line! parent::Create(); - $this->RegisterAttributeArray('DigitalInputs', []); + $this->RegisterAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, []); } public function ApplyChanges(): void { @@ -21,7 +21,7 @@ public function ApplyChanges(): void if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); return; } @@ -31,14 +31,14 @@ public function ApplyChanges(): void $this->SetStatus(IS_EBASE + 1); return; } - $this->WriteAttributeArray('DigitalInputs', $Capabilities['DigitalInputs']); + $this->WriteAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, $Capabilities['DigitalInputs']); foreach ($Capabilities['DigitalInputs'] as $Name => $DigitalInput) { $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); } - $Events = $this->GetEvents($this->ReadPropertyString('EventTopic')); + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); $this->SendDebug('EventConfig', $Events, 0); if (count($Events) != 1) { $this->SetStatus(IS_EBASE + 1); @@ -53,7 +53,7 @@ public function ReceiveData(string $JSONString): string $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return ''; } @@ -87,7 +87,7 @@ public function GetConfigurationForm(): string } $Form['elements'][0] = $this->GetConfigurationFormEventTopic($Form['elements'][0]); $Actions = [['type' => 'TestCenter']]; - $DigitalInputs = $this->ReadAttributeArray('DigitalInputs'); + $DigitalInputs = $this->ReadAttributeArray(\ONVIF\Input\Attribute::DigitalInputs); foreach ($DigitalInputs as $Token => $DigitalInput) { $Expansion = [ 'type' => 'ExpansionPanel', diff --git a/ONVIF Digital Output/module.php b/ONVIF Digital Output/module.php index a81df13..7dfa9fe 100644 --- a/ONVIF Digital Output/module.php +++ b/ONVIF Digital Output/module.php @@ -16,8 +16,8 @@ public function Create(): void { //Never delete this line! parent::Create(); - $this->RegisterAttributeArray('RelayOutputs', []); - $this->RegisterPropertyBoolean('EmulateStatus', false); + $this->RegisterPropertyBoolean(\ONVIF\Output\Property::EmulateStatus, false); + $this->RegisterAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, []); } public function ApplyChanges(): void @@ -27,7 +27,7 @@ public function ApplyChanges(): void if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); return; } @@ -44,14 +44,14 @@ public function ApplyChanges(): void $this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management]; $this->wsdl = \ONVIF\WSDL::Management; } - $this->WriteAttributeArray('RelayOutputs', $Capabilities['RelayOutputs']); + $this->WriteAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, $Capabilities['RelayOutputs']); foreach ($Capabilities['RelayOutputs'] as $Name => $RelayOutput) { $Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name); $Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident); $this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0); $this->EnableAction($Ident); } - $Events = $this->ReadAttributeArray('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (count($Events) != 1) { $this->SetStatus(IS_EBASE + 1); } else { @@ -64,7 +64,7 @@ public function ApplyChanges(): void public function SetRelayOutputState(string $Ident, bool $Value): bool { - if (!array_key_exists($Ident, $this->ReadAttributeArray('RelayOutputs'))) { + if (!array_key_exists($Ident, $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs))) { set_error_handler([$this, 'ModulErrorHandler']); trigger_error($this->Translate('Invalid Ident'), E_USER_NOTICE); restore_error_handler(); @@ -79,7 +79,7 @@ public function SetRelayOutputState(string $Ident, bool $Value): bool if ($Result == false) { return false; } - if ($this->ReadPropertyBoolean('EmulateStatus')) { + if ($this->ReadPropertyBoolean(\ONVIF\Output\Property::EmulateStatus)) { $this->SetValueBoolean($Ident, $Value); } return true; @@ -100,7 +100,7 @@ public function ReceiveData(string $JSONString): string $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $Events = $this->ReadAttributeArray('EventProperties'); + $Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); $EventProperty = array_pop($Events); $SourceIndex = array_search('tt:ReferenceToken', array_column($EventProperty['Sources'], 'Type')); if ($SourceIndex === false) { @@ -135,7 +135,7 @@ public function GetConfigurationForm(): string } $Form['elements'][0] = $this->GetConfigurationFormEventTopic($Form['elements'][0]); $Actions = [['type' => 'TestCenter']]; - $RelayOutputs = $this->ReadAttributeArray('RelayOutputs'); + $RelayOutputs = $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs); foreach ($RelayOutputs as $Token => $RelayOutput) { $Expansion = [ 'type' => 'ExpansionPanel', diff --git a/ONVIF Discovery/module.php b/ONVIF Discovery/module.php index 727f7a7..f4db650 100644 --- a/ONVIF Discovery/module.php +++ b/ONVIF Discovery/module.php @@ -45,8 +45,8 @@ public function Create(): void { //Never delete this line! parent::Create(); - $this->RegisterAttributeString('Username', ''); - $this->RegisterAttributeString('Password', ''); + $this->RegisterAttributeString(\ONVIF\Discovery\Attribute::Username, ''); + $this->RegisterAttributeString(\ONVIF\Discovery\Attribute::Password, ''); $this->Devices = []; $this->DevicesError = []; $this->DevicesTotal = 0; @@ -87,8 +87,8 @@ public function GetConfigurationForm(): string return json_encode($Form); } - $Form['actions'][0]['items'][0]['items'][0]['value'] = $this->ReadAttributeString('Username'); - $Form['actions'][0]['items'][0]['items'][1]['value'] = $this->ReadAttributeString('Password'); + $Form['actions'][0]['items'][0]['items'][0]['value'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username); + $Form['actions'][0]['items'][0]['items'][1]['value'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password); if (!$this->DiscoveryIsRunning) { $ScriptText = 'IPS_RequestAction(' . $this->InstanceID . ', \'StartDiscover\',true);'; IPS_RunScriptText($ScriptText); @@ -103,8 +103,8 @@ public function RequestAction(string $Ident, mixed $Value): void if ($Ident == 'Save') { $this->DiscoveryIsRunning = false; $Data = explode(':', $Value); - $this->WriteAttributeString('Username', urldecode($Data[0])); - $this->WriteAttributeString('Password', urldecode($Data[1])); + $this->WriteAttributeString(\ONVIF\Discovery\Attribute::Username, urldecode($Data[0])); + $this->WriteAttributeString(\ONVIF\Discovery\Attribute::Password, urldecode($Data[1])); $this->EnableErrorPopup = true; $this->UpdateFormField('NotFoundPopup', 'visible', false); $this->UpdateFormField('ProgressPopup', 'visible', true); @@ -126,7 +126,7 @@ public function RequestAction(string $Ident, mixed $Value): void } protected function GetConfigurationValues(): array { - $InstanceIDListConfigurator = IPS_GetInstanceListByModuleID('{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}'); + $InstanceIDListConfigurator = IPS_GetInstanceListByModuleID(\ONVIF\GUID::Configurator); $DevicesAddress = []; $DeviceValues = []; foreach ($InstanceIDListConfigurator as $InstanceIDConfigurator) { @@ -160,16 +160,16 @@ protected function GetConfigurationValues(): array $AddDevice['instanceID'] = $InstanceIDConfigurator; unset($DevicesAddress[$InstanceIDConfigurator]); } else { - $ConfigIo['Username'] = $this->ReadAttributeString('Username'); - $ConfigIo['Password'] = $this->ReadAttributeString('Password'); + $ConfigIo['Username'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username); + $ConfigIo['Password'] = $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password); } $AddDevice['create'][$Device['Name'] . ' (' . $Address . ')'] = [ [ - 'moduleID' => '{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}', + 'moduleID' => \ONVIF\GUID::Configurator, 'configuration' => new stdClass() ], [ - 'moduleID' => '{F40CA9A7-3B4D-4B26-7214-3A94B6074DFB}', + 'moduleID' => \ONVIF\GUID::IO, 'name' => $Device['Name'], 'configuration' => $ConfigIo ] @@ -324,7 +324,7 @@ protected function DiscoverDevices(): array protected function ScanDevice(string $IP, array $IpValues): void { $UseLogin = false; - if (($this->ReadAttributeString('Username') != '') || ($this->ReadAttributeString('Password') != '')) { + if (($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username) != '') || ($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password) != '')) { $UseLogin = true; } $wsdl = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'WSDL' . DIRECTORY_SEPARATOR . \ONVIF\WSDL::Management; @@ -336,8 +336,8 @@ protected function ScanDevice(string $IP, array $IpValues): void $this->SendDebug('Request', $IpValue, 0); if ($UseLogin) { $offset = $this->GetTimeOffset($IpValue); - $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadAttributeString('Username'), $this->ReadAttributeString('Password'), $offset); - $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service', $this->ReadAttributeString('Username'), $this->ReadAttributeString('Password'), $Header); + $Header[] = \ONVIF\ONVIF::soapClientWSSecurityHeader($this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username), $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password), $offset); + $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service', $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Username), $this->ReadAttributeString(\ONVIF\Discovery\Attribute::Password), $Header); } else { $ONVIFClient = new \ONVIF\ONVIF($wsdl, $IpValue . '/onvif/device_service'); } diff --git a/ONVIF Events/module.php b/ONVIF Events/module.php index 05d0d22..59250a5 100644 --- a/ONVIF Events/module.php +++ b/ONVIF Events/module.php @@ -18,10 +18,10 @@ public function ApplyChanges(): void if (IPS_GetKernelRunlevel() != KR_READY) { return; } - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $this->SetStatus(IS_INACTIVE); } else { - $Events = $this->GetEvents($this->ReadPropertyString('EventTopic')); + $Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic)); $this->SendDebug('EventConfig', $Events, 0); if (count($Events) == 0) { $this->SetStatus(IS_INACTIVE); @@ -36,11 +36,11 @@ public function ReceiveData(string $JSONString): string $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return ''; } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); return ''; } diff --git a/ONVIF IO/module.php b/ONVIF IO/module.php index 4680c05..716f2eb 100644 --- a/ONVIF IO/module.php +++ b/ONVIF IO/module.php @@ -1991,7 +1991,7 @@ protected function DecodeNotificationMessage(string $NotificationMessageXML): bo protected function SendEventDataArrayToChildren(array $EventDataArray): void { foreach ($EventDataArray as $EventData) { - $EventData['DataID'] = '{E23DD2CD-F098-268A-CE49-1CC04FE8060B}'; + $EventData['DataID'] = \ONVIF\DataFlow\GUID::SendEvents; $this->SendDataToChildren(json_encode($EventData)); } } diff --git a/ONVIF Image Grabber/module.php b/ONVIF Image Grabber/module.php index 8b3971b..1706028 100644 --- a/ONVIF Image Grabber/module.php +++ b/ONVIF Image Grabber/module.php @@ -8,18 +8,18 @@ */ class ONVIFImageGrabber extends ONVIFModuleBase { - public const wsdl = \ONVIF\WSDL::Media; //'media-mod'; + public const wsdl = \ONVIF\WSDL::Media; public const TopicFilter = 'videosource'; public function Create(): void { //Never delete this line! parent::Create(); - $this->RegisterPropertyString('VideoSource', ''); - $this->RegisterPropertyString('Profile', ''); - $this->RegisterPropertyInteger('Interval', 0); - $this->RegisterPropertyBoolean('UseCaching', true); - $this->RegisterTimer('UpdateImage', 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');'); + $this->RegisterPropertyString(\ONVIF\ImageGrabber\Property::VideoSource, ''); + $this->RegisterPropertyString(\ONVIF\ImageGrabber\Property::Profile, ''); + $this->RegisterPropertyInteger(\ONVIF\ImageGrabber\Property::Interval, 0); + $this->RegisterPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching, true); + $this->RegisterTimer(\ONVIF\ImageGrabber\Timer::UpdateImage, 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');'); $this->ImageURL = false; } public function ApplyChanges(): void @@ -27,16 +27,16 @@ public function ApplyChanges(): void //Never delete this line! parent::ApplyChanges(); $MediaId = $this->GetMediaId(); - IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean('UseCaching')); + IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching)); - if ($this->ReadPropertyString('VideoSource') == '') { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') { $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); return; } - if ($this->ReadPropertyString('Profile') == '') { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') { $this->SetStatus(IS_INACTIVE); - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); return; } if (IPS_GetKernelRunlevel() != KR_READY) { @@ -47,9 +47,9 @@ public function ApplyChanges(): void if ($SnapshotURL) { $this->SetStatus(IS_ACTIVE); $this->UpdateImage(); - $this->SetTimerInterval('UpdateImage', $this->ReadPropertyInteger('Interval') * 1000); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000); } else { - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); $this->SetStatus(IS_EBASE + 1); } } @@ -92,7 +92,7 @@ public function ReceiveData(string $JSONString): string $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return ''; } @@ -111,7 +111,7 @@ public function ReceiveData(string $JSONString): string if ($EventProperty['Sources'][$SourceIndex]['Type'] != 'tt:ReferenceToken') { continue; } - if ($Source['Value'] != $this->ReadPropertyString('VideoSource')) { + if ($Source['Value'] != $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource)) { $SkipEvent = true; continue; } @@ -124,7 +124,7 @@ public function ReceiveData(string $JSONString): string if ($SkipEvent) { return ''; } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); return ''; } @@ -177,14 +177,14 @@ public function GetConfigurationForm(): string 'caption' => $VideoSource['VideoSourceName'], 'value' => $VideoSource['VideoSourceToken'] ]; - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == $VideoSource['VideoSourceToken']) { $ActualSources = $VideoSource; foreach ($VideoSource['Profile'] as $Profile) { $ProfileOptions[] = [ 'caption' => $Profile['Name'], 'value' => $Profile['token'] ]; - if ($this->ReadPropertyString('Profile') == $Profile['token']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == $Profile['token']) { $ActualProfile = $Profile; } } @@ -336,7 +336,7 @@ public function RequestAction(string $Ident, mixed $Value, bool &$done = false): case 'RefreshProfileForm': $this->RefreshProfileForm($Value); return; - case 'UpdateImage': + case \ONVIF\ImageGrabber\Timer::UpdateImage: $this->UpdateImage(); if ((bool) $Value) { $this->ReloadForm(); @@ -349,7 +349,7 @@ protected function IOChangeState(int $State): void parent::IOChangeState($State); if ($State == IS_INACTIVE) { - $this->SetTimerInterval('UpdateImage', 0); + $this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0); } } protected function RefreshProfileForm(string $NewVideoSource): void @@ -383,9 +383,9 @@ protected function GetSnapshotUri(): false|string return false; } foreach ($Capabilities['VideoSourcesJPEG'] as $VideoSource) { - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == $VideoSource['VideoSourceToken']) { foreach ($VideoSource['Profile'] as $Profile) { - if ($Profile['token'] == $this->ReadPropertyString('Profile')) { + if ($Profile['token'] == $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile)) { break; } } @@ -393,7 +393,7 @@ protected function GetSnapshotUri(): false|string } } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) ]; if (($Capabilities['XAddr'][\ONVIF\NS::Media2]) != '') { diff --git a/ONVIF Media Stream/module.php b/ONVIF Media Stream/module.php index b2a8fcd..2fa9d06 100644 --- a/ONVIF Media Stream/module.php +++ b/ONVIF Media Stream/module.php @@ -26,35 +26,35 @@ public function Create(): void //Never delete this line! parent::Create(); //Stream - $this->RegisterPropertyString('VideoSource', ''); - $this->RegisterPropertyString('Profile', ''); + $this->RegisterPropertyString(\ONVIF\Stream\Property::VideoSource, ''); + $this->RegisterPropertyString(\ONVIF\Stream\Property::Profile, ''); // Invert Controls - $this->RegisterPropertyBoolean('InvertPanControl', false); - $this->RegisterPropertyBoolean('InvertTiltControl', false); - $this->RegisterPropertyBoolean('InvertZoomControl', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl, false); //IPS Variables - $this->RegisterPropertyBoolean('EnablePanTiltVariable', false); - $this->RegisterPropertyBoolean('EnableZoomVariable', false); - $this->RegisterPropertyBoolean('EnableSpeedVariable', false); - $this->RegisterPropertyBoolean('EnableTimeVariable', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableZoomVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableSpeedVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable, false); //HTML-Box - $this->RegisterPropertyBoolean('EnablePanTiltHTML', false); - $this->RegisterPropertyBoolean('EnableZoomHTML', false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML, false); //SVG-Design in HTML-Box - $this->RegisterPropertyInteger('PanTiltControlWidth', 100); - $this->RegisterPropertyInteger('PanTiltControlHeight', 100); - $this->RegisterPropertyInteger('PanTiltControlOpacity', 60); - $this->RegisterPropertyInteger('ZoomControlWidth', 50); - $this->RegisterPropertyInteger('ZoomControlHeight', 100); - $this->RegisterPropertyInteger('ZoomControlOpacity', 60); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlWidth, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlHeight, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::PanTiltControlOpacity, 60); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlWidth, 50); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlHeight, 100); + $this->RegisterPropertyInteger(\ONVIF\Stream\Property::ZoomControlOpacity, 60); //Default Speed - $this->RegisterPropertyFloat('PanDefaultSpeed', 1); - $this->RegisterPropertyFloat('TiltDefaultSpeed', 1); - $this->RegisterPropertyFloat('ZoomDefaultSpeed', 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed, 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed, 1); + $this->RegisterPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed, 1); // Presets - $this->RegisterPropertyBoolean('EnablePresetVariable', false); - $this->RegisterPropertyBoolean('EnablePresetProfile', false); - $this->RegisterPropertyString('PresetProfile', json_encode([])); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable, false); + $this->RegisterPropertyBoolean(\ONVIF\Stream\Property::EnablePresetProfile, false); + $this->RegisterPropertyString(\ONVIF\Stream\Property::PresetProfile, json_encode([])); // Buffer $this->PTZ_token = ''; $this->PTZ_xAddr = ''; @@ -140,12 +140,12 @@ public function ApplyChanges(): void $this->PresetTokenList = []; $this->AuthorizationKey = ''; - if ($this->ReadPropertyString('VideoSource') == '') { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == '') { $this->SetStatus(IS_INACTIVE); $this->SetMedia(''); return; } - if ($this->ReadPropertyString('Profile') == '') { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == '') { $this->SetStatus(IS_INACTIVE); $this->SetMedia(''); return; @@ -163,35 +163,35 @@ public function ApplyChanges(): void $this->SetStatus(IS_EBASE + 1); } - if ($this->ReadPropertyBoolean('EnablePanTiltHTML') || $this->ReadPropertyBoolean('EnableZoomHTML')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML) || $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML)) { $this->RegisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); $this->WritePTZInHTMLBox(); } else { $this->UnregisterHook('/hook/ONVIF/PTZ/' . $this->InstanceID); $this->UnregisterVariable('PTZControlHtml'); } - if ($this->ReadPropertyBoolean('EnablePanTiltVariable')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltVariable)) { $this->RegisterVariableInteger('PT', $this->Translate('Move'), 'ONVIF.PanTilt', 3); $this->SetValueInteger('PT', 2); $this->EnableAction('PT'); } else { $this->UnregisterVariable('PT'); } - if ($this->ReadPropertyBoolean('EnableZoomVariable')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomVariable)) { $this->RegisterVariableInteger('ZOOM', $this->Translate('Zoom'), 'ONVIF.Zoom', 4); $this->SetValueInteger('ZOOM', 1); $this->EnableAction('ZOOM'); } else { $this->UnregisterVariable('ZOOM'); } - if ($this->ReadPropertyBoolean('EnableSpeedVariable')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableSpeedVariable)) { $this->RegisterVariableFloat('SPEED', $this->Translate('Speed'), 'ONVIF.Speed', 1); $this->SetValueFloat('SPEED', 0); $this->EnableAction('SPEED'); } else { $this->UnregisterVariable('SPEED'); } - if ($this->ReadPropertyBoolean('EnableTimeVariable')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableTimeVariable)) { $this->RegisterVariableFloat('TIME', $this->Translate('Time'), 'ONVIF.Time', 2); $this->SetValueFloat('TIME', 0); $this->EnableAction('TIME'); @@ -199,9 +199,9 @@ public function ApplyChanges(): void $this->UnregisterVariable('TIME'); } $PresetProfileName = 'ONVIF.Preset.' . $this->InstanceID; - if ($this->ReadPropertyBoolean('EnablePresetVariable')) { - $UsePresetName = $this->ReadPropertyBoolean('EnablePresetProfile'); - $Presets = json_decode($this->ReadPropertyString('PresetProfile')); + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable)) { + $UsePresetName = $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetProfile); + $Presets = json_decode($this->ReadPropertyString(\ONVIF\Stream\Property::PresetProfile)); $PresetTokenList = []; $PresetAssociations = []; foreach ($Presets as $Preset) { @@ -274,14 +274,14 @@ public function GetConfigurationForm(): string 'caption' => $VideoSource['VideoSourceName'], 'value' => $VideoSource['VideoSourceToken'] ]; - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == $VideoSource['VideoSourceToken']) { $ActualSources = $VideoSource; foreach ($VideoSource['Profile'] as $Profile) { $ProfileOptions[] = [ 'caption' => $Profile['Name'], 'value' => $Profile['token'] ]; - if ($this->ReadPropertyString('Profile') == $Profile['token']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::Profile) == $Profile['token']) { $ActualProfile = $Profile; } } @@ -564,8 +564,8 @@ public function GetConfigurationForm(): string ]; $Form['actions'] = array_merge($Actions, $Form['actions']); } - $Form['elements'][4]['popup']['items'][1]['visible'] = $this->ReadPropertyBoolean('EnablePresetVariable'); - $PresetProfile = json_decode($this->ReadPropertyString('PresetProfile'), true); + $Form['elements'][4]['popup']['items'][1]['visible'] = $this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePresetVariable); + $PresetProfile = json_decode($this->ReadPropertyString(\ONVIF\Stream\Property::PresetProfile), true); $ValidTokens = array_column($PTZValues, 'PresetToken'); foreach ($PresetProfile as &$Profile) { $KnownToken = array_search($Profile['PresetToken'], $ValidTokens); @@ -614,13 +614,13 @@ public function MoveLeftSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('PanDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertPanControl') ? $Speed : -$Speed), + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl) ? $Speed : -$Speed), 'y' => 0 ] ] @@ -648,13 +648,13 @@ public function MoveRightSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('PanDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::PanDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertPanControl') ? -$Speed : $Speed), + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertPanControl) ? -$Speed : $Speed), 'y' => 0 ] ] @@ -683,14 +683,14 @@ public function MoveUpSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('TiltDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ 'x' => 0, - 'y' => (!$this->ReadPropertyBoolean('InvertTiltControl') ? $Speed : -$Speed) + 'y' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl) ? $Speed : -$Speed) ] ] ]; @@ -719,14 +719,14 @@ public function MoveDownSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('TiltDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::TiltDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'PanTilt' => [ 'x' => 0, - 'y' => (!$this->ReadPropertyBoolean('InvertTiltControl') ? -$Speed : $Speed) + 'y' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertTiltControl) ? -$Speed : $Speed) ] ] ]; @@ -753,13 +753,13 @@ public function ZoomNearSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('ZoomDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'Zoom' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertZoomControl') ? $Speed : -$Speed) + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl) ? $Speed : -$Speed) ] ] ]; @@ -786,13 +786,13 @@ public function ZoomFarSpeedTime(float $Speed, float $Time): bool return false; } if ($Speed == 0) { - $Speed = $this->ReadPropertyFloat('ZoomDefaultSpeed'); + $Speed = $this->ReadPropertyFloat(\ONVIF\Stream\Property::ZoomDefaultSpeed); } $Params = [ - 'ProfileToken' => $this->ReadPropertyString('Profile'), + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Velocity' => [ 'Zoom' => [ - 'x' => (!$this->ReadPropertyBoolean('InvertZoomControl') ? -$Speed : $Speed) + 'x' => (!$this->ReadPropertyBoolean(\ONVIF\Stream\Property::InvertZoomControl) ? -$Speed : $Speed) ] ] ]; @@ -806,7 +806,7 @@ public function StopPTZ(): bool if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PanTilt' => true, 'Zoom' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PanTilt' => true, 'Zoom' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -815,7 +815,7 @@ public function MoveStop(): bool if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PanTilt' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PanTilt' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -824,7 +824,7 @@ public function ZoomStop(): bool if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'Zoom' => true]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'Zoom' => true]; return $this->SendData($this->PTZ_xAddr, 'Stop', true, $Params, self::PTZwsdl); } @@ -846,7 +846,7 @@ public function GotoPresetToken(string $PresetToken): bool if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile'), 'PresetToken' => $PresetToken]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile), 'PresetToken' => $PresetToken]; return $this->SendData($this->PTZ_xAddr, 'GotoPreset', true, $Params, self::PTZwsdl); } @@ -855,7 +855,7 @@ public function GotoPresetHomePosition(): bool if ($this->PTZ_token == '') { return false; } - $Params = ['ProfileToken' => $this->ReadPropertyString('Profile')]; + $Params = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)]; return $this->SendData($this->PTZ_xAddr, 'GotoHomePosition', true, $Params, self::PTZwsdl); } @@ -953,7 +953,7 @@ public function ReceiveData(string $JSONString): string $Data = json_decode($JSONString, true); unset($Data['DataID']); $this->SendDebug('ReceiveEvent', $Data, 0); - $EventProperties = $this->ReadAttributeArray('EventProperties'); + $EventProperties = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties); if (!array_key_exists($Data['Topic'], $EventProperties)) { return ''; } @@ -971,7 +971,7 @@ public function ReceiveData(string $JSONString): string if ($EventProperty['Sources'][$SourceIndex]['Type'] != 'tt:ReferenceToken') { continue; } - if ($Source['Value'] != $this->ReadPropertyString('VideoSource')) { + if ($Source['Value'] != $this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource)) { continue; } $FoundEventIndex = $SourceIndex; @@ -980,7 +980,7 @@ public function ReceiveData(string $JSONString): string if ($FoundEventIndex !== false) { unset($Data['Sources'][$FoundEventIndex]); } - $PreName = str_replace($this->ReadPropertyString('EventTopic'), '', $Data['Topic']); + $PreName = str_replace($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic), '', $Data['Topic']); $this->SetEventStatusVariable($PreName, $EventProperties[$Data['Topic']], $Data); return ''; } @@ -1051,7 +1051,7 @@ protected function GetPTZCapabilities(): bool } } // Presets - $ProfileToken = ['ProfileToken' => $this->ReadPropertyString('Profile')]; + $ProfileToken = ['ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)]; $PresetResult = @$this->SendData($this->PTZ_xAddr, 'GetPresets', true, $ProfileToken, self::PTZwsdl); ob_clean(); if (is_bool($PresetResult)) { @@ -1081,9 +1081,9 @@ protected function GetStreamUri(): false|string } $this->PTZ_xAddr = $Capabilities['XAddr'][\ONVIF\NS::PTZ]; foreach ($Capabilities['VideoSources'] as $VideoSource) { - if ($this->ReadPropertyString('VideoSource') == $VideoSource['VideoSourceToken']) { + if ($this->ReadPropertyString(\ONVIF\Stream\Property::VideoSource) == $VideoSource['VideoSourceToken']) { foreach ($VideoSource['Profile'] as $Profile) { - if ($Profile['token'] == $this->ReadPropertyString('Profile')) { + if ($Profile['token'] == $this->ReadPropertyString(\ONVIF\Stream\Property::Profile)) { $this->PTZ_token = $Profile['ptztoken']; break; } @@ -1095,7 +1095,7 @@ protected function GetStreamUri(): false|string if (($Capabilities['XAddr'][\ONVIF\NS::Media2]) != '') { $Params = [ 'Protocol' => 'RtspUnicast', - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile) ]; $Result = $this->SendData($Capabilities['XAddr'][\ONVIF\NS::Media2], 'GetStreamUri', true, $Params, \ONVIF\WSDL::Media2); if ($Result == false) { @@ -1114,7 +1114,7 @@ protected function GetStreamUri(): false|string 'Protocol' => 'RTSP', ], ], - 'ProfileToken' => $this->ReadPropertyString('Profile') + 'ProfileToken' => $this->ReadPropertyString(\ONVIF\Stream\Property::Profile) ]; $Result = $this->SendData($Capabilities['XAddr'][\ONVIF\NS::Media], 'GetStreamUri', true, $Params); if ($Result == false) { @@ -1165,7 +1165,7 @@ protected function WritePTZInHTMLBox(): void $Key = urlencode($Key); $ImgSrc = ''; $PanTiltSVG = ''; - if ($this->ReadPropertyBoolean('EnablePanTiltHTML')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnablePanTiltHTML)) { $PanTiltSVG = str_replace( [ '%%InstanceId%%', @@ -1175,15 +1175,15 @@ protected function WritePTZInHTMLBox(): void ], [ $this->InstanceID, - $this->ReadPropertyInteger('PanTiltControlWidth'), - $this->ReadPropertyInteger('PanTiltControlHeight'), - sprintf('%F', $this->ReadPropertyInteger('PanTiltControlOpacity') / 100) + $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlWidth), + $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlHeight), + sprintf('%F', $this->ReadPropertyInteger(\ONVIF\Stream\Property::PanTiltControlOpacity) / 100) ], file_get_contents(__DIR__ . '/../libs/PanTiltControl.svg') ); } $ZoomSVG = ''; - if ($this->ReadPropertyBoolean('EnableZoomHTML')) { + if ($this->ReadPropertyBoolean(\ONVIF\Stream\Property::EnableZoomHTML)) { $ZoomSVG = str_replace( [ '%%InstanceId%%', @@ -1193,9 +1193,9 @@ protected function WritePTZInHTMLBox(): void ], [ $this->InstanceID, - $this->ReadPropertyInteger('ZoomControlWidth'), - $this->ReadPropertyInteger('ZoomControlHeight'), - sprintf('%F', $this->ReadPropertyInteger('ZoomControlOpacity') / 100) + $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlWidth), + $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlHeight), + sprintf('%F', $this->ReadPropertyInteger(\ONVIF\Stream\Property::ZoomControlOpacity) / 100) ], file_get_contents(__DIR__ . '/../libs/ZoomControl.svg') ); diff --git a/libs/ONVIFModuleBase.php b/libs/ONVIFModuleBase.php index d92291d..335cd09 100644 --- a/libs/ONVIFModuleBase.php +++ b/libs/ONVIFModuleBase.php @@ -47,9 +47,9 @@ public function Create(): void { //Never delete this line! parent::Create(); - $this->RegisterPropertyString('EventTopic', ''); + $this->RegisterPropertyString(\ONVIF\Device\Property::EventTopic, ''); $this->EventTopic = ''; - $this->RegisterAttributeArray('EventProperties', []); + $this->RegisterAttributeArray(\ONVIF\Device\Attribute::EventProperties, []); if (IPS_GetKernelRunlevel() != KR_READY) { $this->RegisterMessage(0, IPS_KERNELSTARTED); } @@ -63,8 +63,8 @@ public function Destroy(): void public function ApplyChanges(): void { - $EventTopic = $this->ReadPropertyString('EventTopic'); - $PullEvents = ($EventTopic != $this->EventTopic); + $EventTopic = $this->ReadPropertyString(\ONVIF\Device\Property::EventTopic); + $SyncEvents = ($EventTopic != $this->EventTopic); //Never delete this line! parent::ApplyChanges(); $this->RegisterMessage($this->InstanceID, FM_CONNECT); @@ -83,8 +83,8 @@ public function ApplyChanges(): void } $this->RegisterParent(); $Events = $this->GetEvents($EventTopic); - $this->WriteAttributeArray('EventProperties', $Events); - if ($PullEvents && ($this->HasActiveParent())) { + $this->WriteAttributeArray(\ONVIF\Device\Attribute::EventProperties, $Events); + if ($SyncEvents && ($this->HasActiveParent())) { $this->$EventTopic = $EventTopic; IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"SetSynchronizationPoint",true);'); } @@ -135,7 +135,7 @@ protected function RegisterParent(): void protected function IOChangeState(int $State): void { if ($State == IS_ACTIVE) { - $this->EventTopic = $this->ReadPropertyString('EventTopic'); + $this->EventTopic = $this->ReadPropertyString(\ONVIF\Device\Property::EventTopic); $this->ApplyChanges(); $this->ReloadForm(); } @@ -155,7 +155,7 @@ protected function GetEvents(string $Pattern = '', int $InstanceID = -1, array $ } $this->SendDebug('GetEvents Pattern', $Pattern, 0); $this->SendDebug('GetEvents SkippedTopics', $SkippedTopics, 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetEvents', 'Pattern' => $Pattern, 'Instance' => $InstanceID, 'SkippedTopics' => $SkippedTopics]); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetEvents', 'Pattern' => $Pattern, 'Instance' => $InstanceID, 'SkippedTopics' => $SkippedTopics]); $answer = $this->SendDataToParent($Data); if ($answer !== false) { $answer = unserialize($answer); @@ -169,7 +169,7 @@ protected function SetSynchronizationPoint(): void if ($this->ParentID > 0) { if ($this->HasActiveParent()) { $this->SendDebug('SetSynchronizationPoint', '', 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'SetSynchronizationPoint']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'SetSynchronizationPoint']); $this->SendDataToParent($Data); } } @@ -179,7 +179,7 @@ protected function GetCapabilities(): array if ($this->ParentID > 0) { if ($this->HasActiveParent()) { $this->SendDebug('GetCapabilities', '', 0); - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetCapabilities']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetCapabilities']); $answer = $this->SendDataToParent($Data); if ($answer !== false) { $Result = unserialize($answer); @@ -224,7 +224,7 @@ protected function GetCredentials(): array { if ($this->ParentID > 0) { if ($this->HasActiveParent()) { - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetCredentials']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetCredentials']); $answer = $this->SendDataToParent($Data); if ($answer === false) { $this->SendDebug('GetCredentials', 'No valid answer', 0); @@ -239,7 +239,7 @@ protected function GetUrl(): string { if ($this->ParentID > 0) { if ($this->HasActiveParent()) { - $Data = json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'Function' => 'GetUrl']); + $Data = json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'Function' => 'GetUrl']); $answer = $this->SendDataToParent($Data); if ($answer === false) { $this->SendDebug('GetUrl', 'No valid answer', 0); @@ -266,7 +266,7 @@ protected function SendData(string $URI, string $Function, bool $UseLogin = fals $this->SendDebug('Send Function', $Function, 0); $this->SendDebug('Send Params', $Params, 0); $this->SendDebug('Send useLogin', $UseLogin, 0); - $Ret = $this->SendDataToParent(json_encode(['DataID' => '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}', 'URI' => $URI, 'Function' => $Function, 'Params' => $Params, 'useLogin' => $UseLogin, 'wsdl' => $wsdl])); + $Ret = $this->SendDataToParent(json_encode(['DataID' => \ONVIF\DataFlow\GUID::SendFunction, 'URI' => $URI, 'Function' => $Function, 'Params' => $Params, 'useLogin' => $UseLogin, 'wsdl' => $wsdl])); if ($Ret === false) { $this->SendDebug('Result', false, 0); return false; @@ -343,7 +343,7 @@ protected function GetConfigurationFormEventTopic(array $Form, bool $AddNothingI } $Form['options'] = $SelectTopic; $Form['enabled'] = (count($Events) > 1); - if ($this->ReadPropertyString('EventTopic') == '') { + if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') { $Form['enabled'] = true; } } diff --git a/libs/wsdl.php b/libs/wsdl.php index af7e6f2..32a7118 100644 --- a/libs/wsdl.php +++ b/libs/wsdl.php @@ -165,6 +165,25 @@ public function toString(): string return implode(', ', $Profiles); } } + class GUID + { + public const Configurator = '{C6A79C49-19D5-8D45-FFE5-5D77165FAEE6}'; + public const IO = '{F40CA9A7-3B4D-4B26-7214-3A94B6074DFB}'; + public const Input = '{73097230-1ECC-FEEB-5969-C85148DFA76E}'; + public const Output = '{A44B3114-1F72-1FD1-96FB-D7E970BD8614}'; + public const Stream = '{FA889450-38B6-7E20-D4DC-F2C6D0B074FB}'; + public const ImageGrabber = '{18EA97C1-3CEC-80B7-4CAA-D91F8A2A0599}'; + public const Event = '{62584C2E-4542-4EBF-1E92-299F4CF364E4}'; + } +} + +namespace ONVIF\Discovery +{ + class Attribute + { + public const Username = 'Username'; + public const Password = 'Password'; + } } namespace ONVIF\IO @@ -219,59 +238,92 @@ class Timer class State { public const INACTIVE = 'Interface closed'; - public const ACTIVE ='Interface connected'; + public const ACTIVE = 'Interface connected'; public const CONNECTION_LOST = 'Connection lost'; } } +namespace ONVIF\DataFlow{ + class GUID + { + public const SendEvents = '{E23DD2CD-F098-268A-CE49-1CC04FE8060B}'; + public const SendFunction = '{9B9C8DA6-BC89-21BC-3E8C-BA6E534ABC37}'; + } +} + namespace ONVIF\Device { class Property { public const EventTopic = 'EventTopic'; - /* public const Address = 'Address'; - public const Username = 'Username'; - public const Password = 'Password'; - public const EventHandler = 'EventHandler'; - public const WebHookIP = 'WebHookIP'; - public const WebHookHTTPS = 'WebHookHTTPS'; - public const WebHookPort = 'WebHookPort'; - public const SubscribeEventTimeout = 'SubscribeEventTimeout'; - public const SubscribeInitialTerminationTime = 'SubscribeInitialTerminationTime'; - public const PullPointInitialTerminationTime = 'PullPointInitialTerminationTime'; - public const PullPointTimeout = 'PullPointTimeout'; - public const MessageLimit = 'MessageLimit'; - */ - } class Attribute { public const EventProperties = 'EventProperties'; - /* public const NbrOfInputs = 'NbrOfInputs'; - public const NbrOfOutputs = 'NbrOfOutputs'; - public const NbrOfVideoSources = 'NbrOfVideoSources'; - public const NbrOfAudioSources = 'NbrOfAudioSources'; - public const NbrOfSerialPorts = 'NbrOfSerialPorts'; - public const HasSnapshotUri = 'HasSnapshotUri'; - public const HasRTSPStreaming = 'HasRTSPStreaming'; - public const RuleSupport = 'RuleSupport'; - public const AnalyticsModuleSupport = 'AnalyticsModuleSupport'; - public const WSSubscriptionPolicySupport = 'WSSubscriptionPolicySupport'; - public const WSPullPointSupport = 'WSPullPointSupport'; - public const ConsumerAddress = 'ConsumerAddress'; - public const SubscriptionReference = 'SubscriptionReference'; - public const SubscriptionId = 'SubscriptionId'; - public const CapabilitiesVersion = 'CapabilitiesVersion'; - */ + } +} + +namespace ONVIF\Stream +{ + class Property + { + public const VideoSource = 'VideoSource'; + public const Profile = 'Profile'; + public const InvertPanControl = 'InvertPanControl'; + public const InvertTiltControl = 'InvertTiltControl'; + public const InvertZoomControl = 'InvertZoomControl'; + public const EnablePanTiltVariable = 'EnablePanTiltVariable'; + public const EnableZoomVariable = 'EnableZoomVariable'; + public const EnableSpeedVariable = 'EnableSpeedVariable'; + public const EnableTimeVariable = 'EnableTimeVariable'; + public const EnablePanTiltHTML = 'EnablePanTiltHTML'; + public const EnableZoomHTML = 'EnableZoomHTML'; + public const PanTiltControlWidth = 'PanTiltControlWidth'; + public const PanTiltControlHeight = 'PanTiltControlHeight'; + public const PanTiltControlOpacity = 'PanTiltControlOpacity'; + public const ZoomControlWidth = 'ZoomControlWidth'; + public const ZoomControlHeight = 'ZoomControlHeight'; + public const ZoomControlOpacity = 'ZoomControlOpacity'; + public const PanDefaultSpeed = 'PanDefaultSpeed'; + public const TiltDefaultSpeed = 'TiltDefaultSpeed'; + public const ZoomDefaultSpeed = 'ZoomDefaultSpeed'; + public const EnablePresetVariable = 'EnablePresetVariable'; + public const EnablePresetProfile = 'EnablePresetProfile'; + public const PresetProfile = 'PresetProfile'; + } +} + +namespace ONVIF\ImageGrabber +{ + class Property + { + public const VideoSource = 'VideoSource'; + public const Profile = 'Profile'; + public const Interval = 'Interval'; + public const UseCaching = 'UseCaching'; } class Timer { - public const RenewSubscription = 'RenewSubscription'; + public const UpdateImage = 'UpdateImage'; } - class State +} + +namespace ONVIF\Input +{ + class Attribute { - public const INACTIVE = 'Interface closed'; - public const ACTIVE ='Interface connected'; - public const CONNECTION_LOST = 'Connection lost'; + public const DigitalInputs = 'DigitalInputs'; } } + +namespace ONVIF\Output +{ + class Property + { + public const EmulateStatus = 'EmulateStatus'; + } + class Attribute + { + public const RelayOutputs = 'RelayOutputs'; + } +} \ No newline at end of file