AngularJS - 在 tabs/windows 之间共享一个 websocket

AngularJS - share a websocket between tabs/windows

我正在使用 angular-websocket 打开 WebSocket,应用程序正在等待消息,然后显示网络通知。

我注意到当打开超过 1 个选项卡时会有很多连接,然后每个选项卡都会收到一条消息,并且通知会显示 1 X TABS_NUM 本应显示一次。

我认为要使其正常工作,我需要为整个应用程序打开 1 个 WebSocket。

有什么想法吗?那我该怎么办?

使用 tag 解决了我的问题:

It is usually undesirable for a user to receive a lot of notifications in a short space of time — for example, what if a messenger application notified a user for each incoming message, and they were being sent a lot? To avoid spamming the user with too many notifications, it's possible to modify the pending notifications queue, replacing single or multiple pending notifications with a new one.

To do this, it's possible to add a tag to any new notification. If a notification already has the same tag and has not been displayed yet, the new notification replaces that previous notification. If the notification with the same tag has already been displayed, the previous notification is closed and the new one is displayed.

new Notification(notificationMessage.title, {tag: notificationMessage._id});