# Use of this.msg V this.$socket.on('msg-input:' + this.id, (msg)

**URL:** <https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [29 February 2024 19:49 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037 "2024-02-29T19:49:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [29 February 2024 19:49 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/1 "2024-02-29T19:49:21Z")

</div>

I notice that people are using `this.msg` instead of

```auto
        mounted() {
            // listen for incoming msg's from Node-RED
            // note our topic is "msg-input" + the node's unique ID
            this.$socket.on('msg-input:' + this.id, (msg) => {

            }),

```

for tracking `msg` input

What are the advantages / disadvantages of each strategy?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [29 February 2024 20:04 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/2 "2024-02-29T20:04:59Z")

</div>

Currently revealed difference is about reply message. The socet listening strategy helps to avoid it if needed. Overall the watch strategy offer cleaner and simpler codding. That's of course is opinion which doesn't qualify to be discussed.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 February 2024 20:48 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/3 "2024-02-29T20:48:10Z")

</div>

> [@Buckskin](#):
>
> `this.$socket.on('msg-input:' + this.id,`

I can't think of a reason for doing it, but does that mean one can listen for messages intended for other nodes, with a different id?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [29 February 2024 21:12 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/4 "2024-02-29T21:12:03Z")

</div>

Yes. Just tried it

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [29 February 2024 21:18 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/5 "2024-02-29T21:18:10Z")

</div>

> [@hotNipi](#):
>
> Currently revealed difference is about reply message

Sorry for being a bit slow, but would you explain this, I haven't seen anything about `reply message` apart from here and one of Colin's posts.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 February 2024 21:34 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/6 "2024-02-29T21:34:24Z")

</div>

> [@Buckskin](#):
>
> one of Colin's posts.

Yes, that is it: [Retaining state information in a Dashboard 2 ui-template - #13 by hotNipi](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/13)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 February 2024 21:47 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/7 "2024-02-29T21:47:41Z")

</div>

> [@Buckskin](#):
>
> reply message

Actually it is Replay Message.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [29 February 2024 21:54 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/8 "2024-02-29T21:54:02Z")

</div>

Sorry typo.

But what IS **replay message**. I have haven't seen anything about this in the documentation. The only `msg` mentioned is `this.msg` which is the last `msg` received by the `ui-template` node

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 February 2024 21:57 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/9 "2024-02-29T21:57:16Z")

</div>

> [@Buckskin](#):
>
> The only `msg` mentioned is `this.msg` which is the last `msg` received by the `ui-template` node

If you refresh the page (or open another browser window on it) then node red replays the last message sent to the template. That allows the node to set its current state, assuming that it only needs one message to do that (which is what the other thread is all about).

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [29 February 2024 22:27 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/10 "2024-02-29T22:27:48Z")

</div>

Well you learn something new every day!!

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [1 March 2024 09:22 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/11 "2024-03-01T09:22:03Z")

</div>

Yep, for clarification, as Colin has mentioned, `this.msg` can changed on 2 events:

- `widget-load`: When the Dashboard/page first renders
- `msg-input`: When an input arrives via Node-RED to the `ui-template` node

If you run a `watch` on `msg`, then that will fire in _both_ of those instances. If you add your own `socket` listener, then it'll just fire when a new `msg` comes in via the input.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 March 2024 09:22 UTC](https://discourse.nodered.org/t/use-of-this-msg-v-this-socket-on-msg-input-this-id-msg/86037/12 "2024-03-15T09:22:49Z")

</div>

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