How to get the socketid inside of an Dashboard template

Hey is it possible to get the socketid inside of an Dashboard template node via javascript?

I want to get the id for a multiuser environment to display user specific content with a XMLHttpRequest inside of template node.

I tried with or getting it from from the url parms without luck


function httpGet(theUrl)
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
            document.getElementById("test-socketid").innerHTML = xmlhttp.responseText;
            return xmlhttp.responseText+"test";
    }"GET", theUrl, false );

var delayInMilliseconds = 2000; 
setTimeout(function() { 
}, delayInMilliseconds);

<div id="test-socketid" ></div>

THe socket id isn't available until the connection has happened. So unless the app exposes the id, it will be hidden inside a socket.on('connect', () => {...} function somewhere. I took a quick look using devtools and I can't spot anywhere that it is exposed.

Might not be what you want but uibuilder does expose the id should you need it.

You should, however, note that the id is reset whenever a new connection is made. This could happen because your user refreshes the browser tab or if the socket looses connection briefly due to a network blip. So it isn't a very reliable method of tracking users. There is a lot more info on this subject in the uibuilder technical docs. Dashboard uses Socket.IO as does uibuilder.

1 Like

Thanks for your response!
I found node-red-contrib-mdashboard and I will try it for my propose

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