This is to not have to depend on
https://github.com/MayamaTakeshi/redmine_rt_webextension
to popup issues when calls are answered in a pbx.
Instead we should create one top menu item called RealTime (temporary name) that would take care of subscribing to popup channel and based on the user currently logged in, to check if a tab for the issue URL already exists. If yes, switch the focus to that tab. Otherwise open a new tab for the issue.
For this we can use
https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
to communicate with tabs from the same origin:
we should ask the tabs if someone is open in that URL
if a tab replies, we should switch the focus to it.
if no tab answers after 250 ms, we should open a new tab
Later we can add a summary like: "Your last open tickets" that could be also updated in real time.
And this could also be used to popup a desktop notification informing the phone_number/name/company of a customer that might be ringing the call-center group.
Obs: this would be still an inferior solution in comparison to a webextension since we will have to deal with intertab communication timeout but still it should be worthy to have it as it eliminates webextension security concerns.
In the end we didn't use BroadcastChannel as there are other problems:
to permit to switch the focus to an existing tab, the javascript code must have a reference to that tab/window and this can only be obtained by a tab if it uses window.open(). So it would be able to issue a focus command only for tabs that it created itself.
a tab cannot set focus to itself. (Call to window.focus() might work depending of user settings or browser implementation but we should not rely on it).
So we will not check if there is a tab already open for the ticket and will always popup a new tab for it.
This is to not have to depend on https://github.com/MayamaTakeshi/redmine_rt_webextension to popup issues when calls are answered in a pbx. Instead we should create one top menu item called RealTime (temporary name) that would take care of subscribing to popup channel and based on the user currently logged in, to check if a tab for the issue URL already exists. If yes, switch the focus to that tab. Otherwise open a new tab for the issue. For this we can use https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel to communicate with tabs from the same origin:
Ref: https://www.redmine.org/boards/3/topics/19994
Later we can add a summary like: "Your last open tickets" that could be also updated in real time. And this could also be used to popup a desktop notification informing the phone_number/name/company of a customer that might be ringing the call-center group.
Obs: this would be still an inferior solution in comparison to a webextension since we will have to deal with intertab communication timeout but still it should be worthy to have it as it eliminates webextension security concerns.