-
Hi Alex, I’m having an issue to declare a local variable foo (see below) which is only visible inside the socket connection handlers (open, message, close).
The variable foo can’t be declared globally, otherwise it will be visible for all the connections (total mess). I checked the examples but couldn’t find a solution to my problem. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You've got an extra set of open:ws=>{
ws.foo=true
},
message:(ws,message,isBinary)=>{
console.log(ws.foo)
} |
Beta Was this translation helpful? Give feedback.
-
Thanks a mill. |
Beta Was this translation helpful? Give feedback.
You've got an extra set of
})
at the end that needs to be removed, andopen
event does not havereq
so you need to remove that, and if you want to share something acrossopen
andmessage
events you should put it in thews
object