0

我需要为我的 next.js 应用程序创建一个连接的设备限制器。当用户访问该网站并登录时,将执行一个将他添加到已连接用户列表的功能。每个用户只能连接一台设备。如果此人尝试在另一台设备上访问登录到同一帐户的应用程序,则会显示等待屏幕。到目前为止,一切都很美好。问题是:当这个人断开连接时。不管是什么原因,如果连接丢失,则必须在服务器端执行将其从连接用户列表中删除的功能。


export const getServerSideProps = async (ctx) => {
  // get cookies
  // database
  
  if(connected.includes(user)) {
    // Displays the waiting screen
    // When he leaves the list, he asks if he wants to connect the device.
  }
  
  if(!connected.includes(user)){
    // Add user to the connected list
  }
  
  user.onDisconnect = disconnect()
  // For example, it doesn't have to be inside getServerSideProps.
}

function disconnect () {
  // Remove user from the connected list
}


没有 socket.io有什么方法可以做到这一点吗?

4

1 回答 1

0

我在看Pusher,我认为这可能是解决我的问题的好方法。有什么建议吗?

于 2021-04-03T19:01:11.630 回答