Recognize which tab made the request

This question probably has no answer. But I thought that I would do it. I wrote a great one-page application. When the application starts, the open tab is "registered" itself with the server, which is stored as the "active" tab.

If user A changes XYZ in the workspace, each tab opened in this workspace by any user receives a notification that XYZ has been changed. This causes a reboot in the clients, which will be magically updated. At the moment, I am doing this through a survey. However, when all this works, I can use things like WS or Socket.io to make things even faster.

PROBLEM: Each tab receives a notification. Even the tab that initiated it first! (as a result, the updated screen is updated)

For some reason, I need a server to find out the bookmark ID of the tab that makes the request. Remember that the user can open 5 tabs: if they change XYZ, all tabs should receive a notification, EXCEPT for what really caused it.

I am currently passing the workspace identifier for each Ajax request (a user can log in and have access to multiple workspaces at the same time).

  • Solution 1: Add a workspace id and tab id for each request.
  • Solution 2: use only the tab identifier for each request. The application will develop a workspace identifier from tabID (which knows which workspace it belongs to)
  • Solution 3: (Something I miss?)

Any ideas?

+6
source share
2 answers

Instead of the server worrying about which tabs for sending change notifications may have a tab that triggered the changes, the notification is ignored.

There are two ways to do this:

  • After changing the contents, the tab will display all notifications for a short period of time. (This will work fine if changes on multiple tabs do not happen in a short amount of time.)
  • A “change identifier” is created on the tab, which it sends to the server with the changes in xyz. The broadcast change notification contains this identifier, and the send tab recognizes it as sent and ignores it.
+2
source

You can experiment with the HTML5 visibility API with the fallback window.onfocus and window.onblur events and suppress the page refresh if it is currently visible / active.

0
source

All Articles