UNPKG

node-red-contrib-hikvision-ultimate

Version:

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

176 lines (149 loc) 5.67 kB
<script type="text/javascript"> RED.nodes.registerType('hikvisionUltimateSpeaker', { category: 'Hikvision Ultimate', color: '#C0C0C0', defaults: { name: { value: "" }, topic: { value: "" }, server: { type: "Speaker-config", required: true }, customAudioID: { value: "" }, volume: { value: "2" } }, inputs: 1, outputs: 2, outputLabels: function (i) { var ret = ""; switch (i) { case 0: return "Play"; break; case 1: return "Error"; break; case 2 : return ""; break; default: break; } }, icon: "bridge.svg", label: function () { var label = "Speaker" if (this.name !== undefined && this.name.length > 0) { label = this.name; } return label; }, paletteLabel: function () { return "Speaker"; }, oneditprepare: function () { let node = this; // File to be played $("#node-input-server").change(function () { $("#node-input-customAudioID").empty(); try { let oNodeServer = RED.nodes.node($(this).val()); $.getJSON("hikvisionUltimateGetSpeakerFiles?nodeID=" + oNodeServer.id, {}).done(function (data) { $.each(data, function (i, item) { $("#node-input-customAudioID").append($("<option>").val(item.customAudioID.toString()).text(item.customAudioName + " #" + item.customAudioID)) }); $("#node-input-customAudioID").val(node.customAudioID) }); } catch (error) { } }); // Volume $("#node-input-volume").empty(); for (let index = 1; index < 100; index++) { $("#node-input-volume").append($("<option>").val(index.toString()).text(index + "%")) } $("#node-input-volume").val(this.volume) $("#testFile").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-input-host").val(); jManipulate.port = $("#node-input-port").val(); jManipulate.protocol = $("#node-input-protocol").val(); jManipulate.user = $("#node-input-user").val(); jManipulate.password = $("#node-input-password").val(); jManipulate.authentication = $("#node-input-authentication").val(); sQueryString = "?nodeID=" + node.id + "&customAudioID=" + $("#node-input-customAudioID").find(":selected").val() + "&params=" + encodeURIComponent(JSON.stringify(jManipulate)); $.getJSON("hikvisionUltimateSpeakerTest" + sQueryString, (data) => { this.value = "Connect"; this.disabled = false; }).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' }) }); }); }, oneditsave: function () { if ($("#node-input-name").val() === undefined || $("#node-input-name").val() === '') { $("#node-input-name").val($("#node-input-customAudioID option:selected").text()); } } }); </script> <script type="text/html" data-template-name="hikvisionUltimateSpeaker"> <div class="form-row"> <b>Speaker node</b> <br/> <br/> <label for="node-input-server">Server</label> <input type="text" id="node-input-server" /> </div> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-topic"><i class="fa fa-tasks"></i> Node topic</label> <input type="text" id="node-input-topic" placeholder="Node's own topic"> </div> <div class="form-row"> <label for="node-input-customAudioID"><i class="fa fa-tasks"></i> File</label> <select id="node-input-customAudioID"> <input type="button" id="testFile" class="ui-button ui-corner-all ui-widget" style="background-color:#AEE1FF;width:100px" value="Play"> </div> <div class="form-row"> <label for="node-input-volume"><i class="fa fa-tasks"></i> Volume</label> <select id="node-input-volume"> </div> </script> <script type="text/markdown" data-help-name="hikvisionUltimateSpeaker"> This node lets you play through the Speaker, the audio files that are loaded in the Hikvision Speaker. The audio files must be already be uploaded to the speaker.<br/> **General** |Property|Description| |--|--| | Server | Select the Speaker to be used. | | Name | The node name. | | Topic | The msg.topic.| | Volume | The speaker's volume from 1% to 100%. CAUTION, THE SPEAKER IS VERY LOUD. CHECK FOR PEOPLE AROUND AND PROTECT YOUR EARS! | | File | This is the speaker's audio file list. If you see nothing, upload the audio files into your speaker, via the speaker web interface, via IVMS, etc...| | Play button | Broadcasts the audio file you selected, to your speaker with volume set to 2%. Caution needed, protect your ear in any case! | ### Outputs 1. Standard output PIN 1 : payload (boolean) : the standard output of the command. It contains the status of the message being sent, as true/false. 2. Error output PIN 2 : msg (json) : the connection status. An error will be published in case of connection error ### Inputs 1. Standard input : payload (boolean) : *true* for broadcasting the audio file on the speaker, *false* to stop playing. ### Details CAUTION, THE SPEAKER IS VERY LOUD. CHECK FOR PEOPLE AROUND AND PROTECT YOUR EARS! <br/> [DONATE HERE, THANK YOU!](https://www.paypal.me/techtoday) <br/> </script>