如何解决NEXTJS服务器端中的断开功能
我需要为我的 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就能做到这一点的方法?
解决方法
我正在查看 Pusher 并且我认为这可能是解决我的问题的好方法。有什么建议吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。