1

how to emit the event with using particular_room [io.to(socket.id).emit('sendData') ]at cross domain

I've tried this,

server side
io.emit('sendData', data);

clientside
var socket = io('https://localhost:3000/', { transports: ['websocket'] });

socket.on('sendData', function (data) {
    console.log(data);

})

above syntax are perfectly working on cross domain

but I want to emit with particular room at cross domain

  io.to(socket.id).emit('sendData', data)
io.broadcast.to(socketid).emit('message', 'for your eyes only'); //sending to individual socketid

Reference link -> Cross-domain connection in Socket.IO

Kindly help to solve this!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
maranR
  • 363
  • 8

1 Answers1

1

I Understood your code, you just emit the initial connection on the socket.io server

     io.on("connection", function(socket){
        socket.emit('sendsocketid', data);
        
        })
        
        
        Cross-domain clientside
        var socket = io('https://localhost:3000/', { transports: ['websocket'] });
        
        var obj= [];
        socket.on('sendsocketid', function (data) {
            console.log(data);
    // Now You Can Customize the or add the client Socket .id
          var NewSocketid = {
             id: socket.id
}
Obj.push(data, NewSocketid)

socket.emit("emitnewSocketId", Obj)
    })
socket.on("emitnewSocketId", function(data){
consoleo.log(Obj[1].NewSocketid)

//Now You can emit the new socket id
    io.to(Obj[1].NewSocketid).emit('sendData', data) 
   
})
 

    
R sukumar
  • 100
  • 7