检查在套接字连接中使用哪种浏览器类型用户



使用节点JS和套接字IO。我想知道用户连接时使用的浏览器正在使用哪个浏览器。

使用

sockets.on('connection', function(socket) {
    var ip_address = socket.conn..remoteAddress;  //this fetches the ip address
    var userbrowser = socket.conn. //am stuck here

});

如何获取用户在套接字中使用的浏览器类型

我已经检查了console.log(socket.conn),但我看不到任何有用的浏览器键

这是如何做的方法:

console.log("user-agent: "+socket.request.headers['user-agent']);

在套接字连接事件下,您需要执行此操作

 io.on('connection', function(socket) {
   console.log(socket.request.headers)
   })
   //prints following info like 
{
  "host": "192.168.1.77:4000",
  "user-agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0",
  "accept": "*/*",
  "accept-language": "en-US,en;q=0.5",
  "accept-encoding": "gzip, deflate",
  "origin": "null",
  "connection": "keep-alive",
  "cookie": "io=_ffsFAYurGTLZunDAAAA"
}

最新更新