我正在使用 Action Cable,想知道您如何检测同一用户是否打开了多个选项卡或连接,并在必要时将其删除。我有一个下载任务执行多次,我只希望它执行一次。
class ListsChannel < ApplicationCable::Channel
def subscribed
stream_from "channel"
end
# # TODO code to detect multiple streams and delete them if tabs.
# def unsubscribed
# end
end
最佳答案
Note: this is probably not the exact answer you're looking for, but it might inspire you or others for a different solution.
我遇到了这个有类似问题的问题,但是关于在多个选项卡上显示相同的通知。
对我来说,解决方案实际上是构建到 Notifications API 中,通过使用标签
,它只会在多个选项卡上显示一次通知:
let notification = new Notification('Hey!', {
body : 'So nice to hear from you',
tag : 'greeting-notify',
icon : 'https://example.org/my_funny_icon.png'
});
也许对您来说解决方案是使用此 API 将您的下载链接推送到:
Notification.requestPermission().then(function (result) {})
import consumer from "./consumer"
consumer.subscriptions.create("ReportNotificationChannel", {
connected() {},
disconnected() {},
received(data) {
if (Notification.permission === 'granted') {
let title = `Your file is ready!`
let options = { body: 'Click here to start downloading.', tag: data['filename']} // Assuming filename is something unique
let notification = new Notification(title, options)
notification.onclick = function(event){
window.location.href = `/downloads/${data['filename']}`
}
}
}
});
关于ruby-on-rails - Action 电缆检测多个连接/选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57469762/
相关文章:
node.js - 当无效数据传递给模式时,mongoose 不会抛出错误
python - 在 cmd 中使用 pip 安装 matplotlib 完成而没有实际安装
cordova - 为什么我无法在 ionic cordova 中安装 npm 包 cordova-
c# - XUnit 和 ITestOutputHelper 实例化
vbscript - IBM PCOMM - 无法从另一个 vbs 宏中调用 vbs 宏
azure - 我的域的 DNS 记录未通过 dns-01 质询在 azure-dns 上传播
ruby-on-rails - OAuth 安装 - 如何创建跨请求持续存在的 session ?
angular - ionic `
postman - 使用来自 Postman 的 httpOnly cookie
:0: error: could n">swift - 我在 cygwin 上得到 "