Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

fyi, I've done something similar and the cleanest method for leader election is to use the web locks api:

https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_A...

It is supported by all browsers. You just have all the tabs try to lock the same resource and have them return a promise in the lock callback. The first one wins and when that tab closes the next one in line gets automatically elected.

The leader can then use a broadcast channel and act as a server for all the other tabs to serialize access to any shared resources.



That’s very elegant, thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: