mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	* Adds proper url length detection* fix up the extra line added in the merge
* Adds proper url length detection * fix up the extra line added in the merge
This commit is contained in:
		
				
					committed by
					
						 Dave Conway-Jones
						Dave Conway-Jones
					
				
			
			
				
	
			
			
			
						parent
						
							9300e81e3d
						
					
				
				
					commit
					d8cf46a4ec
				
			| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "node-red-node-physical-web", | ||||
|   "version": "0.0.11", | ||||
|   "version": "0.0.12", | ||||
|   "description": "Node-RED nodes to interact with the Physical Web", | ||||
|   "main": "physical-web.js", | ||||
|   "scripts": { | ||||
|   | ||||
| @@ -87,6 +87,7 @@ | ||||
|     <div class="form-row" id="node-url"> | ||||
|         <label for="node-input-url"><i class="fa fa-link"></i> URL</label> | ||||
|         <input type="text" id="node-input-url" style="width:250px;" placeholder="http://..."> | ||||
|         <span id="url-length"></span> | ||||
|         <!--<button type="button" id="node-input-url-shorten" disabled=true>Shorten</button> --> | ||||
|         <p style="margin-left:100px; width:70%">This URL needs to be shorter than 18 bytes | ||||
|         in length to meet Eddystone spec</p> | ||||
| @@ -161,20 +162,73 @@ | ||||
|             return this.name?"node_label_italic":""; | ||||
|         }, | ||||
|         oneditprepare: function() { | ||||
|             $( "#node-input-period" ).spinner({min:0}); | ||||
|             $( "#node-input-count" ).spinner({min:0}); | ||||
|             $( "#node-input-power" ).spinner({min:-30,max:100}); | ||||
|  | ||||
|             var checkLength = function(text) { | ||||
|                 var l = text.length; | ||||
|                 switch(true) { | ||||
|                     case /^http:\/\/www./.test(text): | ||||
|                         l -= 10; | ||||
|                         break; | ||||
|                     case /^https:\/\/www./.test(text): | ||||
|                         l -= 11; | ||||
|                         break; | ||||
|                     case /^http:\/\//.test(text): | ||||
|                         l -= 6; | ||||
|                         break; | ||||
|                     case /^https:\/\//.test(text): | ||||
|                         l -= 7; | ||||
|                         break; | ||||
|                 } | ||||
|  | ||||
|                 switch(true) { | ||||
|                     case /.*\.info\/.*/.test(text): | ||||
|                         l -= 5; | ||||
|                         break; | ||||
|                     case /.*\.com\/.*/.test(text): | ||||
|                     case /.*\.net\/.*/.test(text): | ||||
|                     case /.*\.org\/.*/.test(text): | ||||
|                     case /.*\.edu\/.*/.test(text): | ||||
|                     case /.*\.biz\/.*/.test(text): | ||||
|                     case /.*\.gov\/.*/.test(text): | ||||
|                     case /.*\.info.*/.test(text): | ||||
|                         l -= 4; | ||||
|                         break; | ||||
|                     case /.*\.com.*/.test(text): | ||||
|                     case /.*\.net.*/.test(text): | ||||
|                     case /.*\.org.*/.test(text): | ||||
|                     case /.*\.edu.*/.test(text): | ||||
|                     case /.*\.biz.*/.test(text): | ||||
|                     case /.*\.gov.*/.test(text): | ||||
|                         l -= 3; | ||||
|                         break; | ||||
|                 } | ||||
|  | ||||
|                 return l; | ||||
|             } | ||||
|  | ||||
|             $("#node-input-period").spinner({min:0}); | ||||
|             $("#node-input-count").spinner({min:0}); | ||||
|             $("#node-input-power").spinner({min:-30,max:100}); | ||||
|             $("#url-length").text(checkLength($('#node-input-url').val())); | ||||
|             $("#node-input-mode").on("change",function() { | ||||
|               if ($("#node-input-mode").val() === "uid") { | ||||
|                   $("#node-url").hide(); | ||||
|                   $('#url-length').hide(); | ||||
|                   $("#node-namespace").show(); | ||||
|                   $("#node-instance").show(); | ||||
|               } else { | ||||
|                   $("#node-url").show(); | ||||
|                   $("#url-length").show(); | ||||
|                   $("#node-input-url").bind('input',function(){ | ||||
|                     console.log("change " + $(this).val()); | ||||
|                     $("#url-length").text(checkLength($(this).val())); | ||||
|                   }); | ||||
|                   $("#node-namespace").hide(); | ||||
|                   $("#node-instance").hide(); | ||||
|               } | ||||
|           }); | ||||
|             }); | ||||
|  | ||||
|  | ||||
|         } | ||||
|     }); | ||||
| </script> | ||||
|   | ||||
| @@ -20,6 +20,48 @@ module.exports = function(RED) { | ||||
|     var EddystoneBeaconScanner = require('eddystone-beacon-scanner'); | ||||
|     var eddyBeacon = false; | ||||
|  | ||||
|     var checkLength = function(text) { | ||||
|         var l = text.length; | ||||
|         switch(true) { | ||||
|             case /^http:\/\/www./.test(text): | ||||
|             l -= 10; | ||||
|             break; | ||||
|             case /^https:\/\/www./.test(text): | ||||
|             l -= 11; | ||||
|             break; | ||||
|             case /^http:\/\//.test(text): | ||||
|             l -= 6; | ||||
|             break; | ||||
|             case /^https:\/\//.test(text): | ||||
|             l -= 7; | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         switch(true) { | ||||
|             case /.*\.info\/.*/.test(text): | ||||
|             l -= 5; | ||||
|             break; | ||||
|             case /.*\.com\/.*/.test(text): | ||||
|             case /.*\.net\/.*/.test(text): | ||||
|             case /.*\.org\/.*/.test(text): | ||||
|             case /.*\.edu\/.*/.test(text): | ||||
|             case /.*\.biz\/.*/.test(text): | ||||
|             case /.*\.gov\/.*/.test(text): | ||||
|             case /.*\.info.*/.test(text): | ||||
|             l -= 4; | ||||
|             break; | ||||
|             case /.*\.com.*/.test(text): | ||||
|             case /.*\.net.*/.test(text): | ||||
|             case /.*\.org.*/.test(text): | ||||
|             case /.*\.edu.*/.test(text): | ||||
|             case /.*\.biz.*/.test(text): | ||||
|             case /.*\.gov.*/.test(text): | ||||
|             l -= 3; | ||||
|             break; | ||||
|         } | ||||
|         return l; | ||||
|     } | ||||
|  | ||||
|     function Beacon(n) { | ||||
|         RED.nodes.createNode(this,n); | ||||
|         var node = this; | ||||
| @@ -65,12 +107,16 @@ module.exports = function(RED) { | ||||
|  | ||||
|         node.on('input', function(msg) { | ||||
|             if (node.mode === "url") { | ||||
|               try { | ||||
|                   eddystoneBeacon.advertiseUrl(msg.payload, node.options); | ||||
|                   node.status({fill:"green",shape:"dot",text:msg.payload}); | ||||
|               } catch(e) { | ||||
|               if (checkLength(msg.payload) <= 18) { | ||||
|                   try { | ||||
|                       eddystoneBeacon.advertiseUrl(msg.payload, node.options); | ||||
|                       node.status({fill:"green",shape:"dot",text:msg.payload}); | ||||
|                   } catch(e) { | ||||
|                       node.status({fill:"red",shape:"dot",text:"Error setting URL"}); | ||||
|                       node.error('error updating beacon URL', e); | ||||
|                   } | ||||
|               } else { | ||||
|                   node.status({fill:"red",shape:"dot",text:"URL too long"}); | ||||
|                   node.error('error updating beacon URL', e); | ||||
|               } | ||||
|             } | ||||
|             // uid mode | ||||
|   | ||||
		Reference in New Issue
	
	Block a user