Socket
Socket
Sign inDemoInstall

broadcast-channel

Package Overview
Dependencies
20
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.12 to 2.2.0

dist/lib/browser.js

4

dist/es/method-chooser.js

@@ -1,5 +0,5 @@

import isNode from 'detect-node';
import NativeMethod from './methods/native.js';
import IndexeDbMethod from './methods/indexed-db.js';
import LocalstorageMethod from './methods/localstorage.js'; // order is important
import LocalstorageMethod from './methods/localstorage.js';
import { isNode } from './util'; // order is important

@@ -6,0 +6,0 @@ var METHODS = [NativeMethod, // fastest

@@ -6,4 +6,3 @@ /**

*/
import isNode from 'detect-node';
import { sleep, randomInt, randomToken, microSeconds as micro } from '../util.js';
import { sleep, randomInt, randomToken, microSeconds as micro, isNode } from '../util.js';
export var microSeconds = micro;

@@ -99,4 +98,3 @@ import ObliviousSet from '../oblivious-set';

if (cursor) {
ret.push(cursor.value); //alert("Name for SSN " + cursor.key + " is " + cursor.value.name);
ret.push(cursor.value);
cursor["continue"]();

@@ -213,3 +211,11 @@ } else {

return getMessagesHigherThen(state.db, state.lastCursorId).then(function (newerMessages) {
var useMessages = newerMessages.map(function (msgObj) {
var useMessages = newerMessages
/**
* there is a bug in iOS where the msgObj can be undefined some times
* so we filter them out
* @link https://github.com/pubkey/broadcast-channel/issues/19
*/
.filter(function (msgObj) {
return !!msgObj;
}).map(function (msgObj) {
if (msgObj.id > state.lastCursorId) {

@@ -216,0 +222,0 @@ state.lastCursorId = msgObj.id;

@@ -8,6 +8,5 @@ /**

*/
import isNode from 'detect-node';
import ObliviousSet from '../oblivious-set';
import { fillOptionsWithDefaults } from '../options';
import { sleep, randomToken, microSeconds as micro } from '../util';
import { sleep, randomToken, microSeconds as micro, isNode } from '../util';
export var microSeconds = micro;

@@ -14,0 +13,0 @@ var KEY_PREFIX = 'pubkey.broadcastChannel-';

@@ -1,3 +0,2 @@

import isNode from 'detect-node';
import { microSeconds as micro } from '../util';
import { microSeconds as micro, isNode } from '../util';
export var microSeconds = micro;

@@ -4,0 +3,0 @@ export var type = 'native';

@@ -56,2 +56,9 @@ /**

}
}
}
/**
* copied from the 'detect-node' npm module
* We cannot use the module directly because it causes problems with rollup
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
export var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';

@@ -10,4 +10,2 @@ "use strict";

var _detectNode = _interopRequireDefault(require("detect-node"));
var _native = _interopRequireDefault(require("./methods/native.js"));

@@ -19,2 +17,4 @@

var _util = require("./util");
// order is important

@@ -29,3 +29,3 @@ var METHODS = [_native["default"], // fastest

if (_detectNode["default"]) {
if (_util.isNode) {
/**

@@ -57,3 +57,3 @@ * we use the non-transpiled code for nodejs

if (!options.webWorkerSupport && !_detectNode["default"]) {
if (!options.webWorkerSupport && !_util.isNode) {
// prefer localstorage over idb when no webworker-support needed

@@ -60,0 +60,0 @@ chooseMethods = METHODS.filter(function (m) {

@@ -24,4 +24,2 @@ "use strict";

var _detectNode = _interopRequireDefault(require("detect-node"));
var _util = require("../util.js");

@@ -133,4 +131,3 @@

if (cursor) {
ret.push(cursor.value); //alert("Name for SSN " + cursor.key + " is " + cursor.value.name);
ret.push(cursor.value);
cursor["continue"]();

@@ -251,3 +248,11 @@ } else {

return getMessagesHigherThen(state.db, state.lastCursorId).then(function (newerMessages) {
var useMessages = newerMessages.map(function (msgObj) {
var useMessages = newerMessages
/**
* there is a bug in iOS where the msgObj can be undefined some times
* so we filter them out
* @link https://github.com/pubkey/broadcast-channel/issues/19
*/
.filter(function (msgObj) {
return !!msgObj;
}).map(function (msgObj) {
if (msgObj.id > state.lastCursorId) {

@@ -298,3 +303,3 @@ state.lastCursorId = msgObj.id;

function canBeUsed() {
if (_detectNode["default"]) return false;
if (_util.isNode) return false;
var idb = getIdb();

@@ -301,0 +306,0 @@ if (!idb) return false;

@@ -20,4 +20,2 @@ "use strict";

var _detectNode = _interopRequireDefault(require("detect-node"));
var _obliviousSet = _interopRequireDefault(require("../oblivious-set"));

@@ -162,3 +160,3 @@

function canBeUsed() {
if (_detectNode["default"]) return false;
if (_util.isNode) return false;
var ls = getLocalStorage();

@@ -165,0 +163,0 @@ if (!ls) return false;

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -16,4 +14,2 @@ value: true

var _detectNode = _interopRequireDefault(require("detect-node"));
var _util = require("../util");

@@ -62,3 +58,3 @@

*/
if (_detectNode["default"] && typeof window === 'undefined') return false;
if (_util.isNode && typeof window === 'undefined') return false;

@@ -65,0 +61,0 @@ if (typeof BroadcastChannel === 'function') {

@@ -11,2 +11,3 @@ "use strict";

exports.microSeconds = microSeconds;
exports.isNode = void 0;

@@ -72,2 +73,11 @@ /**

}
}
}
/**
* copied from the 'detect-node' npm module
* We cannot use the module directly because it causes problems with rollup
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
exports.isNode = isNode;

@@ -19,3 +19,9 @@ import BroadcastChannel from '../';

/**
* IMPORTANT: The leader election is lazy,
* it will not start before you call awaitLeadership()
* so isLeader will never become true then
*/
readonly isLeader: boolean;
readonly isDead: boolean;

@@ -39,2 +45,2 @@ readonly token: string;

export default _default;
export default _default;
{
"name": "broadcast-channel",
"version": "2.1.12",
"version": "2.2.0",
"description": "A BroadcastChannel shim/polyfill that works in New Browsers, Old Browsers, WebWorkers and NodeJs",

@@ -37,3 +37,3 @@ "homepage": "https://github.com/pubkey/broadcast-channel#readme",

"test:e2e": "concurrently \"npm run docs:serve\" \"sleep 5 && testcafe -b && testcafe all test/e2e.test.js\" --kill-others --success first",
"test:e2e:travis": "concurrently \"npm run docs:serve\" \"sleep 5 && testcafe -b && testcafe chrome test/e2e.test.js && testcafe chromium test/e2e.test.js && testcafe firefox test/e2e.test.js\" --kill-others --success first",
"test:e2e:travis": "concurrently \"npm run docs:serve\" \"sleep 5 && testcafe -b && testcafe chrome test/e2e.test.js && testcafe firefox test/e2e.test.js\" --kill-others --success first",
"test:typings": "npm run build && mocha ./test/typings.test.js -b --timeout 12000 --exit",

@@ -45,2 +45,3 @@ "test:performance": "npm run build && mocha ./test/performance.test.js -b --timeout 24000 --exit",

"size:browserify": "npm run build && rimraf test_tmp/browserify.js && browserify --no-builtins dist/lib/browserify.index.js > test_tmp/browserify.js && uglifyjs --compress --mangle --output test_tmp/browserify.min.js -- test_tmp/browserify.js && echo \"Build-Size browserify (minified+gzip):\" && gzip-size --raw test_tmp/browserify.min.js",
"size:rollup": "npm run build && rollup --config ./config/rollup.config.js && echo \"Build-Size Rollup (minified+gzip):\" && gzip-size --raw ./test_tmp/rollup.bundle.js",
"lint": "eslint src test config",

@@ -51,11 +52,13 @@ "clear": "rimraf -rf ./dist && rimraf -rf ./gen",

"build:test": "cross-env NODE_ENV=es5 babel test --out-dir test_tmp",
"build:browser": "browserify test_tmp/scripts/index.js > docs/index.js",
"build:index": "browserify test_tmp/scripts/index.js > docs/index.js",
"build:browser": "browserify test_tmp/scripts/e2e.js > docs/e2e.js",
"build:worker": "browserify test_tmp/scripts/worker.js > docs/worker.js",
"build:iframe": "browserify test_tmp/scripts/iframe.js > docs/iframe.js",
"build:leader-iframe": "browserify test_tmp/scripts/leader-iframe.js > docs/leader-iframe.js",
"build:leader-crown": "browserify test_tmp/scripts/leader-crown.js > docs/leader-crown.js",
"build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:test\" && concurrently \"npm run build:browser\" \"npm run build:worker\" \"npm run build:iframe\" \"npm run build:leader-iframe\" \"npm run build:leader-crown\"",
"build:lib-browser": "browserify dist/lib/browserify.index.js > dist/lib/browser.js",
"build:lib-browser:min": "uglifyjs --compress --mangle --output dist/lib/browser.min.js -- dist/lib/browser.js",
"build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:test\" && concurrently \"npm run build:index\" \"npm run build:browser\" \"npm run build:worker\" \"npm run build:iframe\" \"npm run build:leader-iframe\" && npm run build:lib-browser && npm run build:lib-browser:min",
"build:min": "uglifyjs --compress --mangle --output dist/lib/browserify.min.js -- dist/lib/browserify.index.js",
"docs:only": "http-server ./docs --silent",
"docs:serve": "npm run build && npm run docs:only"
"docs:serve": "npm run build && echo \"Open http://localhost:8080/\" && npm run docs:only"
},

@@ -66,3 +69,3 @@ "pre-commit": [

"dependencies": {
"@babel/runtime": "7.4.3",
"@babel/runtime": "7.5.5",
"detect-node": "2.0.4",

@@ -73,24 +76,24 @@ "js-sha3": "0.8.0",

"rimraf": "2.6.3",
"unload": "2.1.0"
"unload": "2.1.1"
},
"devDependencies": {
"@babel/cli": "7.4.3",
"@babel/core": "7.4.3",
"@babel/cli": "7.5.5",
"@babel/core": "7.5.5",
"@babel/plugin-check-constants": "7.0.0-beta.38",
"@babel/plugin-proposal-object-rest-spread": "7.4.3",
"@babel/plugin-proposal-object-rest-spread": "7.5.5",
"@babel/plugin-transform-member-expression-literals": "7.2.0",
"@babel/plugin-transform-property-literals": "7.2.0",
"@babel/plugin-transform-runtime": "7.4.3",
"@babel/polyfill": "7.4.3",
"@babel/preset-env": "7.4.3",
"@babel/types": "7.4.0",
"@types/core-js": "2.5.0",
"@babel/plugin-transform-runtime": "7.5.5",
"@babel/polyfill": "7.4.4",
"@babel/preset-env": "7.5.5",
"@babel/types": "7.5.5",
"@types/core-js": "2.5.2",
"assert": "1.4.1",
"async-test-util": "1.7.3",
"browserify": "16.2.3",
"browserify": "16.3.0",
"child-process-promise": "2.2.1",
"clone": "2.1.2",
"concurrently": "4.1.0",
"concurrently": "4.1.1",
"convert-hrtime": "3.0.0",
"copyfiles": "2.1.0",
"copyfiles": "2.1.1",
"cross-env": "5.2.0",

@@ -100,5 +103,5 @@ "eslint": "5.16.0",

"http-server": "0.11.1",
"karma": "4.1.0",
"karma-babel-preprocessor": "8.0.0",
"karma-browserify": "6.0.0",
"karma": "4.2.0",
"karma-babel-preprocessor": "8.0.1",
"karma-browserify": "6.1.0",
"karma-chrome-launcher": "2.2.0",

@@ -113,3 +116,3 @@ "karma-coverage": "1.1.2",

"karma-safari-launcher": "1.0.0",
"mocha": "6.1.3",
"mocha": "6.2.0",
"node": "11.13.0",

@@ -119,10 +122,13 @@ "pre-commit": "1.2.2",

"random-token": "0.0.8",
"testcafe": "1.1.2",
"testcafe-hammerhead": "14.6.2",
"rollup": "1.17.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-uglify": "^6.0.2",
"testcafe": "1.3.3",
"testcafe-hammerhead": "14.7.0",
"ts-node": "7.0.1",
"typescript": "3.4.3",
"uglifyjs-webpack-plugin": "2.1.2",
"typescript": "3.5.3",
"uglifyjs-webpack-plugin": "2.1.3",
"watchify": "3.11.1",
"webpack": "4.30.0",
"webpack-cli": "3.3.0"
"webpack": "4.37.0",
"webpack-cli": "3.3.6"
},

@@ -129,0 +135,0 @@ "browser": {

@@ -10,7 +10,7 @@

<p align="center">
<strong>A BroadcastChannel that works in old browsers, new browsers, WebWorkers and NodeJs</strong>
<strong>A BroadcastChannel to send data between different browser-tabs or nodejs-processes</strong>
<br/>
<span>+ LeaderElection over the channels</span>
<span>+ LeaderElection over the channels</span><br />
</p>
<p align="center">

@@ -24,11 +24,12 @@ <a alt="travis" href="https://travis-ci.org/pubkey/broadcast-channel">

<br/>
![demo.gif](docs/files/demo.gif)
* * *
A BroadcastChannel allows simple communication between browsing contexts with the same origin or different NodeJs processes.
A BroadcastChannel that allows you to send data between different browser-tabs or nodejs-processes.
This implementation works with old browsers, new browsers, WebWorkers and NodeJs. You can use it to send messages between multiple browser-tabs, iframes, WebWorkers and NodeJs-processes.
- It works completely **client-side** and **offline**.
- Tested on **old browsers**, **new browsers**, **WebWorkers**, **Iframes** and **NodeJs**
This behaves similar to the [BroadcastChannel-API](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) which is currently not featured in all browsers.
This behaves similar to the [BroadcastChannel-API](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) which is currently only featured in [some browsers](https://caniuse.com/#feat=broadcastchannel).

@@ -203,5 +204,5 @@ ## Using the BroadcastChannel

## Browser Support
I have tested this in all browsers that I could find. For ie8 and ie9 you must transpile the code before you can use this. If you want to know if this works with your browser, [open the demo page](https://pubkey.github.io/broadcast-channel/).
I have tested this in all browsers that I could find. For ie8 and ie9 you must transpile the code before you can use this. If you want to know if this works with your browser, [open the demo page](https://pubkey.github.io/broadcast-channel/e2e.html).
## Thanks
Thanks to [Hemanth.HM](https://github.com/hemanth) for the module name.

@@ -1,6 +0,7 @@

import isNode from 'detect-node';
import NativeMethod from './methods/native.js';
import IndexeDbMethod from './methods/indexed-db.js';
import LocalstorageMethod from './methods/localstorage.js';
import {
isNode
} from './util';

@@ -7,0 +8,0 @@ // order is important

@@ -7,4 +7,2 @@ /**

import isNode from 'detect-node';
import {

@@ -14,3 +12,4 @@ sleep,

randomToken,
microSeconds as micro
microSeconds as micro,
isNode
} from '../util.js';

@@ -112,3 +111,2 @@

ret.push(cursor.value);
//alert("Name for SSN " + cursor.key + " is " + cursor.value.name);
cursor.continue();

@@ -221,3 +219,3 @@ } else {

// channel already closed
if(state.closed) return Promise.resolve();
if (state.closed) return Promise.resolve();

@@ -230,2 +228,8 @@ // if no one is listening, we do not need to scan for new messages

const useMessages = newerMessages
/**
* there is a bug in iOS where the msgObj can be undefined some times
* so we filter them out
* @link https://github.com/pubkey/broadcast-channel/issues/19
*/
.filter(msgObj => !!msgObj)
.map(msgObj => {

@@ -265,3 +269,4 @@ if (msgObj.id > state.lastCursorId) {

if (randomInt(0, 10) === 0) {
/* await (do not await) */ cleanOldMessages(
/* await (do not await) */
cleanOldMessages(
channelState.db,

@@ -268,0 +273,0 @@ channelState.options.idb.ttl

@@ -9,3 +9,2 @@ /**

import isNode from 'detect-node';
import ObliviousSet from '../oblivious-set';

@@ -20,3 +19,4 @@

randomToken,
microSeconds as micro
microSeconds as micro,
isNode
} from '../util';

@@ -23,0 +23,0 @@

@@ -1,5 +0,4 @@

import isNode from 'detect-node';
import {
microSeconds as micro
microSeconds as micro,
isNode
} from '../util';

@@ -6,0 +5,0 @@

@@ -24,3 +24,2 @@ /**

/**

@@ -27,0 +26,0 @@ * windows sucks, so we have handle windows-type of socket-paths

@@ -57,2 +57,9 @@ /**

}
}
}
/**
* copied from the 'detect-node' npm module
* We cannot use the module directly because it causes problems with rollup
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
export const isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc