JavaScript HTML5 Master/Slave Browser Tabs Helper
Version 1.2.7
16 Oct 2016
DuelJS is a fast and small JavaScript helper for master/slave browser tabs actions. Use it for optimize your client-server communication between browser and server and inside browser tabs.
Basic entity of DuelJS is channel. Channel provides unique community between browser tabs inside one site:
var channel = duel.channel('example'); // build your channel
Each window has 2 possible states: Master and Slave.
Master window - is a tab which currently working (has focus).
The simple method for
detection is:
window.isMaster()
You can use it for get chat messages as example:
if (window.isMaster()) {
updateChatWindow(); // user function
}
You want something more? Oh yeah we have. The Broadcast is a system for broadcasting your messages to all specific channel’s members (tabs), just see this example:
<script type="text/javascript">
var channel = duel.channel('test');
document.title = 'Master ' + duel.getWindowID();
channel.on('demo_trigger', function (message) {
console.info((new Date).getTime(), message)
});
setInterval(function () {
document.title = (window.isMaster() ? 'Master ' : 'Slave ') + duel.getWindowID();
}, 100);
</script>
<button onclick="channel.broadcast('demo_trigger', 'hello world')">
channel.broadcast('demo_trigger', 'hello world')
</button>
Install package with bower:
bower install duel --save
Install package with npm:
npm install dueljs --save
If you are using ES6 with babel/webpack, you need to import dueljs like on example below:
import duel from 'dueljs'
Look at this in your browser right now: click here
DuelJS documentation now available on dueljs.readthedocs.org
Now you can determine a superMaster tab which will be it regardless of anything
Beta extension available on github.com/studentIvan/tabninja
Look at this in your browser right now: click here
bower install tabninja --save
Having trouble with DuelJS? Contact [email protected] and i’ll
help you sort it out.
Check my site for information about me:
studentivan.ru