The socket.request
object is shared between namespaces
#3926
Answered
by
darrachequesne
thetutlage
asked this question in
Q&A
-
Is it by design that the Server codeimport { Server } from 'socket.io'
const io = new Server(httpServer)
io.on('connection', (socket) => {
socket.request['foo'] = 'true'
console.log({
'/': {
id: socket.id,
foo: socket.request['foo']
}
})
})
io.of('/chat').on('connection', (socket) => {
// I was not expecting `foo` to exist here
console.log({
'/chat': {
id: socket.id,
foo: socket.request['foo']
}
})
}) Client codeconst socket = io()
socket.on('connect', () => {
io('/chat')
}) Actual output{ '/': { id: 'WWaLxpX9kdLRwC0LAAAM', foo: 'true' } }
{ '/chat': { id: '65FRA7EYdm2SKFvmAAAN', foo: 'true' } } Expected output{ '/': { id: 'WWaLxpX9kdLRwC0LAAAM', foo: 'true' } }
{ '/chat': { id: '65FRA7EYdm2SKFvmAAAN', foo: undefined } } |
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
May 15, 2021
Replies: 1 comment 1 reply
-
Yes, it is by design. The |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
darrachequesne
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it is by design. The
request
attribute is a reference to the first HTTP request of the Socket.IO session.