Socket.io客户端请求源URL
在客户端,在浏览器中,我有这样的代码:
this.socket.on('initial', function(data) { console.log(data); });
在服务器上我有:
socket.sockets.on('connection', function(client){ console.log('client connected'); });
我的问题是:如何检测请求来自哪里的URL? 例如,如果第一个闭包在“/ posts / view / 1”上运行,我希望能够在第二个闭包内部检测到它。
您可以将这些数据发送回服务器。 对细节有点手摇,但是怎么样:
在客户端:
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); });
在服务器上:
this.sockets.on('phone_home', function(url) { console.log("The URL was " + url); });