Dashboard Socket ID bug?

I noticed something interesting with Dashboard, might not be a bug, but I'm not sure if it is intended either. Basically I created two buttons A and B. Button A uses send(msg)

<md-button ng-click="msg.payload = 'clicked A'; send(msg)">Button A</md-button>

while button B creates a new msg:

<md-button ng-click="send({'payload':'clicked B'})">Button B</md-button>

When I click on button A from 2 different browsers (Chrome and Edge), the debug will give me the same socket ID (which I was not expecting), whereas if I click B from the 2 different browsers, it gives different socket IDs (which was expected).

Anybody understands the behavior?

Here's the flow to reproduce:

[
    {
        "id": "3d9a452a.0f875a",
        "type": "ui_template",
        "z": "7a76aa38.4d74a4",
        "group": "6a4d510d.5de65",
        "name": "button A",
        "order": 2,
        "width": "0",
        "height": "0",
        "format": "<md-button ng-click=\"msg.payload = 'clicked A'; send(msg)\">Button A</md-button>",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "templateScope": "local",
        "x": 400,
        "y": 240,
        "wires": [
            [
                "73e44547.2b463c"
            ]
        ]
    },
    {
        "id": "73e44547.2b463c",
        "type": "debug",
        "z": "7a76aa38.4d74a4",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 550,
        "y": 240,
        "wires": []
    },
    {
        "id": "efaf82a4.9fd4a",
        "type": "ui_template",
        "z": "7a76aa38.4d74a4",
        "group": "6a4d510d.5de65",
        "name": "button B",
        "order": 2,
        "width": "0",
        "height": "0",
        "format": "<md-button ng-click=\"send({'payload':'clicked B'})\">Button B</md-button>",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "templateScope": "local",
        "x": 400,
        "y": 300,
        "wires": [
            [
                "a1991d98.fae41"
            ]
        ]
    },
    {
        "id": "a1991d98.fae41",
        "type": "debug",
        "z": "7a76aa38.4d74a4",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 550,
        "y": 300,
        "wires": []
    },
    {
        "id": "6a4d510d.5de65",
        "type": "ui_group",
        "z": "",
        "name": "Users",
        "tab": "56715436.c2591c",
        "order": 2,
        "disp": true,
        "width": "9",
        "collapse": false
    },
    {
        "id": "56715436.c2591c",
        "type": "ui_tab",
        "z": "",
        "name": "Home Tab",
        "icon": "dashboard",
        "order": 3
    }
]

Hey @hugobox,

I haven't much time, but you can debug the code in the ui.js file if you want to see it with your own eyes. In that code snippet, all messages arrive from your dashboard. However when you start in the dashboard with your own constructed message, there will be less original information available as explained below...

In line 269 another function is being called to do some processing before sending the message on the output of your Button node:

  • For button A the original.msg will contain a lot of information.
  • For button B the original.msg will contain only your payload (but no socketId or _msgid).

The result of this function is then used to determine the socketId of the toSend object (which is the message to be send on the output of your Button node):

image

So when you create a message by yourself, the code will behave differently. Don't know at the moment if that is correct or not.

Now I'm off ...
Bart

1 Like

Thanks Bart!

I really appreciate your time, efforts and suggestions! I was under the impression that socketID should be unique to a Dashboard client, but maybe I'm missing something here.

Maybe using a different browser but still being on the same pc is not enough separation to use a different socketid?

As I'm developping multi-user features, I really want to understand the inner workings. So far I'm using sessionStorage or localStorage to change the topic of each client and it works great, but I wanted to see If there was a way of separating users using socketid.

As far as I remember, a different tab or window in the same browser should generate a new ID. Every instance should be unique otherwise you cannot talk to a specific socket instance.

So yes I suspect it is a bug - in that as Julian says each browser client session should have it's own socketid. However as that beforeEmit code has been there for over 2 years I'm loathe to just change it without serious digging first to understand why it is the way it is, and what would break if we change it. Could it also be a consequence of the way Angular "pre-compiles" the msg in the A ng-click function in once case and has to re-evaluate it every time in the other ? (Not sure - just hypothesising).

A bit more digging - changing the beforeEmit function as follows seems to help, as the correct socketid is there, so can be re-attached..

            if (original) {
                var om = original.msg;
                om.socketid = original.socketid;
                return om;
            }
2 Likes