3.1.7 初始化示例-额外Headers
const socket=io({
transportOptions:{
polling:{
extraHeaders:{
"x-clientId":"abc"
}
}
}
})const io= require('socket.io')()
// 中间器件
io.use((socket,next)=>{
const clientId= socket.handshake.headers['x-clientId'];
if (isValid(clientId)){
return next()
}
return next(new Error("authentication error"))
})Last updated
Was this helpful?