1.0.2 • Published 6 years ago

@srounce/broadcastchannel v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

tab-channel

send message to other tab in the same origin. use BroadcastChannel default, use storage event as fallback

Installation

npm i --save tab-channel

Usage

As a polyfill for BroadcastChannel:

import 'tab-channel/polyfill'

Use implementation directly:

import { BroadcastChannel as Channel } from 'tab-channel'

// channel name is required
var channel = new Channel('my-channel')

// get channel name
channel.name

// bind message event 
channel.onmessage = function(m) {
  // string msg in data property
  doAnything(m.data)
}

// send message
channel.postMessage('hello world')

// handle error message
channel.onmessageerror = function(e) {
  //e is an Error object
}

// close channel
channel.close()