Rahul Vel
Rahul Vel

Reputation: 35

How to send multiple Socket IO socket.handshake.query values from Javascript client

At server side I have two variables defined for socket.handshake.query as below. But I am not sure how to pass values to these two from client side (Javascript). Able to pass one value but not both. Can some one help me on this?

Server Side:

io.on('connection', function(socket) {
var userId = socket.handshake.query['userId'];
var shopId = socket.handshake.query['shopId'];
---
---}

Client Side:

socket = io("http://127.0.0.1:3000/", {     
    query: `userId=${userId.value}`,    
    // `shopId=${shopId.value}` // shopId also needs to be added to query           
});

Upvotes: 0

Views: 1993

Answers (1)

radar155
radar155

Reputation: 2220

From the Socket.IO Client Documentation, query should be an object. So You could do:

socket = io("http://127.0.0.1:3000/", {     
    query: {
       userId: userId.value,
       shopId: shopId.value
    }              
});

Upvotes: 1

Related Questions