An event emitter for same-origin tab communication
npm install tab-emittertab-emitter is a client-side javascript module that allows you to send events between browser tabs/windows.
tab-emitter is written to work with browserify, and is extremely easy to implement in your code.
js
var TabEmitter = require('tab-emitter')
var emitter = TabEmitter()
setTimeout(function () {
emitter.emit('hello', { thing: 'world' })
}, 5000)
emitter.on('hello', function (obj) {
console.log(obj.thing) // => 'world'
})
`
client2.js
`js
var TabEmitter = require('tab-emitter')
var emitter = TabEmitter()
emitter.on('hello', function (obj) {
console.log(obj.thing) // => 'world'
})
`
Don't use browserify?
If you just want to use this module in the browser without dealing with browserify, here's how you can:
`html
`
API
`js
var TabEmitter = require('tab-emitter')
`
var emitter = TabEmitter([key])
- key is a key to uniquely identify an emitter across tabs. If the same key is used in multiple tabs, they can communicate with each other.
- Returns emitter which is an EventEmitter` instance.