Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

broadcast-channel

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broadcast-channel - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

.github/workflows/main.yml

7

CHANGELOG.md
# CHANGELOG
## X.X.X (comming soon)
## 3.4.0 (24 January 2021)
Bugfixes:
- fix cursor error in Safari [#420](https://github.com/pubkey/broadcast-channel/pull/420)
## 3.3.0 (20 October 2020)

@@ -4,0 +11,0 @@

39

dist/es/broadcast-channel.js

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

import { isPromise } from './util.js';
import { chooseMethod } from './method-chooser.js';
import { fillOptionsWithDefaults } from './options.js';
export var BroadcastChannel = function BroadcastChannel(name, options) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clearNodeFolder = clearNodeFolder;
exports.enforceOptions = enforceOptions;
exports.BroadcastChannel = void 0;
var _util = require("./util.js");
var _methodChooser = require("./method-chooser.js");
var _options = require("./options.js");
var BroadcastChannel = function BroadcastChannel(name, options) {
this.name = name;

@@ -11,4 +23,4 @@

this.options = fillOptionsWithDefaults(options);
this.method = chooseMethod(this.options); // isListening
this.options = (0, _options.fillOptionsWithDefaults)(options);
this.method = (0, _methodChooser.chooseMethod)(this.options); // isListening

@@ -53,2 +65,4 @@ this._iL = false;

exports.BroadcastChannel = BroadcastChannel;
BroadcastChannel._pubkey = true;

@@ -60,5 +74,5 @@ /**

export function clearNodeFolder(options) {
options = fillOptionsWithDefaults(options);
var method = chooseMethod(options);
function clearNodeFolder(options) {
options = (0, _options.fillOptionsWithDefaults)(options);
var method = (0, _methodChooser.chooseMethod)(options);

@@ -78,7 +92,10 @@ if (method.type === 'node') {

var ENFORCED_OPTIONS;
export function enforceOptions(options) {
function enforceOptions(options) {
ENFORCED_OPTIONS = options;
} // PROTOTYPE
BroadcastChannel.prototype = {

@@ -169,3 +186,3 @@ postMessage: function postMessage(msg) {

if (isPromise(maybePromise)) {
if ((0, _util.isPromise)(maybePromise)) {
channel._prepP = maybePromise;

@@ -172,0 +189,0 @@ maybePromise.then(function (s) {

@@ -1,6 +0,8 @@

var module = require('./index.es5.js');
"use strict";
var BroadcastChannel = module.BroadcastChannel;
var createLeaderElection = module.createLeaderElection;
var _module = require('./index.es5.js');
var BroadcastChannel = _module.BroadcastChannel;
var createLeaderElection = _module.createLeaderElection;
window['BroadcastChannel2'] = BroadcastChannel;
window['createLeaderElection'] = createLeaderElection;

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

"use strict";
var _index = require("./index.js");
/**

@@ -9,8 +13,7 @@ * because babel can only export on default-attribute,

*/
import { BroadcastChannel, createLeaderElection, clearNodeFolder, enforceOptions } from './index.js';
module.exports = {
BroadcastChannel: BroadcastChannel,
createLeaderElection: createLeaderElection,
clearNodeFolder: clearNodeFolder,
enforceOptions: enforceOptions
BroadcastChannel: _index.BroadcastChannel,
createLeaderElection: _index.createLeaderElection,
clearNodeFolder: _index.clearNodeFolder,
enforceOptions: _index.enforceOptions
};

@@ -1,2 +0,33 @@

export { BroadcastChannel, clearNodeFolder, enforceOptions } from './broadcast-channel';
export { createLeaderElection } from './leader-election';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BroadcastChannel", {
enumerable: true,
get: function get() {
return _broadcastChannel.BroadcastChannel;
}
});
Object.defineProperty(exports, "clearNodeFolder", {
enumerable: true,
get: function get() {
return _broadcastChannel.clearNodeFolder;
}
});
Object.defineProperty(exports, "enforceOptions", {
enumerable: true,
get: function get() {
return _broadcastChannel.enforceOptions;
}
});
Object.defineProperty(exports, "createLeaderElection", {
enumerable: true,
get: function get() {
return _leaderElection.createLeaderElection;
}
});
var _broadcastChannel = require("./broadcast-channel");
var _leaderElection = require("./leader-election");

@@ -1,4 +0,14 @@

import { sleep, randomToken } from './util.js';
import unload from 'unload';
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createLeaderElection = createLeaderElection;
var _util = require("./util.js");
var _unload = _interopRequireDefault(require("unload"));
var LeaderElection = function LeaderElection(channel, options) {

@@ -9,3 +19,3 @@ this._channel = channel;

this.isDead = false;
this.token = randomToken();
this.token = (0, _util.randomToken)();
this._isApl = false; // _isApplying

@@ -61,3 +71,3 @@

.then(function () {
return sleep(_this._options.responseTime);
return (0, _util.sleep)(_this._options.responseTime);
}) // let others time to respond

@@ -67,3 +77,3 @@ .then(function () {

}).then(function () {
return sleep(_this._options.responseTime);
return (0, _util.sleep)(_this._options.responseTime);
}) // let others time to respond

@@ -182,3 +192,4 @@ .then(function () {

leaderElector.isLeader = true;
var unloadFn = unload.add(function () {
var unloadFn = _unload["default"].add(function () {
return leaderElector.die();

@@ -217,3 +228,3 @@ });

export function createLeaderElection(channel, options) {
function createLeaderElection(channel, options) {
if (channel._leaderElector) {

@@ -220,0 +231,0 @@ throw new Error('BroadcastChannel already has a leader-elector');

@@ -1,9 +0,23 @@

import NativeMethod from './methods/native.js';
import IndexeDbMethod from './methods/indexed-db.js';
import LocalstorageMethod from './methods/localstorage.js';
import SimulateMethod from './methods/simulate.js';
import { isNode } from './util'; // order is important
"use strict";
var METHODS = [NativeMethod, // fastest
IndexeDbMethod, LocalstorageMethod];
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.chooseMethod = chooseMethod;
var _native = _interopRequireDefault(require("./methods/native.js"));
var _indexedDb = _interopRequireDefault(require("./methods/indexed-db.js"));
var _localstorage = _interopRequireDefault(require("./methods/localstorage.js"));
var _simulate = _interopRequireDefault(require("./methods/simulate.js"));
var _util = require("./util");
// order is important
var METHODS = [_native["default"], // fastest
_indexedDb["default"], _localstorage["default"]];
/**

@@ -14,3 +28,3 @@ * The NodeMethod is loaded lazy

if (isNode) {
if (_util.isNode) {
/**

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

export function chooseMethod(options) {
function chooseMethod(options) {
var chooseMethods = [].concat(options.methods, METHODS).filter(Boolean); // directly chosen

@@ -42,3 +56,3 @@

// only use simulate-method if directly chosen
return SimulateMethod;
return _simulate["default"];
}

@@ -57,3 +71,3 @@

if (!options.webWorkerSupport && !isNode) {
if (!options.webWorkerSupport && !_util.isNode) {
chooseMethods = chooseMethods.filter(function (m) {

@@ -60,0 +74,0 @@ return m.type !== 'idb';

/**
* if you really need this method,
* implement it
*/
*/
"use strict";

@@ -0,1 +1,30 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getIdb = getIdb;
exports.createDatabase = createDatabase;
exports.writeMessage = writeMessage;
exports.getAllMessages = getAllMessages;
exports.getMessagesHigherThan = getMessagesHigherThan;
exports.removeMessageById = removeMessageById;
exports.getOldMessages = getOldMessages;
exports.cleanOldMessages = cleanOldMessages;
exports.create = create;
exports.close = close;
exports.postMessage = postMessage;
exports.onMessage = onMessage;
exports.canBeUsed = canBeUsed;
exports.averageResponseTime = averageResponseTime;
exports["default"] = exports.type = exports.microSeconds = void 0;
var _util = require("../util.js");
var _obliviousSet = _interopRequireDefault(require("../oblivious-set"));
var _options = require("../options");
/**

@@ -6,10 +35,10 @@ * this method uses indexeddb to store the messages

*/
import { sleep, randomInt, randomToken, microSeconds as micro, isNode } from '../util.js';
export var microSeconds = micro;
import ObliviousSet from '../oblivious-set';
import { fillOptionsWithDefaults } from '../options';
var microSeconds = _util.microSeconds;
exports.microSeconds = microSeconds;
var DB_PREFIX = 'pubkey.broadcast-channel-0-';
var OBJECT_STORE_ID = 'messages';
export var type = 'idb';
export function getIdb() {
var type = 'idb';
exports.type = type;
function getIdb() {
if (typeof indexedDB !== 'undefined') return indexedDB;

@@ -25,3 +54,4 @@

}
export function createDatabase(channelName) {
function createDatabase(channelName) {
var IndexedDB = getIdb(); // create table

@@ -56,3 +86,4 @@

export function writeMessage(db, readerUuid, messageJson) {
function writeMessage(db, readerUuid, messageJson) {
var time = new Date().getTime();

@@ -78,3 +109,4 @@ var writeObject = {

}
export function getAllMessages(db) {
function getAllMessages(db) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);

@@ -96,13 +128,30 @@ var ret = [];

}
export function getMessagesHigherThen(db, lastCursorId) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}
return new Promise(function (res) {
objectStore.openCursor(keyRangeValue).onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;
if (cursor) {
ret.push(cursor.value);
cursor["continue"]();
if (cursor.value.id < lastCursorId + 1) {
cursor["continue"](lastCursorId + 1);
} else {
ret.push(cursor.value);
cursor["continue"]();
}
} else {

@@ -114,3 +163,4 @@ res(ret);

}
export function removeMessageById(db, id) {
function removeMessageById(db, id) {
var request = db.transaction([OBJECT_STORE_ID], 'readwrite').objectStore(OBJECT_STORE_ID)["delete"](id);

@@ -123,3 +173,4 @@ return new Promise(function (res) {

}
export function getOldMessages(db, ttl) {
function getOldMessages(db, ttl) {
var olderThen = new Date().getTime() - ttl;

@@ -150,3 +201,4 @@ var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);

}
export function cleanOldMessages(db, ttl) {
function cleanOldMessages(db, ttl) {
return getOldMessages(db, ttl).then(function (tooOld) {

@@ -158,4 +210,5 @@ return Promise.all(tooOld.map(function (msgObj) {

}
export function create(channelName, options) {
options = fillOptionsWithDefaults(options);
function create(channelName, options) {
options = (0, _options.fillOptionsWithDefaults)(options);
return createDatabase(channelName).then(function (db) {

@@ -167,3 +220,3 @@ var state = {

options: options,
uuid: randomToken(),
uuid: (0, _util.randomToken)(),

@@ -175,3 +228,3 @@ /**

*/
eMIs: new ObliviousSet(options.idb.ttl * 2),
eMIs: new _obliviousSet["default"](options.idb.ttl * 2),
// ensures we do not read messages in parrallel

@@ -210,3 +263,3 @@ writeBlockPromise: Promise.resolve(),

readNewMessages(state).then(function () {
return sleep(state.options.idb.fallbackInterval);
return (0, _util.sleep)(state.options.idb.fallbackInterval);
}).then(function () {

@@ -236,3 +289,3 @@ return _readLoop(state);

if (!state.messagesCallback) return Promise.resolve();
return getMessagesHigherThen(state.db, state.lastCursorId).then(function (newerMessages) {
return getMessagesHigherThan(state.db, state.lastCursorId).then(function (newerMessages) {
var useMessages = newerMessages

@@ -268,11 +321,12 @@ /**

export function close(channelState) {
function close(channelState) {
channelState.closed = true;
channelState.db.close();
}
export function postMessage(channelState, messageJson) {
function postMessage(channelState, messageJson) {
channelState.writeBlockPromise = channelState.writeBlockPromise.then(function () {
return writeMessage(channelState.db, channelState.uuid, messageJson);
}).then(function () {
if (randomInt(0, 10) === 0) {
if ((0, _util.randomInt)(0, 10) === 0) {
/* await (do not await) */

@@ -284,3 +338,4 @@ cleanOldMessages(channelState.db, channelState.options.idb.ttl);

}
export function onMessage(channelState, fn, time) {
function onMessage(channelState, fn, time) {
channelState.messagesCallbackTime = time;

@@ -290,4 +345,5 @@ channelState.messagesCallback = fn;

}
export function canBeUsed() {
if (isNode) return false;
function canBeUsed() {
if (_util.isNode) return false;
var idb = getIdb();

@@ -297,6 +353,8 @@ if (!idb) return false;

}
export function averageResponseTime(options) {
function averageResponseTime(options) {
return options.idb.fallbackInterval * 2;
}
export default {
var _default = {
create: create,

@@ -310,2 +368,3 @@ close: close,

microSeconds: microSeconds
};
};
exports["default"] = _default;

@@ -0,1 +1,26 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLocalStorage = getLocalStorage;
exports.storageKey = storageKey;
exports.postMessage = postMessage;
exports.addStorageEventListener = addStorageEventListener;
exports.removeStorageEventListener = removeStorageEventListener;
exports.create = create;
exports.close = close;
exports.onMessage = onMessage;
exports.canBeUsed = canBeUsed;
exports.averageResponseTime = averageResponseTime;
exports["default"] = exports.type = exports.microSeconds = void 0;
var _obliviousSet = _interopRequireDefault(require("../oblivious-set"));
var _options = require("../options");
var _util = require("../util");
/**

@@ -8,8 +33,6 @@ * A localStorage-only method which uses localstorage and its 'storage'-event

*/
import ObliviousSet from '../oblivious-set';
import { fillOptionsWithDefaults } from '../options';
import { sleep, randomToken, microSeconds as micro, isNode } from '../util';
export var microSeconds = micro;
var microSeconds = _util.microSeconds;
exports.microSeconds = microSeconds;
var KEY_PREFIX = 'pubkey.broadcastChannel-';
export var type = 'localstorage';
var type = 'localstorage';
/**

@@ -20,3 +43,5 @@ * copied from crosstab

export function getLocalStorage() {
exports.type = type;
function getLocalStorage() {
var localStorage;

@@ -35,3 +60,4 @@ if (typeof window === 'undefined') return null;

}
export function storageKey(channelName) {
function storageKey(channelName) {
return KEY_PREFIX + channelName;

@@ -44,8 +70,9 @@ }

export function postMessage(channelState, messageJson) {
function postMessage(channelState, messageJson) {
return new Promise(function (res) {
sleep().then(function () {
(0, _util.sleep)().then(function () {
var key = storageKey(channelState.channelName);
var writeObj = {
token: randomToken(),
token: (0, _util.randomToken)(),
time: new Date().getTime(),

@@ -72,3 +99,4 @@ data: messageJson,

}
export function addStorageEventListener(channelName, fn) {
function addStorageEventListener(channelName, fn) {
var key = storageKey(channelName);

@@ -85,8 +113,10 @@

}
export function removeStorageEventListener(listener) {
function removeStorageEventListener(listener) {
window.removeEventListener('storage', listener);
}
export function create(channelName, options) {
options = fillOptionsWithDefaults(options);
function create(channelName, options) {
options = (0, _options.fillOptionsWithDefaults)(options);
if (!canBeUsed()) {

@@ -96,3 +126,3 @@ throw new Error('BroadcastChannel: localstorage cannot be used');

var uuid = randomToken();
var uuid = (0, _util.randomToken)();
/**

@@ -104,3 +134,3 @@ * eMIs

var eMIs = new ObliviousSet(options.localstorage.removeTimeout);
var eMIs = new _obliviousSet["default"](options.localstorage.removeTimeout);
var state = {

@@ -126,11 +156,14 @@ channelName: channelName,

}
export function close(channelState) {
function close(channelState) {
removeStorageEventListener(channelState.listener);
}
export function onMessage(channelState, fn, time) {
function onMessage(channelState, fn, time) {
channelState.messagesCallbackTime = time;
channelState.messagesCallback = fn;
}
export function canBeUsed() {
if (isNode) return false;
function canBeUsed() {
if (_util.isNode) return false;
var ls = getLocalStorage();

@@ -152,3 +185,4 @@ if (!ls) return false;

}
export function averageResponseTime() {
function averageResponseTime() {
var defaultTime = 120;

@@ -164,3 +198,4 @@ var userAgent = navigator.userAgent.toLowerCase();

}
export default {
var _default = {
create: create,

@@ -174,2 +209,3 @@ close: close,

microSeconds: microSeconds
};
};
exports["default"] = _default;

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

import { microSeconds as micro, isNode } from '../util';
export var microSeconds = micro;
export var type = 'native';
export function create(channelName) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.create = create;
exports.close = close;
exports.postMessage = postMessage;
exports.onMessage = onMessage;
exports.canBeUsed = canBeUsed;
exports.averageResponseTime = averageResponseTime;
exports["default"] = exports.type = exports.microSeconds = void 0;
var _util = require("../util");
var microSeconds = _util.microSeconds;
exports.microSeconds = microSeconds;
var type = 'native';
exports.type = type;
function create(channelName) {
var state = {

@@ -20,13 +37,17 @@ messagesCallback: null,

}
export function close(channelState) {
function close(channelState) {
channelState.bc.close();
channelState.subFns = [];
}
export function postMessage(channelState, messageJson) {
function postMessage(channelState, messageJson) {
channelState.bc.postMessage(messageJson, false);
}
export function onMessage(channelState, fn) {
function onMessage(channelState, fn) {
channelState.messagesCallback = fn;
}
export function canBeUsed() {
function canBeUsed() {
/**

@@ -36,3 +57,3 @@ * in the electron-renderer, isNode will be true even if we are in browser-context

*/
if (isNode && typeof window === 'undefined') return false;
if (_util.isNode && typeof window === 'undefined') return false;

@@ -47,6 +68,8 @@ if (typeof BroadcastChannel === 'function') {

}
export function averageResponseTime() {
function averageResponseTime() {
return 150;
}
export default {
var _default = {
create: create,

@@ -60,2 +83,3 @@ close: close,

microSeconds: microSeconds
};
};
exports["default"] = _default;

@@ -1,4 +0,9 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
/**

@@ -99,4 +104,4 @@ * this method is used in nodejs-environments.

function _ensureBaseFolderExists() {
_ensureBaseFolderExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
_ensureBaseFolderExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {

@@ -133,5 +138,5 @@ switch (_context4.prev = _context4.next) {

function _ensureFoldersExist() {
_ensureFoldersExist = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(channelName, paths) {
_ensureFoldersExist = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(channelName, paths) {
var chmodValue;
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {

@@ -181,4 +186,4 @@ switch (_context5.prev = _context5.next) {

function _clearNodeFolder() {
_clearNodeFolder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
_clearNodeFolder = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {

@@ -250,5 +255,5 @@ switch (_context6.prev = _context6.next) {

function _countChannelFolders() {
_countChannelFolders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
_countChannelFolders = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
var folders;
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {

@@ -288,5 +293,5 @@ switch (_context7.prev = _context7.next) {

function _connectionError() {
_connectionError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(originalError) {
_connectionError = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(originalError) {
var count, addObj, text, newError;
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) {

@@ -334,5 +339,5 @@ switch (_context8.prev = _context8.next) {

function _createSocketEventEmitter() {
_createSocketEventEmitter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(channelName, readerUuid, paths) {
_createSocketEventEmitter = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(channelName, readerUuid, paths) {
var pathToSocket, emitter, server;
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
return _regenerator["default"].wrap(function _callee11$(_context11) {
while (1) {

@@ -352,5 +357,5 @@ switch (_context11.prev = _context11.next) {

server.on('error', /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(err) {
var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(err) {
var useErr;
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) {

@@ -379,5 +384,5 @@ switch (_context9.prev = _context9.next) {

server.listen(pathToSocket, /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(err, res) {
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(err, res) {
var useErr;
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
return _regenerator["default"].wrap(function _callee10$(_context10) {
while (1) {

@@ -445,5 +450,5 @@ switch (_context10.prev = _context10.next) {

function _openClientConnection() {
_openClientConnection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(channelName, readerUuid) {
_openClientConnection = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(channelName, readerUuid) {
var pathToSocket, client;
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
return _regenerator["default"].wrap(function _callee12$(_context12) {
while (1) {

@@ -504,5 +509,5 @@ switch (_context12.prev = _context12.next) {

function _getReadersUuids() {
_getReadersUuids = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(channelName, paths) {
_getReadersUuids = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(channelName, paths) {
var readersPath, files;
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
return _regenerator["default"].wrap(function _callee13$(_context13) {
while (1) {

@@ -542,5 +547,5 @@ switch (_context13.prev = _context13.next) {

function _messagePath() {
_messagePath = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(channelName, time, token, writerUuid) {
_messagePath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(channelName, time, token, writerUuid) {
var fileName, msgPath;
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
return _regenerator["default"].wrap(function _callee14$(_context14) {
while (1) {

@@ -568,5 +573,5 @@ switch (_context14.prev = _context14.next) {

function _getAllMessages() {
_getAllMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(channelName, paths) {
_getAllMessages = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(channelName, paths) {
var messagesPath, files;
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
return _regenerator["default"].wrap(function _callee15$(_context15) {
while (1) {

@@ -624,5 +629,5 @@ switch (_context15.prev = _context15.next) {

function _cleanOldMessages() {
_cleanOldMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(messageObjects, ttl) {
_cleanOldMessages = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(messageObjects, ttl) {
var olderThen;
return _regeneratorRuntime.wrap(function _callee16$(_context16) {
return _regenerator["default"].wrap(function _callee16$(_context16) {
while (1) {

@@ -662,3 +667,3 @@ switch (_context16.prev = _context16.next) {

function _create() {
_create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(channelName) {
_create = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(channelName) {
var options,

@@ -675,3 +680,3 @@ time,

return _regeneratorRuntime.wrap(function _callee17$(_context17) {
return _regenerator["default"].wrap(function _callee17$(_context17) {
while (1) {

@@ -778,5 +783,5 @@ switch (_context17.prev = _context17.next) {

function _handleMessagePing() {
_handleMessagePing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(state, msgObj) {
_handleMessagePing = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(state, msgObj) {
var messages, useMessages;
return _regeneratorRuntime.wrap(function _callee18$(_context18) {
return _regenerator["default"].wrap(function _callee18$(_context18) {
while (1) {

@@ -859,4 +864,4 @@ switch (_context18.prev = _context18.next) {

}).forEach( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(readerUuid) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(readerUuid) {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {

@@ -900,5 +905,5 @@ switch (_context.prev = _context.next) {

.map( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(readerUuid) {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(readerUuid) {
var client;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {

@@ -961,6 +966,6 @@ switch (_context2.prev = _context2.next) {

var writePromise = writeMessage(channelState.channelName, channelState.uuid, messageJson, channelState.paths);
channelState.writeBlockPromise = channelState.writeBlockPromise.then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
channelState.writeBlockPromise = channelState.writeBlockPromise.then( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
var _yield$Promise$all, msgObj, pingStr, writeToReadersPromise;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {

@@ -967,0 +972,0 @@ switch (_context3.prev = _context3.next) {

@@ -1,6 +0,23 @@

import { microSeconds as micro } from '../util';
export var microSeconds = micro;
export var type = 'simulate';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.create = create;
exports.close = close;
exports.postMessage = postMessage;
exports.onMessage = onMessage;
exports.canBeUsed = canBeUsed;
exports.averageResponseTime = averageResponseTime;
exports["default"] = exports.type = exports.microSeconds = void 0;
var _util = require("../util");
var microSeconds = _util.microSeconds;
exports.microSeconds = microSeconds;
var type = 'simulate';
exports.type = type;
var SIMULATE_CHANNELS = new Set();
export function create(channelName) {
function create(channelName) {
var state = {

@@ -13,6 +30,8 @@ name: channelName,

}
export function close(channelState) {
function close(channelState) {
SIMULATE_CHANNELS["delete"](channelState);
}
export function postMessage(channelState, messageJson) {
function postMessage(channelState, messageJson) {
return new Promise(function (res) {

@@ -34,12 +53,16 @@ return setTimeout(function () {

}
export function onMessage(channelState, fn) {
function onMessage(channelState, fn) {
channelState.messagesCallback = fn;
}
export function canBeUsed() {
function canBeUsed() {
return true;
}
export function averageResponseTime() {
function averageResponseTime() {
return 5;
}
export default {
var _default = {
create: create,

@@ -53,2 +76,3 @@ close: close,

microSeconds: microSeconds
};
};
exports["default"] = _default;

@@ -0,1 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
/**

@@ -49,2 +56,3 @@ * this is a set which automatically forgets

export default ObliviousSet;
var _default = ObliviousSet;
exports["default"] = _default;

@@ -1,2 +0,9 @@

export function fillOptionsWithDefaults() {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fillOptionsWithDefaults = fillOptionsWithDefaults;
function fillOptionsWithDefaults() {
var originalOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

@@ -3,0 +10,0 @@ var options = JSON.parse(JSON.stringify(originalOptions)); // main

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

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isPromise = isPromise;
exports.sleep = sleep;
exports.randomInt = randomInt;
exports.randomToken = randomToken;
exports.microSeconds = microSeconds;
exports.isNode = void 0;
/**
* returns true if the given object is a promise
*/
export function isPromise(obj) {
function isPromise(obj) {
if (obj && typeof obj.then === 'function') {

@@ -11,3 +23,4 @@ return true;

}
export function sleep(time) {
function sleep(time) {
if (!time) time = 0;

@@ -18,3 +31,4 @@ return new Promise(function (res) {

}
export function randomInt(min, max) {
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);

@@ -26,5 +40,7 @@ }

export function randomToken() {
function randomToken() {
return Math.random().toString(36).substring(2);
}
var lastMs = 0;

@@ -40,3 +56,3 @@ var additional = 0;

export function microSeconds() {
function microSeconds() {
var ms = new Date().getTime();

@@ -59,2 +75,4 @@

export var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
exports.isNode = isNode;

@@ -645,3 +645,3 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

exports.getAllMessages = getAllMessages;
exports.getMessagesHigherThen = getMessagesHigherThen;
exports.getMessagesHigherThan = getMessagesHigherThan;
exports.removeMessageById = removeMessageById;

@@ -759,13 +759,29 @@ exports.getOldMessages = getOldMessages;

function getMessagesHigherThen(db, lastCursorId) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}
return new Promise(function (res) {
objectStore.openCursor(keyRangeValue).onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;
if (cursor) {
ret.push(cursor.value);
cursor["continue"]();
if (cursor.value.id < lastCursorId + 1) {
cursor["continue"](lastCursorId + 1);
} else {
ret.push(cursor.value);
cursor["continue"]();
}
} else {

@@ -896,3 +912,3 @@ res(ret);

if (!state.messagesCallback) return Promise.resolve();
return getMessagesHigherThen(state.db, state.lastCursorId).then(function (newerMessages) {
return getMessagesHigherThan(state.db, state.lastCursorId).then(function (newerMessages) {
var useMessages = newerMessages

@@ -899,0 +915,0 @@ /**

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

!function r(o,i,s){function a(t,e){if(!i[t]){if(!o[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(u)return u(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},o[t][0].call(n.exports,function(e){return a(o[t][1][e]||e)},n,n.exports,r,o,i,s)}return i[t].exports}for(var u="function"==typeof require&&require,e=0;e<s.length;e++)a(s[e]);return a}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.clearNodeFolder=function(e){e=(0,s.fillOptionsWithDefaults)(e);e=(0,i.chooseMethod)(e);return"node"===e.type?e.clearNodeFolder().then(function(){return!0}):Promise.resolve(!1)},n.enforceOptions=function(e){r=e},n.BroadcastChannel=void 0;var r,o=e("./util.js"),i=e("./method-chooser.js"),s=e("./options.js"),e=function(e,t){var n;this.name=e,r&&(t=r),this.options=(0,s.fillOptionsWithDefaults)(t),this.method=(0,i.chooseMethod)(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._befC=[],this._prepP=null,t=(n=this).method.create(n.name,n.options),(0,o.isPromise)(t)?(n._prepP=t).then(function(e){n._state=e}):n._state=t};function a(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._prepP||Promise.resolve()).then(function(){return e.method.postMessage(e._state,r)})}function u(e){return 0<e._addEL.message.length||0<e._addEL.internal.length}function c(e,t,n){e._addEL[t].push(n),function(e){{var t,n;!e._iL&&u(e)&&(t=function(t){e._addEL[t.type].forEach(function(e){t.time>=e.time&&e.fn(t.data)})},n=e.method.microSeconds(),e._prepP?e._prepP.then(function(){e._iL=!0,e.method.onMessage(e._state,t,n)}):(e._iL=!0,e.method.onMessage(e._state,t,n)))}}(e)}function l(e,t,n){e._addEL[t]=e._addEL[t].filter(function(e){return e!==n}),function(e){{var t;e._iL&&!u(e)&&(e._iL=!1,t=e.method.microSeconds(),e.method.onMessage(e._state,null,t))}}(e)}(n.BroadcastChannel=e)._pubkey=!0,e.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed");return a(this,"message",e)},postInternal:function(e){return a(this,"internal",e)},set onmessage(e){var t={time:this.method.microSeconds(),fn:e};l(this,"message",this._onML),e&&"function"==typeof e?(this._onML=t,c(this,"message",t)):this._onML=null},addEventListener:function(e,t){var n=this.method.microSeconds();c(this,e,{time:n,fn:t})},removeEventListener:function(e,t){var n=this._addEL[e].find(function(e){return e.fn===t});l(this,e,n)},close:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._prepP||Promise.resolve();return this._onML=null,this._addEL.message=[],t.then(function(){return Promise.all(e._befC.map(function(e){return e()}))}).then(function(){return e.method.close(e._state)})}},get type(){return this.method.type}}},{"./method-chooser.js":6,"./options.js":12,"./util.js":13}],2:[function(e,t,n){"use strict";var r=e("./index.es5.js"),e=r.BroadcastChannel,r=r.createLeaderElection;window.BroadcastChannel2=e,window.createLeaderElection=r},{"./index.es5.js":3}],3:[function(e,t,n){"use strict";e=e("./index.js");t.exports={BroadcastChannel:e.BroadcastChannel,createLeaderElection:e.createLeaderElection,clearNodeFolder:e.clearNodeFolder,enforceOptions:e.enforceOptions}},{"./index.js":4}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"BroadcastChannel",{enumerable:!0,get:function(){return r.BroadcastChannel}}),Object.defineProperty(n,"clearNodeFolder",{enumerable:!0,get:function(){return r.clearNodeFolder}}),Object.defineProperty(n,"enforceOptions",{enumerable:!0,get:function(){return r.enforceOptions}}),Object.defineProperty(n,"createLeaderElection",{enumerable:!0,get:function(){return o.createLeaderElection}});var r=e("./broadcast-channel"),o=e("./leader-election")},{"./broadcast-channel":1,"./leader-election":5}],5:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.createLeaderElection=function(e,t){if(e._leaderElector)throw new Error("BroadcastChannel already has a leader-elector");t=function(e,t){e=e||{};(e=JSON.parse(JSON.stringify(e))).fallbackInterval||(e.fallbackInterval=3e3);e.responseTime||(e.responseTime=t.method.averageResponseTime(t.options));return e}(t,e);var n=new o(e,t);return e._befC.push(function(){return n.die()}),e._leaderElector=n};var i=e("./util.js"),s=r(e("unload")),o=function(e,t){this._channel=e,this._options=t,this.isLeader=!1,this.isDead=!1,this.token=(0,i.randomToken)(),this._isApl=!1,this._reApply=!1,this._unl=[],this._lstns=[],this._invs=[]};function a(e,t){t={context:"leader",action:t,token:e.token};return e._channel.postInternal(t)}o.prototype={applyOnce:function(){var t=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApl)return this._reApply=!0,Promise.resolve(!1);function n(e){"leader"===e.context&&e.token!=t.token&&(o.push(e),"apply"===e.action&&e.token>t.token&&(r=!0),"tell"===e.action&&(r=!0))}var r=!(this._isApl=!0),o=[];return this._channel.addEventListener("internal",n),a(this,"apply").then(function(){return(0,i.sleep)(t._options.responseTime)}).then(function(){return r?Promise.reject(new Error):a(t,"apply")}).then(function(){return(0,i.sleep)(t._options.responseTime)}).then(function(){return r?Promise.reject(new Error):a(t)}).then(function(){return function(t){t.isLeader=!0;var e=s.default.add(function(){return t.die()});t._unl.push(e);e=function(e){"leader"===e.context&&"apply"===e.action&&a(t,"tell")};return t._channel.addEventListener("internal",e),t._lstns.push(e),a(t,"tell")}(t)}).then(function(){return!0}).catch(function(){return!1}).then(function(e){return t._channel.removeEventListener("internal",n),t._isApl=!1,!e&&t._reApply?(t._reApply=!1,t.applyOnce()):e})},awaitLeadership:function(){var i;return this._aLP||(this._aLP=(i=this).isLeader?Promise.resolve():new Promise(function(e){function t(){n||(n=!0,clearInterval(r),i._channel.removeEventListener("internal",o),e(!0))}var n=!1;i.applyOnce().then(function(){i.isLeader&&t()});var r=setInterval(function(){i.applyOnce().then(function(){i.isLeader&&t()})},i._options.fallbackInterval);i._invs.push(r);var o=function(e){"leader"===e.context&&"death"===e.action&&i.applyOnce().then(function(){i.isLeader&&t()})};i._channel.addEventListener("internal",o),i._lstns.push(o)})),this._aLP},die:function(){var t=this;if(!this.isDead)return this.isDead=!0,this._lstns.forEach(function(e){return t._channel.removeEventListener("internal",e)}),this._invs.forEach(function(e){return clearInterval(e)}),this._unl.forEach(function(e){e.remove()}),a(this,"death")}}},{"./util.js":13,"@babel/runtime/helpers/interopRequireDefault":14,unload:19}],6:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.chooseMethod=function(t){var e=[].concat(t.methods,u).filter(Boolean);if(t.type){if("simulate"===t.type)return s.default;var n=e.find(function(e){return e.type===t.type});if(n)return n;throw new Error("method-type "+t.type+" not found")}t.webWorkerSupport||a.isNode||(e=e.filter(function(e){return"idb"!==e.type}));e=e.find(function(e){return e.canBeUsed()});{if(e)return e;throw new Error("No useable methode found:"+JSON.stringify(u.map(function(e){return e.type})))}};var o=r(e("./methods/native.js")),i=r(e("./methods/indexed-db.js")),n=r(e("./methods/localstorage.js")),s=r(e("./methods/simulate.js")),a=e("./util"),u=[o.default,i.default,n.default];!a.isNode||"function"==typeof(e=e("../../src/methods/node.js")).canBeUsed&&u.push(e)},{"./methods/indexed-db.js":7,"./methods/localstorage.js":8,"./methods/native.js":9,"./methods/simulate.js":10,"./util":13,"@babel/runtime/helpers/interopRequireDefault":14}],7:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.getIdb=c,n.createDatabase=l,n.writeMessage=d,n.getAllMessages=function(e){var n=e.transaction(u).objectStore(u),r=[];return new Promise(function(t){n.openCursor().onsuccess=function(e){e=e.target.result;e?(r.push(e.value),e.continue()):t(r)}})},n.getMessagesHigherThen=f,n.removeMessageById=h,n.getOldMessages=p,n.cleanOldMessages=m,n.create=v,n.close=g,n.postMessage=w,n.onMessage=_,n.canBeUsed=y,n.averageResponseTime=k,n.default=n.type=n.microSeconds=void 0;var o=e("../util.js"),i=r(e("../oblivious-set")),s=e("../options"),e=o.microSeconds;n.microSeconds=e;var a="pubkey.broadcast-channel-0-",u="messages";function c(){if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof window){if(void 0!==window.mozIndexedDB)return window.mozIndexedDB;if(void 0!==window.webkitIndexedDB)return window.webkitIndexedDB;if(void 0!==window.msIndexedDB)return window.msIndexedDB}return!1}function l(e){var t=c(),e=a+e,n=t.open(e,1);return n.onupgradeneeded=function(e){e.target.result.createObjectStore(u,{keyPath:"id",autoIncrement:!0})},new Promise(function(e,t){n.onerror=function(e){return t(e)},n.onsuccess=function(){e(n.result)}})}function d(e,t,n){var r={uuid:t,time:(new Date).getTime(),data:n},o=e.transaction([u],"readwrite");return new Promise(function(e,t){o.oncomplete=function(){return e()},o.onerror=function(e){return t(e)},o.objectStore(u).add(r)})}function f(e,t){var n=e.transaction(u).objectStore(u),r=[],o=IDBKeyRange.bound(t+1,1/0);return new Promise(function(t){n.openCursor(o).onsuccess=function(e){e=e.target.result;e?(r.push(e.value),e.continue()):t(r)}})}function h(e,t){var n=e.transaction([u],"readwrite").objectStore(u).delete(t);return new Promise(function(e){n.onsuccess=function(){return e()}})}function p(e,t){var r=(new Date).getTime()-t,o=e.transaction(u).objectStore(u),i=[];return new Promise(function(n){o.openCursor().onsuccess=function(e){var t,e=e.target.result;e&&(t=e.value).time<r?(i.push(t),e.continue()):n(i)}})}function m(t,e){return p(t,e).then(function(e){return Promise.all(e.map(function(e){return h(t,e.id)}))})}function v(n,r){return r=(0,s.fillOptionsWithDefaults)(r),l(n).then(function(e){var t={closed:!1,lastCursorId:0,channelName:n,options:r,uuid:(0,o.randomToken)(),eMIs:new i.default(2*r.idb.ttl),writeBlockPromise:Promise.resolve(),messagesCallback:null,readQueuePromises:[],db:e};return e.onclose=function(){t.closed=!0,r.idb.onclose&&r.idb.onclose()},function e(t){if(t.closed)return;b(t).then(function(){return(0,o.sleep)(t.options.idb.fallbackInterval)}).then(function(){return e(t)})}(t),t})}function b(n){return!n.closed&&n.messagesCallback?f(n.db,n.lastCursorId).then(function(e){return e.filter(function(e){return!!e}).map(function(e){return e.id>n.lastCursorId&&(n.lastCursorId=e.id),e}).filter(function(e){return t=n,(e=e).uuid!==t.uuid&&(!t.eMIs.has(e.id)&&!(e.data.time<t.messagesCallbackTime));var t}).sort(function(e,t){return e.time-t.time}).forEach(function(e){n.messagesCallback&&(n.eMIs.add(e.id),n.messagesCallback(e.data))}),Promise.resolve()}):Promise.resolve()}function g(e){e.closed=!0,e.db.close()}function w(e,t){return e.writeBlockPromise=e.writeBlockPromise.then(function(){return d(e.db,e.uuid,t)}).then(function(){0===(0,o.randomInt)(0,10)&&m(e.db,e.options.idb.ttl)}),e.writeBlockPromise}function _(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t,b(e)}function y(){return!o.isNode&&!!c()}function k(e){return 2*e.idb.fallbackInterval}e={create:v,close:g,onMessage:_,postMessage:w,canBeUsed:y,type:n.type="idb",averageResponseTime:k,microSeconds:e};n.default=e},{"../oblivious-set":11,"../options":12,"../util.js":13,"@babel/runtime/helpers/interopRequireDefault":14}],8:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.getLocalStorage=u,n.storageKey=c,n.postMessage=l,n.addStorageEventListener=d,n.removeStorageEventListener=f,n.create=h,n.close=p,n.onMessage=m,n.canBeUsed=v,n.averageResponseTime=b,n.default=n.type=n.microSeconds=void 0;var i=r(e("../oblivious-set")),s=e("../options"),a=e("../util"),r=a.microSeconds;n.microSeconds=r;var o="pubkey.broadcastChannel-",e="localstorage";function u(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function c(e){return o+e}function l(o,i){return new Promise(function(r){(0,a.sleep)().then(function(){var e=c(o.channelName),t={token:(0,a.randomToken)(),time:(new Date).getTime(),data:i,uuid:o.uuid},n=JSON.stringify(t);u().setItem(e,n);t=document.createEvent("Event");t.initEvent("storage",!0,!0),t.key=e,t.newValue=n,window.dispatchEvent(t),r()})})}function d(e,t){var n=o+e,e=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",e),e}function f(e){window.removeEventListener("storage",e)}function h(e,t){if(t=(0,s.fillOptionsWithDefaults)(t),!v())throw new Error("BroadcastChannel: localstorage cannot be used");var n=(0,a.randomToken)(),r=new i.default(t.localstorage.removeTimeout),o={channelName:e,uuid:n,eMIs:r};return o.listener=d(e,function(e){o.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<o.messagesCallbackTime||(r.add(e.token),o.messagesCallback(e.data)))}),o}function p(e){f(e.listener)}function m(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t}function v(){if(a.isNode)return!1;var e=u();if(!e)return!1;try{var t="__broadcastchannel_check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}function b(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}r={create:h,close:p,onMessage:m,postMessage:l,canBeUsed:v,type:n.type=e,averageResponseTime:b,microSeconds:r};n.default=r},{"../oblivious-set":11,"../options":12,"../util":13,"@babel/runtime/helpers/interopRequireDefault":14}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.create=o,n.close=i,n.postMessage=s,n.onMessage=a,n.canBeUsed=u,n.averageResponseTime=c,n.default=n.type=n.microSeconds=void 0;var r=e("../util"),e=r.microSeconds;n.microSeconds=e;function o(e){var t={messagesCallback:null,bc:new BroadcastChannel(e),subFns:[]};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t}function i(e){e.bc.close(),e.subFns=[]}function s(e,t){e.bc.postMessage(t,!1)}function a(e,t){e.messagesCallback=t}function u(){if(r.isNode&&"undefined"==typeof window)return!1;if("function"!=typeof BroadcastChannel)return!1;if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}function c(){return 150}e={create:o,close:i,onMessage:a,postMessage:s,canBeUsed:u,type:n.type="native",averageResponseTime:c,microSeconds:e};n.default=e},{"../util":13}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.create=i,n.close=s,n.postMessage=a,n.onMessage=u,n.canBeUsed=c,n.averageResponseTime=l,n.default=n.type=n.microSeconds=void 0;var r=e("../util").microSeconds;n.microSeconds=r;e="simulate";n.type=e;var o=new Set;function i(e){e={name:e,messagesCallback:null};return o.add(e),e}function s(e){o.delete(e)}function a(t,n){return new Promise(function(e){return setTimeout(function(){Array.from(o).filter(function(e){return e.name===t.name}).filter(function(e){return e!==t}).filter(function(e){return!!e.messagesCallback}).forEach(function(e){return e.messagesCallback(n)}),e()},5)})}function u(e,t){e.messagesCallback=t}function c(){return!0}function l(){return 5}r={create:i,close:s,onMessage:u,postMessage:a,canBeUsed:c,type:e,averageResponseTime:l,microSeconds:r};n.default=r},{"../util":13}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;function s(){return(new Date).getTime()}function r(r){var o=new Set,i=new Map;this.has=o.has.bind(o),this.add=function(e){i.set(e,s()),o.add(e),function(){var e=s()-r,t=o[Symbol.iterator]();for(;;){var n=t.next().value;if(!n)return;if(!(i.get(n)<e))return;i.delete(n),o.delete(n)}}()},this.clear=function(){o.clear(),i.clear()}}n.default=r},{}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.fillOptionsWithDefaults=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=JSON.parse(JSON.stringify(e));void 0===t.webWorkerSupport&&(t.webWorkerSupport=!0);t.idb||(t.idb={});t.idb.ttl||(t.idb.ttl=45e3);t.idb.fallbackInterval||(t.idb.fallbackInterval=150);e.idb&&"function"==typeof e.idb.onclose&&(t.idb.onclose=e.idb.onclose);t.localstorage||(t.localstorage={});t.localstorage.removeTimeout||(t.localstorage.removeTimeout=6e4);e.methods&&(t.methods=e.methods);t.node||(t.node={});t.node.ttl||(t.node.ttl=12e4);void 0===t.node.useFastPath&&(t.node.useFastPath=!0);return t}},{}],13:[function(e,t,o){(function(r){(function(){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.isPromise=function(e){return!(!e||"function"!=typeof e.then)},o.sleep=function(t){t=t||0;return new Promise(function(e){return setTimeout(e,t)})},o.randomInt=function(e,t){return Math.floor(Math.random()*(t-e+1)+e)},o.randomToken=function(){return Math.random().toString(36).substring(2)},o.microSeconds=function(){var e=(new Date).getTime();return e===t?1e3*e+ ++n:(n=0,1e3*(t=e))},o.isNode=void 0;var t=0,n=0;var e="[object process]"===Object.prototype.toString.call(void 0!==r?r:0);o.isNode=e}).call(this)}).call(this,e("_process"))},{_process:17}],14:[function(e,t,n){t.exports=function(e){return e&&e.__esModule?e:{default:e}}},{}],15:[function(e,t,n){},{}],16:[function(e,t,n){t.exports=!1},{}],17:[function(e,t,n){var r,o,t=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(t){if(r===setTimeout)return setTimeout(t,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{o="function"==typeof clearTimeout?clearTimeout:s}catch(e){o=s}}();var u,c=[],l=!1,d=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):d=-1,c.length&&h())}function h(){if(!l){var e=a(f);l=!0;for(var t=c.length;t;){for(u=c,c=[];++d<t;)u&&u[d].run();d=-1,t=c.length}u=null,l=!1,function(t){if(o===clearTimeout)return clearTimeout(t);if((o===s||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(t);try{o(t)}catch(e){try{return o.call(null,t)}catch(e){return o.call(this,t)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}t.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new p(e,t)),1!==c.length||l||a(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},t.title="browser",t.browser=!0,t.env={},t.argv=[],t.version="",t.versions={},t.on=m,t.addListener=m,t.once=m,t.off=m,t.removeListener=m,t.removeAllListeners=m,t.emit=m,t.prependListener=m,t.prependOnceListener=m,t.listeners=function(e){return[]},t.binding=function(e){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(e){throw new Error("process.chdir is not supported")},t.umask=function(){return 0}},{}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r={add:function(e){"function"==typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope||"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0))}};n.default=r},{}],19:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.add=c,n.runAll=l,n.removeAll=d,n.getSize=f,n.default=void 0;var o=r(e("detect-node")),i=r(e("./browser.js")),e=r(e("./node.js")),s=(o.default?e:i).default,a=new Set,u=!1;function c(e){if(u||(u=!0,s.add(l)),"function"!=typeof e)throw new Error("Listener is no function");return a.add(e),{remove:function(){return a.delete(e)},run:function(){return a.delete(e),e()}}}function l(){var t=[];return a.forEach(function(e){t.push(e()),a.delete(e)}),Promise.all(t)}function d(){a.clear()}function f(){return a.size}i={add:c,runAll:l,removeAll:d,getSize:f};n.default=i},{"./browser.js":18,"./node.js":15,"@babel/runtime/helpers/interopRequireDefault":14,"detect-node":16}]},{},[2]);
!function r(o,i,s){function a(t,e){if(!i[t]){if(!o[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(u)return u(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},o[t][0].call(n.exports,function(e){return a(o[t][1][e]||e)},n,n.exports,r,o,i,s)}return i[t].exports}for(var u="function"==typeof require&&require,e=0;e<s.length;e++)a(s[e]);return a}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.clearNodeFolder=function(e){e=(0,s.fillOptionsWithDefaults)(e);e=(0,i.chooseMethod)(e);return"node"===e.type?e.clearNodeFolder().then(function(){return!0}):Promise.resolve(!1)},n.enforceOptions=function(e){r=e},n.BroadcastChannel=void 0;var r,o=e("./util.js"),i=e("./method-chooser.js"),s=e("./options.js"),e=function(e,t){var n;this.name=e,r&&(t=r),this.options=(0,s.fillOptionsWithDefaults)(t),this.method=(0,i.chooseMethod)(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._befC=[],this._prepP=null,t=(n=this).method.create(n.name,n.options),(0,o.isPromise)(t)?(n._prepP=t).then(function(e){n._state=e}):n._state=t};function a(e,t,n){var r={time:e.method.microSeconds(),type:t,data:n};return(e._prepP||Promise.resolve()).then(function(){return e.method.postMessage(e._state,r)})}function u(e){return 0<e._addEL.message.length||0<e._addEL.internal.length}function c(e,t,n){var r,o,i;e._addEL[t].push(n),!(r=e)._iL&&u(r)&&(o=function(t){r._addEL[t.type].forEach(function(e){t.time>=e.time&&e.fn(t.data)})},i=r.method.microSeconds(),r._prepP?r._prepP.then(function(){r._iL=!0,r.method.onMessage(r._state,o,i)}):(r._iL=!0,r.method.onMessage(r._state,o,i)))}function l(e,t,n){e._addEL[t]=e._addEL[t].filter(function(e){return e!==n}),(t=e)._iL&&!u(t)&&(t._iL=!1,e=t.method.microSeconds(),t.method.onMessage(t._state,null,e))}(n.BroadcastChannel=e)._pubkey=!0,e.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed");return a(this,"message",e)},postInternal:function(e){return a(this,"internal",e)},set onmessage(e){var t={time:this.method.microSeconds(),fn:e};l(this,"message",this._onML),e&&"function"==typeof e?(this._onML=t,c(this,"message",t)):this._onML=null},addEventListener:function(e,t){var n=this.method.microSeconds();c(this,e,{time:n,fn:t})},removeEventListener:function(e,t){var n=this._addEL[e].find(function(e){return e.fn===t});l(this,e,n)},close:function(){var e=this;if(!this.closed){this.closed=!0;var t=this._prepP||Promise.resolve();return this._onML=null,this._addEL.message=[],t.then(function(){return Promise.all(e._befC.map(function(e){return e()}))}).then(function(){return e.method.close(e._state)})}},get type(){return this.method.type}}},{"./method-chooser.js":6,"./options.js":12,"./util.js":13}],2:[function(e,t,n){"use strict";var r=e("./index.es5.js"),e=r.BroadcastChannel,r=r.createLeaderElection;window.BroadcastChannel2=e,window.createLeaderElection=r},{"./index.es5.js":3}],3:[function(e,t,n){"use strict";e=e("./index.js");t.exports={BroadcastChannel:e.BroadcastChannel,createLeaderElection:e.createLeaderElection,clearNodeFolder:e.clearNodeFolder,enforceOptions:e.enforceOptions}},{"./index.js":4}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"BroadcastChannel",{enumerable:!0,get:function(){return r.BroadcastChannel}}),Object.defineProperty(n,"clearNodeFolder",{enumerable:!0,get:function(){return r.clearNodeFolder}}),Object.defineProperty(n,"enforceOptions",{enumerable:!0,get:function(){return r.enforceOptions}}),Object.defineProperty(n,"createLeaderElection",{enumerable:!0,get:function(){return o.createLeaderElection}});var r=e("./broadcast-channel"),o=e("./leader-election")},{"./broadcast-channel":1,"./leader-election":5}],5:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.createLeaderElection=function(e,t){if(e._leaderElector)throw new Error("BroadcastChannel already has a leader-elector");t=function(e,t){e=e||{};(e=JSON.parse(JSON.stringify(e))).fallbackInterval||(e.fallbackInterval=3e3);e.responseTime||(e.responseTime=t.method.averageResponseTime(t.options));return e}(t,e);var n=new o(e,t);return e._befC.push(function(){return n.die()}),e._leaderElector=n};var i=e("./util.js"),s=r(e("unload")),o=function(e,t){this._channel=e,this._options=t,this.isLeader=!1,this.isDead=!1,this.token=(0,i.randomToken)(),this._isApl=!1,this._reApply=!1,this._unl=[],this._lstns=[],this._invs=[]};function a(e,t){t={context:"leader",action:t,token:e.token};return e._channel.postInternal(t)}o.prototype={applyOnce:function(){var t=this;if(this.isLeader)return Promise.resolve(!1);if(this.isDead)return Promise.resolve(!1);if(this._isApl)return this._reApply=!0,Promise.resolve(!1);function n(e){"leader"===e.context&&e.token!=t.token&&(o.push(e),"apply"===e.action&&e.token>t.token&&(r=!0),"tell"===e.action&&(r=!0))}var r=!(this._isApl=!0),o=[];return this._channel.addEventListener("internal",n),a(this,"apply").then(function(){return(0,i.sleep)(t._options.responseTime)}).then(function(){return r?Promise.reject(new Error):a(t,"apply")}).then(function(){return(0,i.sleep)(t._options.responseTime)}).then(function(){return r?Promise.reject(new Error):a(t)}).then(function(){return function(t){t.isLeader=!0;var e=s.default.add(function(){return t.die()});t._unl.push(e);e=function(e){"leader"===e.context&&"apply"===e.action&&a(t,"tell")};return t._channel.addEventListener("internal",e),t._lstns.push(e),a(t,"tell")}(t)}).then(function(){return!0}).catch(function(){return!1}).then(function(e){return t._channel.removeEventListener("internal",n),t._isApl=!1,!e&&t._reApply?(t._reApply=!1,t.applyOnce()):e})},awaitLeadership:function(){var i;return this._aLP||(this._aLP=(i=this).isLeader?Promise.resolve():new Promise(function(e){function t(){n||(n=!0,clearInterval(r),i._channel.removeEventListener("internal",o),e(!0))}var n=!1;i.applyOnce().then(function(){i.isLeader&&t()});var r=setInterval(function(){i.applyOnce().then(function(){i.isLeader&&t()})},i._options.fallbackInterval);i._invs.push(r);var o=function(e){"leader"===e.context&&"death"===e.action&&i.applyOnce().then(function(){i.isLeader&&t()})};i._channel.addEventListener("internal",o),i._lstns.push(o)})),this._aLP},die:function(){var t=this;if(!this.isDead)return this.isDead=!0,this._lstns.forEach(function(e){return t._channel.removeEventListener("internal",e)}),this._invs.forEach(function(e){return clearInterval(e)}),this._unl.forEach(function(e){e.remove()}),a(this,"death")}}},{"./util.js":13,"@babel/runtime/helpers/interopRequireDefault":14,unload:19}],6:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.chooseMethod=function(t){var e=[].concat(t.methods,u).filter(Boolean);if(t.type){if("simulate"===t.type)return s.default;var n=e.find(function(e){return e.type===t.type});if(n)return n;throw new Error("method-type "+t.type+" not found")}t.webWorkerSupport||a.isNode||(e=e.filter(function(e){return"idb"!==e.type}));e=e.find(function(e){return e.canBeUsed()});{if(e)return e;throw new Error("No useable methode found:"+JSON.stringify(u.map(function(e){return e.type})))}};var o=r(e("./methods/native.js")),i=r(e("./methods/indexed-db.js")),n=r(e("./methods/localstorage.js")),s=r(e("./methods/simulate.js")),a=e("./util"),u=[o.default,i.default,n.default];!a.isNode||"function"==typeof(e=e("../../src/methods/node.js")).canBeUsed&&u.push(e)},{"./methods/indexed-db.js":7,"./methods/localstorage.js":8,"./methods/native.js":9,"./methods/simulate.js":10,"./util":13,"@babel/runtime/helpers/interopRequireDefault":14}],7:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.getIdb=c,n.createDatabase=l,n.writeMessage=d,n.getAllMessages=function(e){var n=e.transaction(u).objectStore(u),r=[];return new Promise(function(t){n.openCursor().onsuccess=function(e){e=e.target.result;e?(r.push(e.value),e.continue()):t(r)}})},n.getMessagesHigherThan=f,n.removeMessageById=h,n.getOldMessages=p,n.cleanOldMessages=m,n.create=v,n.close=g,n.postMessage=w,n.onMessage=_,n.canBeUsed=y,n.averageResponseTime=k,n.default=n.type=n.microSeconds=void 0;var o=e("../util.js"),i=r(e("../oblivious-set")),s=e("../options"),e=o.microSeconds;n.microSeconds=e;var a="pubkey.broadcast-channel-0-",u="messages";function c(){if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof window){if(void 0!==window.mozIndexedDB)return window.mozIndexedDB;if(void 0!==window.webkitIndexedDB)return window.webkitIndexedDB;if(void 0!==window.msIndexedDB)return window.msIndexedDB}return!1}function l(e){var t=c(),e=a+e,n=t.open(e,1);return n.onupgradeneeded=function(e){e.target.result.createObjectStore(u,{keyPath:"id",autoIncrement:!0})},new Promise(function(e,t){n.onerror=function(e){return t(e)},n.onsuccess=function(){e(n.result)}})}function d(e,t,n){var r={uuid:t,time:(new Date).getTime(),data:n},o=e.transaction([u],"readwrite");return new Promise(function(e,t){o.oncomplete=function(){return e()},o.onerror=function(e){return t(e)},o.objectStore(u).add(r)})}function f(e,n){var r=e.transaction(u).objectStore(u),o=[];return new Promise(function(t){(function(){try{var e=IDBKeyRange.bound(n+1,1/0);return r.openCursor(e)}catch(e){return r.openCursor()}})().onsuccess=function(e){e=e.target.result;e?e.value.id<n+1?e.continue(n+1):(o.push(e.value),e.continue()):t(o)}})}function h(e,t){var n=e.transaction([u],"readwrite").objectStore(u).delete(t);return new Promise(function(e){n.onsuccess=function(){return e()}})}function p(e,t){var r=(new Date).getTime()-t,o=e.transaction(u).objectStore(u),i=[];return new Promise(function(n){o.openCursor().onsuccess=function(e){var t,e=e.target.result;e&&(t=e.value).time<r?(i.push(t),e.continue()):n(i)}})}function m(t,e){return p(t,e).then(function(e){return Promise.all(e.map(function(e){return h(t,e.id)}))})}function v(n,r){return r=(0,s.fillOptionsWithDefaults)(r),l(n).then(function(e){var t={closed:!1,lastCursorId:0,channelName:n,options:r,uuid:(0,o.randomToken)(),eMIs:new i.default(2*r.idb.ttl),writeBlockPromise:Promise.resolve(),messagesCallback:null,readQueuePromises:[],db:e};return e.onclose=function(){t.closed=!0,r.idb.onclose&&r.idb.onclose()},function e(t){if(t.closed)return;b(t).then(function(){return(0,o.sleep)(t.options.idb.fallbackInterval)}).then(function(){return e(t)})}(t),t})}function b(n){return!n.closed&&n.messagesCallback?f(n.db,n.lastCursorId).then(function(e){return e.filter(function(e){return!!e}).map(function(e){return e.id>n.lastCursorId&&(n.lastCursorId=e.id),e}).filter(function(e){return t=n,(e=e).uuid!==t.uuid&&(!t.eMIs.has(e.id)&&!(e.data.time<t.messagesCallbackTime));var t}).sort(function(e,t){return e.time-t.time}).forEach(function(e){n.messagesCallback&&(n.eMIs.add(e.id),n.messagesCallback(e.data))}),Promise.resolve()}):Promise.resolve()}function g(e){e.closed=!0,e.db.close()}function w(e,t){return e.writeBlockPromise=e.writeBlockPromise.then(function(){return d(e.db,e.uuid,t)}).then(function(){0===(0,o.randomInt)(0,10)&&m(e.db,e.options.idb.ttl)}),e.writeBlockPromise}function _(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t,b(e)}function y(){return!o.isNode&&!!c()}function k(e){return 2*e.idb.fallbackInterval}e={create:v,close:g,onMessage:_,postMessage:w,canBeUsed:y,type:n.type="idb",averageResponseTime:k,microSeconds:e};n.default=e},{"../oblivious-set":11,"../options":12,"../util.js":13,"@babel/runtime/helpers/interopRequireDefault":14}],8:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.getLocalStorage=u,n.storageKey=c,n.postMessage=l,n.addStorageEventListener=d,n.removeStorageEventListener=f,n.create=h,n.close=p,n.onMessage=m,n.canBeUsed=v,n.averageResponseTime=b,n.default=n.type=n.microSeconds=void 0;var i=r(e("../oblivious-set")),s=e("../options"),a=e("../util"),r=a.microSeconds;n.microSeconds=r;var o="pubkey.broadcastChannel-",e="localstorage";function u(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function c(e){return o+e}function l(o,i){return new Promise(function(r){(0,a.sleep)().then(function(){var e=c(o.channelName),t={token:(0,a.randomToken)(),time:(new Date).getTime(),data:i,uuid:o.uuid},n=JSON.stringify(t);u().setItem(e,n);t=document.createEvent("Event");t.initEvent("storage",!0,!0),t.key=e,t.newValue=n,window.dispatchEvent(t),r()})})}function d(e,t){var n=o+e,e=function(e){e.key===n&&t(JSON.parse(e.newValue))};return window.addEventListener("storage",e),e}function f(e){window.removeEventListener("storage",e)}function h(e,t){if(t=(0,s.fillOptionsWithDefaults)(t),!v())throw new Error("BroadcastChannel: localstorage cannot be used");var n=(0,a.randomToken)(),r=new i.default(t.localstorage.removeTimeout),o={channelName:e,uuid:n,eMIs:r};return o.listener=d(e,function(e){o.messagesCallback&&e.uuid!==n&&e.token&&!r.has(e.token)&&(e.data.time&&e.data.time<o.messagesCallbackTime||(r.add(e.token),o.messagesCallback(e.data)))}),o}function p(e){f(e.listener)}function m(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t}function v(){if(a.isNode)return!1;var e=u();if(!e)return!1;try{var t="__broadcastchannel_check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}function b(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}r={create:h,close:p,onMessage:m,postMessage:l,canBeUsed:v,type:n.type=e,averageResponseTime:b,microSeconds:r};n.default=r},{"../oblivious-set":11,"../options":12,"../util":13,"@babel/runtime/helpers/interopRequireDefault":14}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.create=o,n.close=i,n.postMessage=s,n.onMessage=a,n.canBeUsed=u,n.averageResponseTime=c,n.default=n.type=n.microSeconds=void 0;var r=e("../util"),e=r.microSeconds;n.microSeconds=e;function o(e){var t={messagesCallback:null,bc:new BroadcastChannel(e),subFns:[]};return t.bc.onmessage=function(e){t.messagesCallback&&t.messagesCallback(e.data)},t}function i(e){e.bc.close(),e.subFns=[]}function s(e,t){e.bc.postMessage(t,!1)}function a(e,t){e.messagesCallback=t}function u(){if(r.isNode&&"undefined"==typeof window)return!1;if("function"!=typeof BroadcastChannel)return!1;if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}function c(){return 150}e={create:o,close:i,onMessage:a,postMessage:s,canBeUsed:u,type:n.type="native",averageResponseTime:c,microSeconds:e};n.default=e},{"../util":13}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.create=i,n.close=s,n.postMessage=a,n.onMessage=u,n.canBeUsed=c,n.averageResponseTime=l,n.default=n.type=n.microSeconds=void 0;var r=e("../util").microSeconds;n.microSeconds=r;e="simulate";n.type=e;var o=new Set;function i(e){e={name:e,messagesCallback:null};return o.add(e),e}function s(e){o.delete(e)}function a(t,n){return new Promise(function(e){return setTimeout(function(){Array.from(o).filter(function(e){return e.name===t.name}).filter(function(e){return e!==t}).filter(function(e){return!!e.messagesCallback}).forEach(function(e){return e.messagesCallback(n)}),e()},5)})}function u(e,t){e.messagesCallback=t}function c(){return!0}function l(){return 5}r={create:i,close:s,onMessage:u,postMessage:a,canBeUsed:c,type:e,averageResponseTime:l,microSeconds:r};n.default=r},{"../util":13}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;function s(){return(new Date).getTime()}function r(r){var o=new Set,i=new Map;this.has=o.has.bind(o),this.add=function(e){i.set(e,s()),o.add(e),function(){for(var e=s()-r,t=o[Symbol.iterator]();;){var n=t.next().value;if(!n)return;if(!(i.get(n)<e))return;i.delete(n),o.delete(n)}}()},this.clear=function(){o.clear(),i.clear()}}n.default=r},{}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.fillOptionsWithDefaults=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=JSON.parse(JSON.stringify(e));void 0===t.webWorkerSupport&&(t.webWorkerSupport=!0);t.idb||(t.idb={});t.idb.ttl||(t.idb.ttl=45e3);t.idb.fallbackInterval||(t.idb.fallbackInterval=150);e.idb&&"function"==typeof e.idb.onclose&&(t.idb.onclose=e.idb.onclose);t.localstorage||(t.localstorage={});t.localstorage.removeTimeout||(t.localstorage.removeTimeout=6e4);e.methods&&(t.methods=e.methods);t.node||(t.node={});t.node.ttl||(t.node.ttl=12e4);void 0===t.node.useFastPath&&(t.node.useFastPath=!0);return t}},{}],13:[function(e,t,o){(function(r){(function(){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.isPromise=function(e){return!(!e||"function"!=typeof e.then)},o.sleep=function(t){t=t||0;return new Promise(function(e){return setTimeout(e,t)})},o.randomInt=function(e,t){return Math.floor(Math.random()*(t-e+1)+e)},o.randomToken=function(){return Math.random().toString(36).substring(2)},o.microSeconds=function(){var e=(new Date).getTime();return e===t?1e3*e+ ++n:(n=0,1e3*(t=e))},o.isNode=void 0;var t=0,n=0;var e="[object process]"===Object.prototype.toString.call(void 0!==r?r:0);o.isNode=e}).call(this)}).call(this,e("_process"))},{_process:17}],14:[function(e,t,n){t.exports=function(e){return e&&e.__esModule?e:{default:e}}},{}],15:[function(e,t,n){},{}],16:[function(e,t,n){t.exports=!1},{}],17:[function(e,t,n){var r,o,t=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(t){if(r===setTimeout)return setTimeout(t,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{o="function"==typeof clearTimeout?clearTimeout:s}catch(e){o=s}}();var u,c=[],l=!1,d=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):d=-1,c.length&&h())}function h(){if(!l){var e=a(f);l=!0;for(var t=c.length;t;){for(u=c,c=[];++d<t;)u&&u[d].run();d=-1,t=c.length}u=null,l=!1,function(t){if(o===clearTimeout)return clearTimeout(t);if((o===s||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(t);try{o(t)}catch(e){try{return o.call(null,t)}catch(e){return o.call(this,t)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}t.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new p(e,t)),1!==c.length||l||a(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},t.title="browser",t.browser=!0,t.env={},t.argv=[],t.version="",t.versions={},t.on=m,t.addListener=m,t.once=m,t.off=m,t.removeListener=m,t.removeAllListeners=m,t.emit=m,t.prependListener=m,t.prependOnceListener=m,t.listeners=function(e){return[]},t.binding=function(e){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(e){throw new Error("process.chdir is not supported")},t.umask=function(){return 0}},{}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r={add:function(e){"function"==typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope||"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0))}};n.default=r},{}],19:[function(e,t,n){"use strict";var r=e("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(n,"__esModule",{value:!0}),n.add=c,n.runAll=l,n.removeAll=d,n.getSize=f,n.default=void 0;var o=r(e("detect-node")),i=r(e("./browser.js")),e=r(e("./node.js")),s=(o.default?e:i).default,a=new Set,u=!1;function c(e){if(u||(u=!0,s.add(l)),"function"!=typeof e)throw new Error("Listener is no function");return a.add(e),{remove:function(){return a.delete(e)},run:function(){return a.delete(e),e()}}}function l(){var t=[];return a.forEach(function(e){t.push(e()),a.delete(e)}),Promise.all(t)}function d(){a.clear()}function f(){return a.size}i={add:c,runAll:l,removeAll:d,getSize:f};n.default=i},{"./browser.js":18,"./node.js":15,"@babel/runtime/helpers/interopRequireDefault":14,"detect-node":16}]},{},[2]);

@@ -12,3 +12,3 @@ "use strict";

exports.getAllMessages = getAllMessages;
exports.getMessagesHigherThen = getMessagesHigherThen;
exports.getMessagesHigherThan = getMessagesHigherThan;
exports.removeMessageById = removeMessageById;

@@ -126,13 +126,29 @@ exports.getOldMessages = getOldMessages;

function getMessagesHigherThen(db, lastCursorId) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}
return new Promise(function (res) {
objectStore.openCursor(keyRangeValue).onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;
if (cursor) {
ret.push(cursor.value);
cursor["continue"]();
if (cursor.value.id < lastCursorId + 1) {
cursor["continue"](lastCursorId + 1);
} else {
ret.push(cursor.value);
cursor["continue"]();
}
} else {

@@ -263,3 +279,3 @@ res(ret);

if (!state.messagesCallback) return Promise.resolve();
return getMessagesHigherThen(state.db, state.lastCursorId).then(function (newerMessages) {
return getMessagesHigherThan(state.db, state.lastCursorId).then(function (newerMessages) {
var useMessages = newerMessages

@@ -266,0 +282,0 @@ /**

{
"name": "broadcast-channel",
"version": "3.3.0",
"version": "3.4.0",
"description": "A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers and NodeJs",

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

"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/cli": "7.12.10",
"@babel/core": "7.12.10",
"@babel/plugin-check-constants": "7.0.0-beta.38",

@@ -83,6 +83,6 @@ "@babel/plugin-proposal-object-rest-spread": "7.12.1",

"@babel/plugin-transform-property-literals": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.10",
"@babel/polyfill": "7.12.1",
"@babel/preset-env": "7.12.1",
"@babel/types": "7.12.1",
"@babel/preset-env": "7.12.11",
"@babel/types": "7.12.12",
"@types/core-js": "2.5.4",

@@ -96,10 +96,11 @@ "assert": "2.0.0",

"convert-hrtime": "3.0.0",
"copyfiles": "2.4.0",
"cross-env": "7.0.2",
"eslint": "7.11.0",
"gzip-size-cli": "3.0.0",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
"eslint": "7.18.0",
"gzip-size-cli": "4.0.0",
"http-server": "0.12.3",
"karma": "5.2.3",
"jest": "26.6.3",
"karma": "6.0.1",
"karma-babel-preprocessor": "8.0.1",
"karma-browserify": "7.0.0",
"karma-browserify": "8.0.0",
"karma-chrome-launcher": "3.1.0",

@@ -109,3 +110,3 @@ "karma-coverage": "2.0.3",

"karma-edge-launcher": "0.4.2",
"karma-firefox-launcher": "1.3.0",
"karma-firefox-launcher": "2.1.0",
"karma-ie-launcher": "1.0.0",

@@ -115,16 +116,16 @@ "karma-mocha": "2.0.1",

"karma-safari-launcher": "1.0.0",
"mocha": "8.2.0",
"mocha": "8.2.1",
"pre-commit": "1.2.2",
"random-int": "2.0.1",
"random-token": "0.0.8",
"rollup": "2.32.0",
"rollup": "2.38.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-uglify": "6.0.4",
"testcafe": "1.9.4",
"testcafe-hammerhead": "17.1.21",
"ts-node": "9.0.0",
"typescript": "4.0.3",
"testcafe": "1.10.1",
"testcafe-hammerhead": "19.1.1",
"ts-node": "9.1.1",
"typescript": "4.1.3",
"watchify": "3.11.1",
"webpack": "5.1.3",
"webpack-cli": "4.1.0"
"webpack": "5.17.0",
"webpack-cli": "4.4.0"
},

@@ -131,0 +132,0 @@ "browser": {

@@ -102,12 +102,28 @@ /**

export function getMessagesHigherThen(db, lastCursorId) {
export function getMessagesHigherThan(db, lastCursorId) {
const objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
const ret = [];
const keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
const keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}
return new Promise(res => {
objectStore.openCursor(keyRangeValue).onsuccess = ev => {
openCursor().onsuccess = ev => {
const cursor = ev.target.result;
if (cursor) {
ret.push(cursor.value);
cursor.continue();
if (cursor.value.id < lastCursorId + 1) {
cursor.continue(lastCursorId + 1);
} else {
ret.push(cursor.value);
cursor.continue();
}
} else {

@@ -236,3 +252,3 @@ res(ret);

return getMessagesHigherThen(state.db, state.lastCursorId)
return getMessagesHigherThan(state.db, state.lastCursorId)
.then(newerMessages => {

@@ -239,0 +255,0 @@ const useMessages = newerMessages

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc