gpt4 book ai didi

ruby-on-rails - Action 电缆检测多个连接/选项卡

转载 作者:行者123 更新时间:2023-12-05 07:20:31 30 4
gpt4 key购买 nike

我正在使用 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/

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