如果在另一台设备上的谷歌chrome上已经收到网络推送通知,有没有办法停止在一台设备的谷歌chrom上的网络推送



我已经使用在Google chrome上运行的web推送实现了推送通知。

如果在另一台设备上的谷歌chrome上已经收到网络推送通知,有没有办法停止在一台设备的谷歌chrom上的网络推送?

这将要求您在将通知推送给最终用户之前访问分布式存储中的某些内容。例如,您的逻辑可能类似于:

// Only one client can get a lock at a time
var lock = await api.getPushNotificationDistributedLock(); 
// Get the status
var pushNotificationStatus = await api.getPushNotificationStatus();
// Send the notification if it hasn't already been sent
if(pushNotificationStatus === "pending") {
// Push notification to user
await api.setPushNotificationStatus("completed");
}
// Release the lock
lock.release();

第一个获得锁的客户端将看到状态为pending,并成功发送推送通知。在它将状态更新为completed之后,每个后续客户端都会看到状态已完成并继续

相关内容

最新更新