gpt4 book ai didi

Meteor - 服务器端判断用户是否离开网站的方式?

转载 作者:行者123 更新时间:2023-12-01 12:36:31 28 4
gpt4 key购买 nike

由于 Meteor 使用 WebSockets,我猜可能很容易判断用户是否真的关闭了他们的浏览器,或者至少关闭了带有 Meteor 网站的选项卡。这可行吗?如果可行,怎么做?

最佳答案

来自 Meteor 文档:Meteor.onConnection :

Meteor.onConnection(callback) Server

onConnection returns an object with a single method stop. Calling stop unregisters the callback, so that this callback will no longer be called on new connections.

The callback is called with a single argument, the server-side connection representing the connection from the client.

服务器端连接对象有onClose字段:

onClose Function

Register a callback to be called when the connection is closed. If the connection is already closed, the callback will be called immediately.

需要注意的是,每次连接断开时都会调用此回调。用户是否关闭了他们的浏览器,或者只是暂时失去了他们的连接并且很快就会回来。

关于Meteor - 服务器端判断用户是否离开网站的方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29202142/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com