Socket.io Client Request URL

On the client in the browser, I have this code:

this.socket.on('initial', function(data) { console.log(data); }); 

On the server, I have:

 socket.sockets.on('connection', function(client){ console.log('client connected'); }); 

My question is: how can I determine the url where the request came from? For example, if the first closure was done on "/ posts / view / 1", I want to be able to detect it inside the second closure.

+1
source share
1 answer

You can send this data to the server. A little hand wave in detail, but what about something like:

On the client:

 this.socket.on('initial', function(data) { // do whatever with data var my_location = get_page_location_with_javascript(); // or whatever this.socket.emit('phone_home', my_location); }); 

On server:

 this.sockets.on('phone_home', function(url) { console.log("The URL was " + url); }); 
+3
source

Source: https://habr.com/ru/post/1200013/


All Articles