# Dashboard Socket ID bug?

**URL:** https://discourse.nodered.org/t/dashboard-socket-id-bug/6229
**Category:** Dashboard
**Created:** [30 December 2018 05:25 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229 "2018-12-30T05:25:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)
#### Post date: [30 December 2018 05:25 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/1 "2018-12-30T05:25:10Z")

</div>

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)

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

```

while button B creates a new msg:

```auto
<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:

```auto
[
    {
        "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
    }
]
```

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [30 December 2018 19:07 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/2 "2018-12-30T19:07:09Z")

</div>

Hey @hugobox,

_ **I haven't much time** _, but you can debug the code in the [ui.js](https://github.com/node-red/node-red-dashboard/blob/master/ui.js#L268) 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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e98f40627c17878859447337128f51672b06275b.png)

- 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4ff31e684606d874c0555bd668fe487e4eb8bbf0.png)

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

---

<div class="post-metadata">

### Author: ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)
#### Post date: [30 December 2018 19:44 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/3 "2018-12-30T19:44:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [30 December 2018 20:03 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/4 "2018-12-30T20:03:53Z")

</div>

> [@hugobox](#):
>
> Maybe using a different browser but still being on the same pc is not enough separation to use a different 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.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [30 December 2018 21:53 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/5 "2018-12-30T21:53:35Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [30 December 2018 22:13 UTC](https://discourse.nodered.org/t/dashboard-socket-id-bug/6229/6 "2018-12-30T22:13:39Z")

</div>

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;
            }
```
