UNPKG

node-red-contrib-hikvision-ultimate

Version:

A native set of nodes for Hikvision (and compatible) Cameras, Alarms, Radars, NVR, Doorbells, etc.

249 lines (225 loc) 12.9 kB
<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()); var discoveredDevices = []; function applyDiscoveredDevice(index) { var device = discoveredDevices[index]; if (!device) return; if (device.host) $("#node-config-input-host").val(device.host); if (device.port) $("#node-config-input-port").val(device.port); if (device.name && (!$("#node-config-input-name").val() || $("#node-config-input-name").val() === "Server")) { $("#node-config-input-name").val(device.name); } } function refreshDiscoveredDevices() { var button = $("#node-config-input-discover-devices"); var select = $("#node-config-input-discovered-device"); button.val("Searching..."); button.prop("disabled", true); select.empty().append('<option value="">Searching Hikvision devices...</option>'); $.getJSON("hikvisionUltimateDiscoverOnlineDevices", function (data) { discoveredDevices = Array.isArray(data) ? data : []; select.empty(); if (discoveredDevices.length === 0) { select.append('<option value="">No devices found</option>'); RED.notify("No Hikvision devices found on the local network. You can still enter the IP manually.", { modal: false, fixed: false, type: 'warning' }); return; } select.append('<option value="">Select discovered device...</option>'); discoveredDevices.forEach(function (device, index) { select.append($("<option></option>").attr("value", index).text(device.label || (device.host + ":" + device.port))); }); }).fail(function () { select.empty().append('<option value="">Discovery unavailable</option>'); RED.notify("Unable to run Hikvision discovery. Save/deploy once and reopen this config if this is a new install.", { modal: false, fixed: false, type: 'warning' }); }).always(function () { button.val("Discover"); button.prop("disabled", false); }); } $("#node-config-input-discovered-device").change(function () { applyDiscoveredDevice($(this).val()); }); $("#node-config-input-discover-devices").click(refreshDiscoveredDevices); refreshDiscoveredDevices(); $("#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 + "&params=" + 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>&nbsp&nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<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-discovered-device"> <i class="fa fa-search"></i> Discover </label> <select id="node-config-input-discovered-device" style="width:45%"></select> <input type="button" id="node-config-input-discover-devices" class="ui-button ui-corner-all ui-widget" style="width:110px;margin-left:6px" value="Discover"> </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. | | Discover | Searches Hikvision devices on the local LAN and lets you fill IP, port, and name from a selectable list. Manual entry remains available. | | 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>