node-red-contrib-hikvision-ultimate
Version:
A native set of nodes for Hikvision (and compatible) Cameras, Alarms, Radars, NVR, Doorbells, etc.
224 lines (197 loc) • 10.9 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('Hikvision-config', {
category: 'config',
defaults: {
host: { value: "", required: true },
port: { value: 80, required: true, validate: RED.validators.number() },
name: { value: "Server" },
authentication: { value: "digest" },
protocol: { value: "http" },
heartbeattimerdisconnectionlimit: { value: 2 },
deviceinfo: { value: {} },
debuglevel: { value: "no" },
streamtimeout: { value: 3 }
},
credentials: {
user: { type: "text" },
password: { type: "password" }
},
oneditprepare: function () {
var node = this;
const timeoutSelect = $("#node-config-input-streamtimeout");
timeoutSelect.empty();
timeoutSelect.append('<option value="0">No Timeout (not recommended)</option>');
for (let i = 1; i <= 20; i++) {
const label = i === 1 ? '1 minute' : `${i} minutes`;
timeoutSelect.append(`<option value="${i}">${label}</option>`);
}
const storedTimeout = node.streamtimeout !== undefined ? node.streamtimeout : 3;
timeoutSelect.val(storedTimeout.toString());
// // Get the online devices
// $.getJSON("hikvisionUltimateDiscoverOnlineDevices", (data) => {
// try {
// data.forEach(element => {
// $("#node-config-input-discoverOnLineDevices").val(element.DeviceDescription + " IP:" + element.IPv4Address + " " + element.SoftwareVersion + " Port:" + element.HttpPort + "\n" + $("#node-config-input-discoverOnLineDevices").val());
// });
// } catch (error) {
// }
// }).error(function (jqXHR, textStatus, errorThrown) {
// RED.notify("THIS IS YOUR FIRST CAMERA NODE EVER. PLEASE SAVE AND DEPLOY. THEN REOPEN THIS WINDOW AGAIN.",
// {
// modal: false,
// fixed: false,
// type: 'warning'
// })
// });
$("#getinfocam").click(function () {
this.value = "Wait...";
this.disabled = true;
// If the node is newly created, the backend cannot get the infos, so i must pass each parameter back
var sQueryString = "";
var jManipulate = {};
// Read all data needed to backend to call the camera URL
jManipulate.host = $("#node-config-input-host").val();
jManipulate.port = $("#node-config-input-port").val();
jManipulate.protocol = $("#node-config-input-protocol").val();
jManipulate.user = $("#node-config-input-user").val();
jManipulate.password = $("#node-config-input-password").val();
jManipulate.authentication = $("#node-config-input-authentication").val();
sQueryString = "?nodeID=" + node.id + "¶ms=" + encodeURIComponent(JSON.stringify(jManipulate));
$.getJSON("hikvisionUltimateGetInfoCam" + sQueryString, (data) => {
this.value = "Connect";
this.disabled = false;
if (!data.hasOwnProperty("DeviceInfo")) {
RED.notify("Problem reading infostream from camera: " + JSON.stringify(data) + ". Check your credentials and connection properties.",
{
modal: false,
fixed: false,
type: 'warning'
});
return;
}
$("#node-config-input-name").val(data.DeviceInfo.deviceName);
$("#node-config-input-deviceinfo").val(JSON.stringify(data));
$("#labeldeviceinfo").html("<b>DEVICE INFORMATION</b><br/>Name: <b>" + data.DeviceInfo.deviceName + "</b><br/>Model: <b>" + data.DeviceInfo.model + "</b><br/>Firmware: <b>" + data.DeviceInfo.firmwareVersion + "</b>");
}).error(function (jqXHR, textStatus, errorThrown) {
RED.notify("THIS IS YOUR FIRST CAMERA NODE EVER. PLEASE SAVE AND DEPLOY. THEN REOPEN THIS WINDOW AGAIN.",
{
modal: false,
fixed: false,
type: 'warning'
})
});
});
var dati = JSON.parse(this.deviceinfo);
if (dati !== null) {
try {
$("#labeldeviceinfo").html("<b>LAST DEVICE INFORMATION SAVED</b><br/>Name: <b>" + dati.DeviceInfo.deviceName + "</b><br/>Model: <b>" + dati.DeviceInfo.model + "</b><br/>Firmware: <b>" + dati.DeviceInfo.firmwareVersion + "</b>");
} catch (error) { }
}
},
oneditsave: function () {
},
label: function () {
return typeof this.name === undefined ? (this.host + ":" + this.port) : this.name + " " + (this.host + ":" + this.port);
}
});
</script>
<script type="text/html" data-template-name="Hikvision-config">
<div class="form-row">
<b>Server config</b>    <span style="color:red"><i class="fa fa-question-circle"></i> <a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-hikvision-ultimate"><u>Help online</u></a></span>
<br/>
<br/>
</div>
<!--
<div class="form-row">
<label for="node-config-input-discoverOnLineDevices" >
<i class="fa fa-tag"></i> Online Devices
</label>
<textarea style='font-family:"Times New Roman", Times, serif; font-size: 12px;' rows="10" id="node-config-input-discoverOnLineDevices"></textarea>
</div> -->
<div class="form-row">
<label for="node-config-input-name" >
<i class="fa fa-tag"></i> Name
</label>
<input type="text" id="node-config-input-name" placeholder="Click Connect to automatically get the camera name">
</div>
<div class="form-row">
<label for="node-config-input-host">
<i class="fa fa-server"></i> Server IP or Hostname
</label>
<input type="text" id="node-config-input-host" placeholder="e.g. 192.168.1.10 or mycamera.mynetwork.com">
</div>
<div class="form-row">
<label for="node-config-input-port"> Port</label>
<input type="text" id="node-config-input-port" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-protocol"><i class="fa fa-sign-in"></i> Protocol</label>
<select type="text" id="node-config-input-protocol">
<option value="http">Http</option>
<option value="https">Https</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-user"> Username</label>
<input type="text" id="node-config-input-user" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-password"> Password</label>
<input type="password" id="node-config-input-password" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-authentication"><i class="fa fa-sign-in"></i> Auth.</label>
<select type="text" id="node-config-input-authentication">
<option value="digest">Digest</option>
<option value="basic">Basic</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-heartbeattimerdisconnectionlimit"><i class="fa fa-exclamation-triangle"></i> Emit error</label>
<select type="text" id="node-config-input-heartbeattimerdisconnectionlimit">
<option value=1>after 1 failed reconnection attempt (not recommended)</option>
<option value=2>after 2 failed reconnection attempts (Default)</option>
<option value=3>after 3 failed reconnection attempts</option>
<option value=4>after 4 failed reconnection attempts</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-streamtimeout"><i class="fa fa-clock-o"></i> Connection timeout</label>
<select type="text" id="node-config-input-streamtimeout"></select>
</div>
<div class="form-row">
<label for="node-config-input-debuglevel"><i class="fa fa-exclamation-triangle"></i> Debug level</label>
<select type="text" id="node-config-input-debuglevel">
<option value="no">No. No debug text please.</option>
<option value="yes">Turn on the debug mode.</option>
</select>
</div>
<div class="form-row">
<label><i class="fa fa-sign-in"></i> Get info</label>
<input type="button" id="getinfocam" class="ui-button ui-corner-all ui-widget" style="background-color:#AEE1FF;width:150px" value="Connect">
</div>
<div class="form-row">
<img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-hikvision-ultimate/master/img/info.png' width="10%">
<div><p id="labeldeviceinfo">No Device info present.<br/>Please click CONNECT to retrieve the infos.</p></div>
<input type="hidden" id="node-config-input-deviceinfo" placeholder="">
</div>
</script>
<script type="text/markdown" data-help-name="Hikvision-config">
This node connects your camera/nvr to node-red.
**Properties**
|Property|Description|
|--|--|
| Name | The node name. |
| Server IP or Hostname | The IP address or hostname of your camera/nvr. |
| Port | The ip's port of your camera/nvr. |
| Protocol | Protocol used to connect to the camera/nvr. |
| Username | The username you use to conect. |
| Password | The passowrd you use to connect. |
| Auth. | The authentication to be used. Must be the same as your camera/nvr |
| Emit error | Number of failed connection from the node to the camera/nvr, after than an error on PIN 2 is emitted. After connection error, the node try to reconnect for the number of times selected, then emits a connection error on PIN 2. Increase this number for slow LANs, like VPN |
| Connection timeout | Minutes before the stream is considered lost. *No Timeout* is not recommended because the connection can drop silently. Default is 3 minutes. |
| Debug level | Outputs all errors in Node-Red. Useful for debugging. Default is *false*. Node-Red must be restarted.|
| Get Info | Click "Connect" button to retrieve some info. This is not mandatory, but helps you understand, wether the camera/nvr is reachable. |
[Find it useful?](https://www.paypal.me/techtoday)
<br/>
</script>