Custom node is not adding to Node-red

I have created the node-red custom node which will take the URLs to be connected and it connects to multiple endpoints dynamically.

Below is the code that I am usingpackage.json (434 Bytes) package-lock.json (669 Bytes) .

HTML:

<script type="text/javascript">
    RED.nodes.registerType('websocketlistener',{
        category: 'function',
        color: '#de4e61',
        defaults: {
            name: {value:""}
        },
        inputs:1,
        outputs:1,
        icon: "white-globe.svg",
        label: function() {
            return this.name||"websocketlistener";
        }
    });
</script>

<script type="text/html" data-template-name="websocketlistener">
    <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>
</script>

<script type="text/html" data-help-name="websocketlistener">
    <p>Based on the input JSON urls it will listen from websocket multiple endpoint</p>
</script>

JAVASCRIPT:
module.exports = function(RED) {

var WSCLIENT = require('ws-reconnect');

function CustomWebSocketListener(config) {
    RED.nodes.createNode(this,config);
    var node = this;
    node.on('input', function(msg) {
		
		let urls =msg.payload.urls;
		let connections = {};
		
		
			for(let i=0;i<urls.length;i++){
				if(connections[urls[i]]){
					
				}
				else{
				const wsclient = new WSCLIENT(urls[i],{
				retryCount:1, // default is 2
				reconnectInterval: 20 // default is 5
				});
				wsclient.start();
				wsclient.on("message",function(data){
					    node.send(msg);
    
				});

				wsclient.on("reconnect",function(){
					console.log("websocketlistener :::reconnecting");
				});
				wsclient.on("connect",function(){
					console.log("websocketlistener ::: connected"+urls[i]);
					wsclient.send(urls[i]);
				});
				wsclient.on("destroyed",function(){
					console.log("websocketlistener ::: destroyed");
				});
				connections[urls[i]]=wsclient;

				}
			}
		
	
    });
}
RED.nodes.registerType("websocketlistener",CustomWebSocketListener);

}

Below is the command I am using for linking node to node-red.

In custom node folder: npm link node-red-contrib-websocketlistener
Then in node-red I ran the following command: npm link "E:\node-red custom node\node-red-contrib-websocketlistener"

But after the above steps also it is not adding in node-red.

1 Like
  • Created websocketlistener.js with the js code
  • Created websocketlistener.html with the html code
  • Added "websocketlistener": "websocketlistener.js" to the node-red > nodes in package.json.
  • Restarted NR

The node appeared in Functions, so the code is ok. Probably something wrong with the npm link step.

Also check this

Have you tried installing it instead? Go to the node red user directory, often ~/.node-red/ or your platform’s equivalent, then running npm install /path/to/folder/with/source

2 Likes

Yes, please use a browser from at least this century :slight_smile: IE11 is no longer likely to work on many sites.

Sadly, it's still required in a number of corporate environments. I remember when only a couple years ago we still had to test on both Edge and IE10/11 for a product because the client's had customers on either of those... It was great when we finally could drop IE10 from the tests, and upgrade the testing machine that had been kept back on purpose.

As this node code is under control of the OP - they can re-write it to use ES5 compatible javascript such that IE11 can render it correctly.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.