broadcast-channel
Advanced tools
Comparing version 6.0.0 to 7.0.0
@@ -6,2 +6,6 @@ # CHANGELOG | ||
## 7.0.0 (27 November 2023) | ||
- CHANGE do not emit messages that have been existed before the channel was created. | ||
## 6.0.0 (30 October 2023) | ||
@@ -8,0 +12,0 @@ |
@@ -240,14 +240,3 @@ "use strict"; | ||
channel._addEL[msgObj.type].forEach(function (listenerObject) { | ||
/** | ||
* Getting the current time in JavaScript has no good precision. | ||
* So instead of only listening to events that happened 'after' the listener | ||
* was added, we also listen to events that happened 100ms before it. | ||
* This ensures that when another process, like a WebWorker, sends events | ||
* we do not miss them out because their timestamp is a bit off compared to the main process. | ||
* Not doing this would make messages missing when we send data directly after subscribing and awaiting a response. | ||
* @link https://johnresig.com/blog/accuracy-of-javascript-time/ | ||
*/ | ||
var hundredMsInMicro = 100 * 1000; | ||
var minMessageTime = listenerObject.time - hundredMsInMicro; | ||
if (msgObj.time >= minMessageTime) { | ||
if (msgObj.time >= listenerObject.time) { | ||
listenerObject.fn(msgObj.data); | ||
@@ -254,0 +243,0 @@ } |
@@ -20,2 +20,3 @@ "use strict"; | ||
var state = { | ||
time: (0, _util.microSeconds)(), | ||
messagesCallback: null, | ||
@@ -26,5 +27,5 @@ bc: new BroadcastChannel(channelName), | ||
state.bc.onmessage = function (msg) { | ||
state.bc.onmessage = function (msgEvent) { | ||
if (state.messagesCallback) { | ||
state.messagesCallback(msg.data); | ||
state.messagesCallback(msgEvent.data); | ||
} | ||
@@ -31,0 +32,0 @@ }; |
@@ -443,7 +443,9 @@ "use strict"; | ||
function writeMessage(channelName, readerUuid, messageJson, paths) { | ||
var time = messageJson.time; | ||
if (!time) { | ||
time = microSeconds(); | ||
} | ||
paths = paths || getPaths(channelName); | ||
var time = microSeconds(); | ||
var writeObject = { | ||
uuid: readerUuid, | ||
time: time, | ||
data: messageJson | ||
@@ -691,4 +693,4 @@ }; | ||
if (!state.messagesCallback) return false; // no listener | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older then onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older then channel | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older than onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older than channel | ||
@@ -695,0 +697,0 @@ state.emittedMessagesIds.add(msgObj.token); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.SimulateMethod = void 0; | ||
exports.SimulateMethod = exports.SIMULATE_DELAY_TIME = void 0; | ||
exports.averageResponseTime = averageResponseTime; | ||
@@ -22,2 +22,3 @@ exports.canBeUsed = canBeUsed; | ||
var state = { | ||
time: microSeconds(), | ||
name: channelName, | ||
@@ -32,2 +33,3 @@ messagesCallback: null | ||
} | ||
var SIMULATE_DELAY_TIME = exports.SIMULATE_DELAY_TIME = 5; | ||
function postMessage(channelState, messageJson) { | ||
@@ -37,13 +39,16 @@ return new Promise(function (res) { | ||
var channelArray = Array.from(SIMULATE_CHANNELS); | ||
channelArray.filter(function (channel) { | ||
return channel.name === channelState.name; | ||
}).filter(function (channel) { | ||
return channel !== channelState; | ||
}).filter(function (channel) { | ||
return !!channel.messagesCallback; | ||
}).forEach(function (channel) { | ||
return channel.messagesCallback(messageJson); | ||
channelArray.forEach(function (channel) { | ||
if (channel.name === channelState.name && | ||
// has same name | ||
channel !== channelState && | ||
// not own channel | ||
!!channel.messagesCallback && | ||
// has subscribers | ||
channel.time < messageJson.time // channel not created after postMessage() call | ||
) { | ||
channel.messagesCallback(messageJson); | ||
} | ||
}); | ||
res(); | ||
}, 5); | ||
}, SIMULATE_DELAY_TIME); | ||
}); | ||
@@ -58,3 +63,3 @@ } | ||
function averageResponseTime() { | ||
return 5; | ||
return SIMULATE_DELAY_TIME; | ||
} | ||
@@ -61,0 +66,0 @@ var SimulateMethod = exports.SimulateMethod = { |
@@ -41,6 +41,5 @@ "use strict"; | ||
var lastMs = 0; | ||
var additional = 0; | ||
/** | ||
* returns the current time in micro-seconds, | ||
* Returns the current unix time in micro-seconds, | ||
* WARNING: This is a pseudo-function | ||
@@ -52,11 +51,8 @@ * Performance.now is not reliable in webworkers, so we just make sure to never return the same time. | ||
function microSeconds() { | ||
var ms = Date.now(); | ||
if (ms === lastMs) { | ||
additional++; | ||
return ms * 1000 + additional; | ||
} else { | ||
lastMs = ms; | ||
additional = 0; | ||
return ms * 1000; | ||
var ret = Date.now() * 1000; // milliseconds to microseconds | ||
if (ret <= lastMs) { | ||
ret = lastMs + 1; | ||
} | ||
lastMs = ret; | ||
return ret; | ||
} | ||
@@ -63,0 +59,0 @@ |
@@ -233,14 +233,3 @@ import { isPromise, PROMISE_RESOLVED_FALSE, PROMISE_RESOLVED_VOID } from './util.js'; | ||
channel._addEL[msgObj.type].forEach(function (listenerObject) { | ||
/** | ||
* Getting the current time in JavaScript has no good precision. | ||
* So instead of only listening to events that happened 'after' the listener | ||
* was added, we also listen to events that happened 100ms before it. | ||
* This ensures that when another process, like a WebWorker, sends events | ||
* we do not miss them out because their timestamp is a bit off compared to the main process. | ||
* Not doing this would make messages missing when we send data directly after subscribing and awaiting a response. | ||
* @link https://johnresig.com/blog/accuracy-of-javascript-time/ | ||
*/ | ||
var hundredMsInMicro = 100 * 1000; | ||
var minMessageTime = listenerObject.time - hundredMsInMicro; | ||
if (msgObj.time >= minMessageTime) { | ||
if (msgObj.time >= listenerObject.time) { | ||
listenerObject.fn(msgObj.data); | ||
@@ -247,0 +236,0 @@ } |
@@ -6,2 +6,3 @@ import { microSeconds as micro, PROMISE_RESOLVED_VOID } from '../util.js'; | ||
var state = { | ||
time: micro(), | ||
messagesCallback: null, | ||
@@ -12,5 +13,5 @@ bc: new BroadcastChannel(channelName), | ||
state.bc.onmessage = function (msg) { | ||
state.bc.onmessage = function (msgEvent) { | ||
if (state.messagesCallback) { | ||
state.messagesCallback(msg.data); | ||
state.messagesCallback(msgEvent.data); | ||
} | ||
@@ -17,0 +18,0 @@ }; |
@@ -410,7 +410,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
export function writeMessage(channelName, readerUuid, messageJson, paths) { | ||
var time = messageJson.time; | ||
if (!time) { | ||
time = microSeconds(); | ||
} | ||
paths = paths || getPaths(channelName); | ||
var time = microSeconds(); | ||
var writeObject = { | ||
uuid: readerUuid, | ||
time: time, | ||
data: messageJson | ||
@@ -658,4 +660,4 @@ }; | ||
if (!state.messagesCallback) return false; // no listener | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older then onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older then channel | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older than onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older than channel | ||
@@ -662,0 +664,0 @@ state.emittedMessagesIds.add(msgObj.token); |
@@ -7,2 +7,3 @@ import { microSeconds as micro } from '../util.js'; | ||
var state = { | ||
time: microSeconds(), | ||
name: channelName, | ||
@@ -17,2 +18,3 @@ messagesCallback: null | ||
} | ||
export var SIMULATE_DELAY_TIME = 5; | ||
export function postMessage(channelState, messageJson) { | ||
@@ -22,13 +24,16 @@ return new Promise(function (res) { | ||
var channelArray = Array.from(SIMULATE_CHANNELS); | ||
channelArray.filter(function (channel) { | ||
return channel.name === channelState.name; | ||
}).filter(function (channel) { | ||
return channel !== channelState; | ||
}).filter(function (channel) { | ||
return !!channel.messagesCallback; | ||
}).forEach(function (channel) { | ||
return channel.messagesCallback(messageJson); | ||
channelArray.forEach(function (channel) { | ||
if (channel.name === channelState.name && | ||
// has same name | ||
channel !== channelState && | ||
// not own channel | ||
!!channel.messagesCallback && | ||
// has subscribers | ||
channel.time < messageJson.time // channel not created after postMessage() call | ||
) { | ||
channel.messagesCallback(messageJson); | ||
} | ||
}); | ||
res(); | ||
}, 5); | ||
}, SIMULATE_DELAY_TIME); | ||
}); | ||
@@ -43,3 +48,3 @@ } | ||
export function averageResponseTime() { | ||
return 5; | ||
return SIMULATE_DELAY_TIME; | ||
} | ||
@@ -46,0 +51,0 @@ export var SimulateMethod = { |
@@ -29,6 +29,5 @@ /** | ||
var lastMs = 0; | ||
var additional = 0; | ||
/** | ||
* returns the current time in micro-seconds, | ||
* Returns the current unix time in micro-seconds, | ||
* WARNING: This is a pseudo-function | ||
@@ -40,11 +39,8 @@ * Performance.now is not reliable in webworkers, so we just make sure to never return the same time. | ||
export function microSeconds() { | ||
var ms = Date.now(); | ||
if (ms === lastMs) { | ||
additional++; | ||
return ms * 1000 + additional; | ||
} else { | ||
lastMs = ms; | ||
additional = 0; | ||
return ms * 1000; | ||
var ret = Date.now() * 1000; // milliseconds to microseconds | ||
if (ret <= lastMs) { | ||
ret = lastMs + 1; | ||
} | ||
lastMs = ret; | ||
return ret; | ||
} | ||
@@ -51,0 +47,0 @@ |
@@ -233,14 +233,3 @@ import { isPromise, PROMISE_RESOLVED_FALSE, PROMISE_RESOLVED_VOID } from './util.js'; | ||
channel._addEL[msgObj.type].forEach(function (listenerObject) { | ||
/** | ||
* Getting the current time in JavaScript has no good precision. | ||
* So instead of only listening to events that happened 'after' the listener | ||
* was added, we also listen to events that happened 100ms before it. | ||
* This ensures that when another process, like a WebWorker, sends events | ||
* we do not miss them out because their timestamp is a bit off compared to the main process. | ||
* Not doing this would make messages missing when we send data directly after subscribing and awaiting a response. | ||
* @link https://johnresig.com/blog/accuracy-of-javascript-time/ | ||
*/ | ||
var hundredMsInMicro = 100 * 1000; | ||
var minMessageTime = listenerObject.time - hundredMsInMicro; | ||
if (msgObj.time >= minMessageTime) { | ||
if (msgObj.time >= listenerObject.time) { | ||
listenerObject.fn(msgObj.data); | ||
@@ -247,0 +236,0 @@ } |
@@ -6,2 +6,3 @@ import { microSeconds as micro, PROMISE_RESOLVED_VOID } from '../util.js'; | ||
var state = { | ||
time: micro(), | ||
messagesCallback: null, | ||
@@ -12,5 +13,5 @@ bc: new BroadcastChannel(channelName), | ||
state.bc.onmessage = function (msg) { | ||
state.bc.onmessage = function (msgEvent) { | ||
if (state.messagesCallback) { | ||
state.messagesCallback(msg.data); | ||
state.messagesCallback(msgEvent.data); | ||
} | ||
@@ -17,0 +18,0 @@ }; |
@@ -410,7 +410,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
export function writeMessage(channelName, readerUuid, messageJson, paths) { | ||
var time = messageJson.time; | ||
if (!time) { | ||
time = microSeconds(); | ||
} | ||
paths = paths || getPaths(channelName); | ||
var time = microSeconds(); | ||
var writeObject = { | ||
uuid: readerUuid, | ||
time: time, | ||
data: messageJson | ||
@@ -658,4 +660,4 @@ }; | ||
if (!state.messagesCallback) return false; // no listener | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older then onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older then channel | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older than onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older than channel | ||
@@ -662,0 +664,0 @@ state.emittedMessagesIds.add(msgObj.token); |
@@ -7,2 +7,3 @@ import { microSeconds as micro } from '../util.js'; | ||
var state = { | ||
time: microSeconds(), | ||
name: channelName, | ||
@@ -17,2 +18,3 @@ messagesCallback: null | ||
} | ||
export var SIMULATE_DELAY_TIME = 5; | ||
export function postMessage(channelState, messageJson) { | ||
@@ -22,13 +24,16 @@ return new Promise(function (res) { | ||
var channelArray = Array.from(SIMULATE_CHANNELS); | ||
channelArray.filter(function (channel) { | ||
return channel.name === channelState.name; | ||
}).filter(function (channel) { | ||
return channel !== channelState; | ||
}).filter(function (channel) { | ||
return !!channel.messagesCallback; | ||
}).forEach(function (channel) { | ||
return channel.messagesCallback(messageJson); | ||
channelArray.forEach(function (channel) { | ||
if (channel.name === channelState.name && | ||
// has same name | ||
channel !== channelState && | ||
// not own channel | ||
!!channel.messagesCallback && | ||
// has subscribers | ||
channel.time < messageJson.time // channel not created after postMessage() call | ||
) { | ||
channel.messagesCallback(messageJson); | ||
} | ||
}); | ||
res(); | ||
}, 5); | ||
}, SIMULATE_DELAY_TIME); | ||
}); | ||
@@ -43,3 +48,3 @@ } | ||
export function averageResponseTime() { | ||
return 5; | ||
return SIMULATE_DELAY_TIME; | ||
} | ||
@@ -46,0 +51,0 @@ export var SimulateMethod = { |
@@ -29,6 +29,5 @@ /** | ||
var lastMs = 0; | ||
var additional = 0; | ||
/** | ||
* returns the current time in micro-seconds, | ||
* Returns the current unix time in micro-seconds, | ||
* WARNING: This is a pseudo-function | ||
@@ -40,11 +39,8 @@ * Performance.now is not reliable in webworkers, so we just make sure to never return the same time. | ||
export function microSeconds() { | ||
var ms = Date.now(); | ||
if (ms === lastMs) { | ||
additional++; | ||
return ms * 1000 + additional; | ||
} else { | ||
lastMs = ms; | ||
additional = 0; | ||
return ms * 1000; | ||
var ret = Date.now() * 1000; // milliseconds to microseconds | ||
if (ret <= lastMs) { | ||
ret = lastMs + 1; | ||
} | ||
lastMs = ret; | ||
return ret; | ||
} | ||
@@ -51,0 +47,0 @@ |
@@ -240,14 +240,3 @@ "use strict"; | ||
channel._addEL[msgObj.type].forEach(function (listenerObject) { | ||
/** | ||
* Getting the current time in JavaScript has no good precision. | ||
* So instead of only listening to events that happened 'after' the listener | ||
* was added, we also listen to events that happened 100ms before it. | ||
* This ensures that when another process, like a WebWorker, sends events | ||
* we do not miss them out because their timestamp is a bit off compared to the main process. | ||
* Not doing this would make messages missing when we send data directly after subscribing and awaiting a response. | ||
* @link https://johnresig.com/blog/accuracy-of-javascript-time/ | ||
*/ | ||
var hundredMsInMicro = 100 * 1000; | ||
var minMessageTime = listenerObject.time - hundredMsInMicro; | ||
if (msgObj.time >= minMessageTime) { | ||
if (msgObj.time >= listenerObject.time) { | ||
listenerObject.fn(msgObj.data); | ||
@@ -254,0 +243,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function o(r,i,s){function a(t,e){if(!i[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(u)return u(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}n=i[t]={exports:{}},r[t][0].call(n.exports,function(e){return a(r[t][1][e]||e)},n,n.exports,o,r,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.OPEN_BROADCAST_CHANNELS=n.BroadcastChannel=void 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}):r.PROMISE_RESOLVED_FALSE},n.enforceOptions=function(e){o=e};var o,r=e("./util.js"),i=e("./method-chooser.js"),s=e("./options.js"),a=n.OPEN_BROADCAST_CHANNELS=new Set,u=0,e=n.BroadcastChannel=function(e,t){var n;this.id=u++,a.add(this),this.name=e,o&&(t=o),this.options=(0,s.fillOptionsWithDefaults)(t),this.method=(0,i.chooseMethod)(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._uMP=new Set,this._befC=[],this._prepP=null,e=(n=this).method.create(n.name,n.options),(0,r.isPromise)(e)?(n._prepP=e).then(function(e){n._state=e}):n._state=e};function c(t,e,n){var o={time:t.method.microSeconds(),type:e,data:n};return(t._prepP||r.PROMISE_RESOLVED_VOID).then(function(){var e=t.method.postMessage(t._state,o);return t._uMP.add(e),e.catch().then(function(){return t._uMP.delete(e)}),e})}function l(e){return 0<e._addEL.message.length||0<e._addEL.internal.length}function d(e,t,n){e._addEL[t].push(n);var o,r,i=e;!i._iL&&l(i)&&(o=function(n){i._addEL[n.type].forEach(function(e){var t=e.time-1e5;n.time>=t&&e.fn(n.data)})},r=i.method.microSeconds(),i._prepP?i._prepP.then(function(){i._iL=!0,i.method.onMessage(i._state,o,r)}):(i._iL=!0,i.method.onMessage(i._state,o,r)))}function f(e,t,n){e._addEL[t]=e._addEL[t].filter(function(e){return e!==n});t=e;t._iL&&!l(t)&&(t._iL=!1,e=t.method.microSeconds(),t.method.onMessage(t._state,null,e))}e._pubkey=!0,e.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed "+JSON.stringify(e));return c(this,"message",e)},postInternal:function(e){return c(this,"internal",e)},set onmessage(e){var t={time:this.method.microSeconds(),fn:e};f(this,"message",this._onML),e&&"function"==typeof e?(this._onML=t,d(this,"message",t)):this._onML=null},addEventListener:function(e,t){var n=this.method.microSeconds();d(this,e,{time:n,fn:t})},removeEventListener:function(e,t){var n=this._addEL[e].find(function(e){return e.fn===t});f(this,e,n)},close:function(){var e,t=this;if(!this.closed)return a.delete(this),this.closed=!0,e=this._prepP||r.PROMISE_RESOLVED_VOID,this._onML=null,this._addEL.message=[],e.then(function(){return Promise.all(Array.from(t._uMP))}).then(function(){return Promise.all(t._befC.map(function(e){return e()}))}).then(function(){return t.method.close(t._state)})},get type(){return this.method.type},get isClosed(){return this.closed}}},{"./method-chooser.js":8,"./options.js":13,"./util.js":14}],2:[function(e,t,n){"use strict";var e=e("./index.es5.js"),o=e.BroadcastChannel,e=e.createLeaderElection;window.BroadcastChannel2=o,window.createLeaderElection=e},{"./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,beLeader:e.beLeader}},{"./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 o.BroadcastChannel}}),Object.defineProperty(n,"OPEN_BROADCAST_CHANNELS",{enumerable:!0,get:function(){return o.OPEN_BROADCAST_CHANNELS}}),Object.defineProperty(n,"beLeader",{enumerable:!0,get:function(){return i.beLeader}}),Object.defineProperty(n,"clearNodeFolder",{enumerable:!0,get:function(){return o.clearNodeFolder}}),Object.defineProperty(n,"createLeaderElection",{enumerable:!0,get:function(){return r.createLeaderElection}}),Object.defineProperty(n,"enforceOptions",{enumerable:!0,get:function(){return o.enforceOptions}});var o=e("./broadcast-channel.js"),r=e("./leader-election.js"),i=e("./leader-election-util.js")},{"./broadcast-channel.js":1,"./leader-election-util.js":5,"./leader-election.js":7}],5:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.beLeader=function(t){t.isLeader=!0,t._hasLeader=!0;function e(e){"leader"===e.context&&"apply"===e.action&&r(t,"tell"),"leader"!==e.context||"tell"!==e.action||t._dpLC||(t._dpLC=!0,t._dpL(),r(t,"tell"))}var n=(0,o.add)(function(){return t.die()});t._unl.push(n);return t.broadcastChannel.addEventListener("internal",e),t._lstns.push(e),r(t,"tell")},n.sendLeaderMessage=r;var o=e("unload");function r(e,t){t={context:"leader",action:t,token:e.token};return e.broadcastChannel.postInternal(t)}},{unload:20}],6:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LeaderElectionWebLock=void 0;var o=e("./util.js"),r=e("./leader-election-util.js");(n.LeaderElectionWebLock=function(e,t){var n=this;(this.broadcastChannel=e)._befC.push(function(){return n.die()}),this._options=t,this.isLeader=!1,this.isDead=!1,this.token=(0,o.randomToken)(),this._lstns=[],this._unl=[],this._dpL=function(){},this._dpLC=!1,this._wKMC={},this.lN="pubkey-bc||"+e.method.type+"||"+e.name}).prototype={hasLeader:function(){var t=this;return navigator.locks.query().then(function(e){e=e.held?e.held.filter(function(e){return e.name===t.lN}):[];return!!(e&&0<e.length)})},awaitLeadership:function(){var t,n=this;return this._wLMP||(this._wKMC.c=new AbortController,t=new Promise(function(e,t){n._wKMC.res=e,n._wKMC.rej=t}),this._wLMP=new Promise(function(e){navigator.locks.request(n.lN,{signal:n._wKMC.c.signal},function(){return(n._wKMC.c=void 0,r.beLeader)(n),e(),t}).catch(function(){})})),this._wLMP},set onduplicate(e){},die:function(){var t=this;return this._lstns.forEach(function(e){return t.broadcastChannel.removeEventListener("internal",e)}),this._lstns=[],this._unl.forEach(function(e){return e.remove()}),this._unl=[],this.isLeader&&(this.isLeader=!1),this.isDead=!0,this._wKMC.res&&this._wKMC.res(),this._wKMC.c&&this._wKMC.c.abort("LeaderElectionWebLock.die() called"),(0,r.sendLeaderMessage)(this,"death")}}},{"./leader-election-util.js":5,"./util.js":14}],7:[function(e,t,n){"use strict";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((0,a.supportsWebLockAPI)()?o.LeaderElectionWebLock:r)(e,t);return e._befC.push(function(){return n.die()}),e._leaderElector=n};var a=e("./util.js"),u=e("./leader-election-util.js"),o=e("./leader-election-web-lock.js"),r=function(e,t){function n(e){"leader"===e.context&&("death"===e.action&&(o._hasLeader=!1),"tell"===e.action)&&(o._hasLeader=!0)}var o=this;this.broadcastChannel=e,this._options=t,this.isLeader=!1,this._hasLeader=!1,this.isDead=!1,this.token=(0,a.randomToken)(),this._aplQ=a.PROMISE_RESOLVED_VOID,this._aplQC=0,this._unl=[],this._lstns=[],this._dpL=function(){},this._dpLC=!1;this.broadcastChannel.addEventListener("internal",n),this._lstns.push(n)};r.prototype={hasLeader:function(){return Promise.resolve(this._hasLeader)},applyOnce:function(i){var s=this;return this.isLeader?(0,a.sleep)(0,!0):this.isDead?(0,a.sleep)(0,!1):1<this._aplQC?this._aplQ:(this._aplQC=this._aplQC+1,this._aplQ=this._aplQ.then(function(){return s.isLeader?a.PROMISE_RESOLVED_TRUE:(t=!1,e=new Promise(function(e){n=function(){t=!0,e()}}),s.broadcastChannel.addEventListener("internal",o=function(e){"leader"===e.context&&e.token!=s.token&&("apply"===e.action&&e.token>s.token&&n(),"tell"===e.action)&&(n(),s._hasLeader=!0)}),r=i?4*s._options.responseTime:s._options.responseTime,(0,u.sendLeaderMessage)(s,"apply").then(function(){return Promise.race([(0,a.sleep)(r),e.then(function(){return Promise.reject(new Error)})])}).then(function(){return(0,u.sendLeaderMessage)(s,"apply")}).then(function(){return Promise.race([(0,a.sleep)(r),e.then(function(){return Promise.reject(new Error)})])}).catch(function(){}).then(function(){return s.broadcastChannel.removeEventListener("internal",o),!t&&(0,u.beLeader)(s).then(function(){return!0})}));var t,n,e,o,r}).then(function(){s._aplQC=s._aplQC-1}),this._aplQ.then(function(){return s.isLeader}))},awaitLeadership:function(){return this._aLP||(this._aLP=function(r){if(r.isLeader)return a.PROMISE_RESOLVED_VOID;return new Promise(function(e){var t=!1;function n(){t||(t=!0,r.broadcastChannel.removeEventListener("internal",o),e(!0))}r.applyOnce().then(function(){r.isLeader&&n()});(function e(){return(0,a.sleep)(r._options.fallbackInterval).then(function(){if(!r.isDead&&!t)return r.isLeader?void n():r.applyOnce(!0).then(function(){(r.isLeader?n:e)()})})})();var o=function(e){"leader"===e.context&&"death"===e.action&&(r._hasLeader=!1,r.applyOnce().then(function(){r.isLeader&&n()}))};r.broadcastChannel.addEventListener("internal",o),r._lstns.push(o)})}(this)),this._aLP},set onduplicate(e){this._dpL=e},die:function(){var t=this;return this._lstns.forEach(function(e){return t.broadcastChannel.removeEventListener("internal",e)}),this._lstns=[],this._unl.forEach(function(e){return e.remove()}),this._unl=[],this.isLeader&&(this._hasLeader=!1,this.isLeader=!1),this.isDead=!0,(0,u.sendLeaderMessage)(this,"death")}}},{"./leader-election-util.js":5,"./leader-election-web-lock.js":6,"./util.js":14}],8:[function(e,t,n){"use strict";e("@babel/runtime/helpers/typeof");Object.defineProperty(n,"__esModule",{value:!0}),n.chooseMethod=function(t){var e=[].concat(t.methods,s).filter(Boolean);if(t.type){if("simulate"===t.type)return i.SimulateMethod;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||(e=e.filter(function(e){return"idb"!==e.type}));n=e.find(function(e){return e.canBeUsed()});{if(n)return n;throw new Error("No usable method found in "+JSON.stringify(s.map(function(e){return e.type})))}};var n=e("./methods/native.js"),o=e("./methods/indexed-db.js"),r=e("./methods/localstorage.js"),i=e("./methods/simulate.js");var s=[n.NativeMethod,o.IndexedDBMethod,r.LocalstorageMethod]},{"./methods/indexed-db.js":9,"./methods/localstorage.js":10,"./methods/native.js":11,"./methods/simulate.js":12,"@babel/runtime/helpers/typeof":15}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.TRANSACTION_SETTINGS=n.IndexedDBMethod=void 0,n.averageResponseTime=E,n.canBeUsed=L,n.cleanOldMessages=v,n.close=g,n.commitIndexedDBTransaction=d,n.create=_,n.createDatabase=u,n.getAllMessages=function(e){var n=e.transaction(c,"readonly",l),o=n.objectStore(c),r=[];return new Promise(function(t){o.openCursor().onsuccess=function(e){e=e.target.result;e?(r.push(e.value),e.continue()):(d(n),t(r))}})},n.getIdb=a,n.getMessagesHigherThan=h,n.getOldMessages=m,n.microSeconds=void 0,n.onMessage=y,n.postMessage=w,n.removeMessagesById=p,n.type=void 0,n.writeMessage=f;var r=e("../util.js"),i=e("oblivious-set"),s=e("../options.js"),e=n.microSeconds=r.microSeconds,o="pubkey.broadcast-channel-0-",c="messages",l=n.TRANSACTION_SETTINGS={durability:"relaxed"};n.type="idb";function a(){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 d(e){e.commit&&e.commit()}function u(e){var n=a().open(o+e);return n.onupgradeneeded=function(e){e.target.result.createObjectStore(c,{keyPath:"id",autoIncrement:!0})},new Promise(function(e,t){n.onerror=function(e){return t(e)},n.onsuccess=function(){e(n.result)}})}function f(e,t,n){var o={uuid:t,time:Date.now(),data:n},r=e.transaction([c],"readwrite",l);return new Promise(function(e,t){r.oncomplete=function(){return e()},r.onerror=function(e){return t(e)},r.objectStore(c).add(o),d(r)})}function h(e,o){var r,i=e.transaction(c,"readonly",l),s=i.objectStore(c),a=[],u=IDBKeyRange.bound(o+1,1/0);return s.getAll?(r=s.getAll(u),new Promise(function(t,n){r.onerror=function(e){return n(e)},r.onsuccess=function(e){t(e.target.result)}})):new Promise(function(t,n){var e=function(){try{return u=IDBKeyRange.bound(o+1,1/0),s.openCursor(u)}catch(e){return s.openCursor()}}();e.onerror=function(e){return n(e)},e.onsuccess=function(e){e=e.target.result;e?e.value.id<o+1?e.continue(o+1):(a.push(e.value),e.continue()):(d(i),t(a))}})}function p(e,t){var n;return e.closed?Promise.resolve([]):(n=e.db.transaction(c,"readwrite",l).objectStore(c),Promise.all(t.map(function(e){var t=n.delete(e);return new Promise(function(e){t.onsuccess=function(){return e()}})})))}function m(e,t){var o=Date.now()-t,r=e.transaction(c,"readonly",l),i=r.objectStore(c),s=[];return new Promise(function(n){i.openCursor().onsuccess=function(e){var t,e=e.target.result;e?(t=e.value).time<o?(s.push(t),e.continue()):(d(r),n(s)):n(s)}})}function v(t){return m(t.db,t.options.idb.ttl).then(function(e){return p(t,e.map(function(e){return e.id}))})}function _(n,o){return o=(0,s.fillOptionsWithDefaults)(o),u(n).then(function(e){var t={closed:!1,lastCursorId:0,channelName:n,options:o,uuid:(0,r.randomToken)(),eMIs:new i.ObliviousSet(2*o.idb.ttl),writeBlockPromise:r.PROMISE_RESOLVED_VOID,messagesCallback:null,readQueuePromises:[],db:e};return e.onclose=function(){t.closed=!0,o.idb.onclose&&o.idb.onclose()},function e(t){if(t.closed)return;b(t).then(function(){return(0,r.sleep)(t.options.idb.fallbackInterval)}).then(function(){return e(t)})}(t),t})}function b(n){return!n.closed&&n.messagesCallback?h(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))}),r.PROMISE_RESOLVED_VOID}):r.PROMISE_RESOLVED_VOID}function g(e){e.closed=!0,e.db.close()}function w(e,t){return e.writeBlockPromise=e.writeBlockPromise.then(function(){return f(e.db,e.uuid,t)}).then(function(){0===(0,r.randomInt)(0,10)&&v(e)}),e.writeBlockPromise}function y(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t,b(e)}function L(){return!!a()}function E(e){return 2*e.idb.fallbackInterval}n.IndexedDBMethod={create:_,close:g,onMessage:y,postMessage:w,canBeUsed:L,type:"idb",averageResponseTime:E,microSeconds:e}},{"../options.js":13,"../util.js":14,"oblivious-set":16}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LocalstorageMethod=void 0,n.addStorageEventListener=l,n.averageResponseTime=v,n.canBeUsed=m,n.close=h,n.create=f,n.getLocalStorage=u,n.microSeconds=void 0,n.onMessage=p,n.postMessage=o,n.removeStorageEventListener=d,n.storageKey=c,n.type=void 0;var i=e("oblivious-set"),s=e("../options.js"),a=e("../util.js"),e=n.microSeconds=a.microSeconds,r="pubkey.broadcastChannel-";n.type="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 r+e}function o(r,i){return new Promise(function(o){(0,a.sleep)().then(function(){var e=c(r.channelName),t={token:(0,a.randomToken)(),time:Date.now(),data:i,uuid:r.uuid},t=JSON.stringify(t),n=(u().setItem(e,t),document.createEvent("Event"));n.initEvent("storage",!0,!0),n.key=e,n.newValue=t,window.dispatchEvent(n),o()})})}function l(e,t){function n(e){e.key===o&&t(JSON.parse(e.newValue))}var o=r+e;return window.addEventListener("storage",n),n}function d(e){window.removeEventListener("storage",e)}function f(e,t){var n,o,r;if(t=(0,s.fillOptionsWithDefaults)(t),m())return n=(0,a.randomToken)(),o=new i.ObliviousSet(t.localstorage.removeTimeout),(r={channelName:e,uuid:n,eMIs:o}).listener=l(e,function(e){!r.messagesCallback||e.uuid===n||!e.token||o.has(e.token)||e.data.time&&e.data.time<r.messagesCallbackTime||(o.add(e.token),r.messagesCallback(e.data))}),r;throw new Error("BroadcastChannel: localstorage cannot be used")}function h(e){d(e.listener)}function p(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t}function m(){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 v(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}n.LocalstorageMethod={create:f,close:h,onMessage:p,postMessage:o,canBeUsed:m,type:"localstorage",averageResponseTime:v,microSeconds:e}},{"../options.js":13,"../util.js":14,"oblivious-set":16}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.NativeMethod=void 0,n.averageResponseTime=c,n.canBeUsed=u,n.close=i,n.create=r,n.microSeconds=void 0,n.onMessage=a,n.postMessage=s,n.type=void 0;var o=e("../util.js"),e=n.microSeconds=o.microSeconds;n.type="native";function r(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){try{return e.bc.postMessage(t,!1),o.PROMISE_RESOLVED_VOID}catch(e){return Promise.reject(e)}}function a(e,t){e.messagesCallback=t}function u(){if("undefined"==typeof globalThis||!globalThis.Deno||!globalThis.Deno.args){if("undefined"==typeof window&&"undefined"==typeof self||"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}n.NativeMethod={create:r,close:i,onMessage:a,postMessage:s,canBeUsed:u,type:"native",averageResponseTime:c,microSeconds:e}},{"../util.js":14}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.SimulateMethod=void 0,n.averageResponseTime=c,n.canBeUsed=u,n.close=i,n.create=r,n.microSeconds=void 0,n.onMessage=a,n.postMessage=s,n.type=void 0;var e=e("../util.js"),e=n.microSeconds=e.microSeconds,o=(n.type="simulate",new Set);function r(e){e={name:e,messagesCallback:null};return o.add(e),e}function i(e){o.delete(e)}function s(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 a(e,t){e.messagesCallback=t}function u(){return!0}function c(){return 5}n.SimulateMethod={create:r,close:i,onMessage:a,postMessage:s,canBeUsed:u,type:"simulate",averageResponseTime:c,microSeconds:e}},{"../util.js":14}],13:[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);t.node.maxParallelWrites||(t.node.maxParallelWrites=2048);void 0===t.node.useFastPath&&(t.node.useFastPath=!0);return t}},{}],14:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.PROMISE_RESOLVED_VOID=n.PROMISE_RESOLVED_TRUE=n.PROMISE_RESOLVED_FALSE=void 0,n.isPromise=function(e){return e&&"function"==typeof e.then},n.microSeconds=function(){var e=Date.now();return e===o?1e3*e+ ++r:(r=0,1e3*(o=e))},n.randomInt=function(e,t){return Math.floor(Math.random()*(t-e+1)+e)},n.randomToken=function(){return Math.random().toString(36).substring(2)},n.sleep=function(t,n){t=t||0;return new Promise(function(e){return setTimeout(function(){return e(n)},t)})},n.supportsWebLockAPI=function(){return"undefined"!=typeof navigator&&void 0!==navigator.locks&&"function"==typeof navigator.locks.request};n.PROMISE_RESOLVED_FALSE=Promise.resolve(!1),n.PROMISE_RESOLVED_TRUE=Promise.resolve(!0),n.PROMISE_RESOLVED_VOID=Promise.resolve();var o=0,r=0},{}],15:[function(e,t,n){function o(e){return t.exports=o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,o(e)}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},{}],16:[function(e,t,n){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&("get"in r?t.__esModule:!r.writable&&!r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){e[o=void 0===o?n:o]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&o(t,e,n);return r(t,e),t},n=(Object.defineProperty(n,"__esModule",{value:!0}),i(e("./index.js")));t.exports=n},{"./index.js":17}],17:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.now=n.removeTooOldValues=n.ObliviousSet=void 0;function o(e){for(var t=i()-e.ttl,n=e.map[Symbol.iterator]();;){var o=n.next().value;if(!o)return;var r=o[0];if(!(o[1]<t))return;e.map.delete(r)}}function i(){return Date.now()}n.ObliviousSet=class{ttl;map=new Map;_to=!1;constructor(e){this.ttl=e}has(e){return this.map.has(e)}add(e){this.map.set(e,i()),this._to||(this._to=!0,setTimeout(()=>{this._to=!1,o(this)},0))}clear(){this.map.clear()}},n.removeTooOldValues=o,n.now=i},{}],18:[function(e,t,n){var o,r,t=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}try{o="function"==typeof setTimeout?setTimeout:i}catch(e){o=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}function a(t){if(o===setTimeout)return setTimeout(t,0);if((o===i||!o)&&setTimeout)return(o=setTimeout)(t,0);try{return o(t,0)}catch(e){try{return o.call(null,t,0)}catch(e){return o.call(this,t,0)}}}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){for(var e=a(f),t=(l=!0,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(r===clearTimeout)return clearTimeout(t);if((r===s||!r)&&clearTimeout)return(r=clearTimeout)(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.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}},{}],19:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.addBrowser=function(e){{var t;"function"==typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?(t=self.close.bind(self),self.close=function(){return e(),t()}):"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0))}}},{}],20:[function(a,e,u){!function(s){!function(){"use strict";Object.defineProperty(u,"__esModule",{value:!0}),u.add=function(e){if(r||(r=!0,n(i)),"function"!=typeof e)throw new Error("Listener is no function");return o.add(e),{remove:function(){return o.delete(e)},run:function(){return o.delete(e),e()}}},u.getSize=function(){return o.size},u.removeAll=function(){o.clear()},u.runAll=i;var e=a("./browser.js"),t=a("./node.js"),n="[object process]"===Object.prototype.toString.call(void 0!==s?s:0)?t.addNode:e.addBrowser,o=new Set,r=!1;function i(){var t=[];return o.forEach(function(e){t.push(e()),o.delete(e)}),Promise.all(t)}}.call(this)}.call(this,a("_process"))},{"./browser.js":19,"./node.js":21,_process:18}],21:[function(e,t,o){!function(n){!function(){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.addNode=function(t){n.on("exit",function(){return t()}),n.on("beforeExit",function(){return t().then(function(){return n.exit()})}),n.on("SIGINT",function(){return t().then(function(){return n.exit()})}),n.on("uncaughtException",function(e){return t().then(function(){console.trace(e),n.exit(101)})})}}.call(this)}.call(this,e("_process"))},{_process:18}]},{},[2]); | ||
!function o(r,i,s){function a(t,e){if(!i[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}n=i[t]={exports:{}},r[t][0].call(n.exports,function(e){return a(r[t][1][e]||e)},n,n.exports,o,r,i,s)}return i[t].exports}for(var c="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.OPEN_BROADCAST_CHANNELS=n.BroadcastChannel=void 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}):r.PROMISE_RESOLVED_FALSE},n.enforceOptions=function(e){o=e};var o,r=e("./util.js"),i=e("./method-chooser.js"),s=e("./options.js"),a=n.OPEN_BROADCAST_CHANNELS=new Set,c=0,e=n.BroadcastChannel=function(e,t){var n;this.id=c++,a.add(this),this.name=e,o&&(t=o),this.options=(0,s.fillOptionsWithDefaults)(t),this.method=(0,i.chooseMethod)(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._uMP=new Set,this._befC=[],this._prepP=null,e=(n=this).method.create(n.name,n.options),(0,r.isPromise)(e)?(n._prepP=e).then(function(e){n._state=e}):n._state=e};function u(t,e,n){var o={time:t.method.microSeconds(),type:e,data:n};return(t._prepP||r.PROMISE_RESOLVED_VOID).then(function(){var e=t.method.postMessage(t._state,o);return t._uMP.add(e),e.catch().then(function(){return t._uMP.delete(e)}),e})}function l(e){return 0<e._addEL.message.length||0<e._addEL.internal.length}function d(e,t,n){e._addEL[t].push(n);var o,r,i=e;!i._iL&&l(i)&&(o=function(t){i._addEL[t.type].forEach(function(e){t.time>=e.time&&e.fn(t.data)})},r=i.method.microSeconds(),i._prepP?i._prepP.then(function(){i._iL=!0,i.method.onMessage(i._state,o,r)}):(i._iL=!0,i.method.onMessage(i._state,o,r)))}function f(e,t,n){e._addEL[t]=e._addEL[t].filter(function(e){return e!==n});t=e;t._iL&&!l(t)&&(t._iL=!1,e=t.method.microSeconds(),t.method.onMessage(t._state,null,e))}e._pubkey=!0,e.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed "+JSON.stringify(e));return u(this,"message",e)},postInternal:function(e){return u(this,"internal",e)},set onmessage(e){var t={time:this.method.microSeconds(),fn:e};f(this,"message",this._onML),e&&"function"==typeof e?(this._onML=t,d(this,"message",t)):this._onML=null},addEventListener:function(e,t){var n=this.method.microSeconds();d(this,e,{time:n,fn:t})},removeEventListener:function(e,t){var n=this._addEL[e].find(function(e){return e.fn===t});f(this,e,n)},close:function(){var e,t=this;if(!this.closed)return a.delete(this),this.closed=!0,e=this._prepP||r.PROMISE_RESOLVED_VOID,this._onML=null,this._addEL.message=[],e.then(function(){return Promise.all(Array.from(t._uMP))}).then(function(){return Promise.all(t._befC.map(function(e){return e()}))}).then(function(){return t.method.close(t._state)})},get type(){return this.method.type},get isClosed(){return this.closed}}},{"./method-chooser.js":8,"./options.js":13,"./util.js":14}],2:[function(e,t,n){"use strict";var e=e("./index.es5.js"),o=e.BroadcastChannel,e=e.createLeaderElection;window.BroadcastChannel2=o,window.createLeaderElection=e},{"./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,beLeader:e.beLeader}},{"./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 o.BroadcastChannel}}),Object.defineProperty(n,"OPEN_BROADCAST_CHANNELS",{enumerable:!0,get:function(){return o.OPEN_BROADCAST_CHANNELS}}),Object.defineProperty(n,"beLeader",{enumerable:!0,get:function(){return i.beLeader}}),Object.defineProperty(n,"clearNodeFolder",{enumerable:!0,get:function(){return o.clearNodeFolder}}),Object.defineProperty(n,"createLeaderElection",{enumerable:!0,get:function(){return r.createLeaderElection}}),Object.defineProperty(n,"enforceOptions",{enumerable:!0,get:function(){return o.enforceOptions}});var o=e("./broadcast-channel.js"),r=e("./leader-election.js"),i=e("./leader-election-util.js")},{"./broadcast-channel.js":1,"./leader-election-util.js":5,"./leader-election.js":7}],5:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.beLeader=function(t){t.isLeader=!0,t._hasLeader=!0;function e(e){"leader"===e.context&&"apply"===e.action&&r(t,"tell"),"leader"!==e.context||"tell"!==e.action||t._dpLC||(t._dpLC=!0,t._dpL(),r(t,"tell"))}var n=(0,o.add)(function(){return t.die()});t._unl.push(n);return t.broadcastChannel.addEventListener("internal",e),t._lstns.push(e),r(t,"tell")},n.sendLeaderMessage=r;var o=e("unload");function r(e,t){t={context:"leader",action:t,token:e.token};return e.broadcastChannel.postInternal(t)}},{unload:20}],6:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LeaderElectionWebLock=void 0;var o=e("./util.js"),r=e("./leader-election-util.js");(n.LeaderElectionWebLock=function(e,t){var n=this;(this.broadcastChannel=e)._befC.push(function(){return n.die()}),this._options=t,this.isLeader=!1,this.isDead=!1,this.token=(0,o.randomToken)(),this._lstns=[],this._unl=[],this._dpL=function(){},this._dpLC=!1,this._wKMC={},this.lN="pubkey-bc||"+e.method.type+"||"+e.name}).prototype={hasLeader:function(){var t=this;return navigator.locks.query().then(function(e){e=e.held?e.held.filter(function(e){return e.name===t.lN}):[];return!!(e&&0<e.length)})},awaitLeadership:function(){var t,n=this;return this._wLMP||(this._wKMC.c=new AbortController,t=new Promise(function(e,t){n._wKMC.res=e,n._wKMC.rej=t}),this._wLMP=new Promise(function(e){navigator.locks.request(n.lN,{signal:n._wKMC.c.signal},function(){return(n._wKMC.c=void 0,r.beLeader)(n),e(),t}).catch(function(){})})),this._wLMP},set onduplicate(e){},die:function(){var t=this;return this._lstns.forEach(function(e){return t.broadcastChannel.removeEventListener("internal",e)}),this._lstns=[],this._unl.forEach(function(e){return e.remove()}),this._unl=[],this.isLeader&&(this.isLeader=!1),this.isDead=!0,this._wKMC.res&&this._wKMC.res(),this._wKMC.c&&this._wKMC.c.abort("LeaderElectionWebLock.die() called"),(0,r.sendLeaderMessage)(this,"death")}}},{"./leader-election-util.js":5,"./util.js":14}],7:[function(e,t,n){"use strict";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((0,a.supportsWebLockAPI)()?o.LeaderElectionWebLock:r)(e,t);return e._befC.push(function(){return n.die()}),e._leaderElector=n};var a=e("./util.js"),c=e("./leader-election-util.js"),o=e("./leader-election-web-lock.js"),r=function(e,t){function n(e){"leader"===e.context&&("death"===e.action&&(o._hasLeader=!1),"tell"===e.action)&&(o._hasLeader=!0)}var o=this;this.broadcastChannel=e,this._options=t,this.isLeader=!1,this._hasLeader=!1,this.isDead=!1,this.token=(0,a.randomToken)(),this._aplQ=a.PROMISE_RESOLVED_VOID,this._aplQC=0,this._unl=[],this._lstns=[],this._dpL=function(){},this._dpLC=!1;this.broadcastChannel.addEventListener("internal",n),this._lstns.push(n)};r.prototype={hasLeader:function(){return Promise.resolve(this._hasLeader)},applyOnce:function(i){var s=this;return this.isLeader?(0,a.sleep)(0,!0):this.isDead?(0,a.sleep)(0,!1):1<this._aplQC?this._aplQ:(this._aplQC=this._aplQC+1,this._aplQ=this._aplQ.then(function(){return s.isLeader?a.PROMISE_RESOLVED_TRUE:(t=!1,e=new Promise(function(e){n=function(){t=!0,e()}}),s.broadcastChannel.addEventListener("internal",o=function(e){"leader"===e.context&&e.token!=s.token&&("apply"===e.action&&e.token>s.token&&n(),"tell"===e.action)&&(n(),s._hasLeader=!0)}),r=i?4*s._options.responseTime:s._options.responseTime,(0,c.sendLeaderMessage)(s,"apply").then(function(){return Promise.race([(0,a.sleep)(r),e.then(function(){return Promise.reject(new Error)})])}).then(function(){return(0,c.sendLeaderMessage)(s,"apply")}).then(function(){return Promise.race([(0,a.sleep)(r),e.then(function(){return Promise.reject(new Error)})])}).catch(function(){}).then(function(){return s.broadcastChannel.removeEventListener("internal",o),!t&&(0,c.beLeader)(s).then(function(){return!0})}));var t,n,e,o,r}).then(function(){s._aplQC=s._aplQC-1}),this._aplQ.then(function(){return s.isLeader}))},awaitLeadership:function(){return this._aLP||(this._aLP=function(r){if(r.isLeader)return a.PROMISE_RESOLVED_VOID;return new Promise(function(e){var t=!1;function n(){t||(t=!0,r.broadcastChannel.removeEventListener("internal",o),e(!0))}r.applyOnce().then(function(){r.isLeader&&n()});(function e(){return(0,a.sleep)(r._options.fallbackInterval).then(function(){if(!r.isDead&&!t)return r.isLeader?void n():r.applyOnce(!0).then(function(){(r.isLeader?n:e)()})})})();var o=function(e){"leader"===e.context&&"death"===e.action&&(r._hasLeader=!1,r.applyOnce().then(function(){r.isLeader&&n()}))};r.broadcastChannel.addEventListener("internal",o),r._lstns.push(o)})}(this)),this._aLP},set onduplicate(e){this._dpL=e},die:function(){var t=this;return this._lstns.forEach(function(e){return t.broadcastChannel.removeEventListener("internal",e)}),this._lstns=[],this._unl.forEach(function(e){return e.remove()}),this._unl=[],this.isLeader&&(this._hasLeader=!1,this.isLeader=!1),this.isDead=!0,(0,c.sendLeaderMessage)(this,"death")}}},{"./leader-election-util.js":5,"./leader-election-web-lock.js":6,"./util.js":14}],8:[function(e,t,n){"use strict";e("@babel/runtime/helpers/typeof");Object.defineProperty(n,"__esModule",{value:!0}),n.chooseMethod=function(t){var e=[].concat(t.methods,s).filter(Boolean);if(t.type){if("simulate"===t.type)return i.SimulateMethod;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||(e=e.filter(function(e){return"idb"!==e.type}));n=e.find(function(e){return e.canBeUsed()});{if(n)return n;throw new Error("No usable method found in "+JSON.stringify(s.map(function(e){return e.type})))}};var n=e("./methods/native.js"),o=e("./methods/indexed-db.js"),r=e("./methods/localstorage.js"),i=e("./methods/simulate.js");var s=[n.NativeMethod,o.IndexedDBMethod,r.LocalstorageMethod]},{"./methods/indexed-db.js":9,"./methods/localstorage.js":10,"./methods/native.js":11,"./methods/simulate.js":12,"@babel/runtime/helpers/typeof":15}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.TRANSACTION_SETTINGS=n.IndexedDBMethod=void 0,n.averageResponseTime=E,n.canBeUsed=y,n.cleanOldMessages=_,n.close=g,n.commitIndexedDBTransaction=d,n.create=v,n.createDatabase=c,n.getAllMessages=function(e){var n=e.transaction(u,"readonly",l),o=n.objectStore(u),r=[];return new Promise(function(t){o.openCursor().onsuccess=function(e){e=e.target.result;e?(r.push(e.value),e.continue()):(d(n),t(r))}})},n.getIdb=a,n.getMessagesHigherThan=h,n.getOldMessages=m,n.microSeconds=void 0,n.onMessage=L,n.postMessage=w,n.removeMessagesById=p,n.type=void 0,n.writeMessage=f;var r=e("../util.js"),i=e("oblivious-set"),s=e("../options.js"),e=n.microSeconds=r.microSeconds,o="pubkey.broadcast-channel-0-",u="messages",l=n.TRANSACTION_SETTINGS={durability:"relaxed"};n.type="idb";function a(){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 d(e){e.commit&&e.commit()}function c(e){var n=a().open(o+e);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 f(e,t,n){var o={uuid:t,time:Date.now(),data:n},r=e.transaction([u],"readwrite",l);return new Promise(function(e,t){r.oncomplete=function(){return e()},r.onerror=function(e){return t(e)},r.objectStore(u).add(o),d(r)})}function h(e,o){var r,i=e.transaction(u,"readonly",l),s=i.objectStore(u),a=[],c=IDBKeyRange.bound(o+1,1/0);return s.getAll?(r=s.getAll(c),new Promise(function(t,n){r.onerror=function(e){return n(e)},r.onsuccess=function(e){t(e.target.result)}})):new Promise(function(t,n){var e=function(){try{return c=IDBKeyRange.bound(o+1,1/0),s.openCursor(c)}catch(e){return s.openCursor()}}();e.onerror=function(e){return n(e)},e.onsuccess=function(e){e=e.target.result;e?e.value.id<o+1?e.continue(o+1):(a.push(e.value),e.continue()):(d(i),t(a))}})}function p(e,t){var n;return e.closed?Promise.resolve([]):(n=e.db.transaction(u,"readwrite",l).objectStore(u),Promise.all(t.map(function(e){var t=n.delete(e);return new Promise(function(e){t.onsuccess=function(){return e()}})})))}function m(e,t){var o=Date.now()-t,r=e.transaction(u,"readonly",l),i=r.objectStore(u),s=[];return new Promise(function(n){i.openCursor().onsuccess=function(e){var t,e=e.target.result;e?(t=e.value).time<o?(s.push(t),e.continue()):(d(r),n(s)):n(s)}})}function _(t){return m(t.db,t.options.idb.ttl).then(function(e){return p(t,e.map(function(e){return e.id}))})}function v(n,o){return o=(0,s.fillOptionsWithDefaults)(o),c(n).then(function(e){var t={closed:!1,lastCursorId:0,channelName:n,options:o,uuid:(0,r.randomToken)(),eMIs:new i.ObliviousSet(2*o.idb.ttl),writeBlockPromise:r.PROMISE_RESOLVED_VOID,messagesCallback:null,readQueuePromises:[],db:e};return e.onclose=function(){t.closed=!0,o.idb.onclose&&o.idb.onclose()},function e(t){if(t.closed)return;b(t).then(function(){return(0,r.sleep)(t.options.idb.fallbackInterval)}).then(function(){return e(t)})}(t),t})}function b(n){return!n.closed&&n.messagesCallback?h(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))}),r.PROMISE_RESOLVED_VOID}):r.PROMISE_RESOLVED_VOID}function g(e){e.closed=!0,e.db.close()}function w(e,t){return e.writeBlockPromise=e.writeBlockPromise.then(function(){return f(e.db,e.uuid,t)}).then(function(){0===(0,r.randomInt)(0,10)&&_(e)}),e.writeBlockPromise}function L(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t,b(e)}function y(){return!!a()}function E(e){return 2*e.idb.fallbackInterval}n.IndexedDBMethod={create:v,close:g,onMessage:L,postMessage:w,canBeUsed:y,type:"idb",averageResponseTime:E,microSeconds:e}},{"../options.js":13,"../util.js":14,"oblivious-set":16}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LocalstorageMethod=void 0,n.addStorageEventListener=l,n.averageResponseTime=_,n.canBeUsed=m,n.close=h,n.create=f,n.getLocalStorage=c,n.microSeconds=void 0,n.onMessage=p,n.postMessage=o,n.removeStorageEventListener=d,n.storageKey=u,n.type=void 0;var i=e("oblivious-set"),s=e("../options.js"),a=e("../util.js"),e=n.microSeconds=a.microSeconds,r="pubkey.broadcastChannel-";n.type="localstorage";function c(){var e;if("undefined"==typeof window)return null;try{e=window.localStorage,e=window["ie8-eventlistener/storage"]||window.localStorage}catch(e){}return e}function u(e){return r+e}function o(r,i){return new Promise(function(o){(0,a.sleep)().then(function(){var e=u(r.channelName),t={token:(0,a.randomToken)(),time:Date.now(),data:i,uuid:r.uuid},t=JSON.stringify(t),n=(c().setItem(e,t),document.createEvent("Event"));n.initEvent("storage",!0,!0),n.key=e,n.newValue=t,window.dispatchEvent(n),o()})})}function l(e,t){function n(e){e.key===o&&t(JSON.parse(e.newValue))}var o=r+e;return window.addEventListener("storage",n),n}function d(e){window.removeEventListener("storage",e)}function f(e,t){var n,o,r;if(t=(0,s.fillOptionsWithDefaults)(t),m())return n=(0,a.randomToken)(),o=new i.ObliviousSet(t.localstorage.removeTimeout),(r={channelName:e,uuid:n,eMIs:o}).listener=l(e,function(e){!r.messagesCallback||e.uuid===n||!e.token||o.has(e.token)||e.data.time&&e.data.time<r.messagesCallbackTime||(o.add(e.token),r.messagesCallback(e.data))}),r;throw new Error("BroadcastChannel: localstorage cannot be used")}function h(e){d(e.listener)}function p(e,t,n){e.messagesCallbackTime=n,e.messagesCallback=t}function m(){var e=c();if(!e)return!1;try{var t="__broadcastchannel_check";e.setItem(t,"works"),e.removeItem(t)}catch(e){return!1}return!0}function _(){var e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?240:120}n.LocalstorageMethod={create:f,close:h,onMessage:p,postMessage:o,canBeUsed:m,type:"localstorage",averageResponseTime:_,microSeconds:e}},{"../options.js":13,"../util.js":14,"oblivious-set":16}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.NativeMethod=void 0,n.averageResponseTime=u,n.canBeUsed=c,n.close=i,n.create=r,n.microSeconds=void 0,n.onMessage=a,n.postMessage=s,n.type=void 0;var o=e("../util.js"),e=n.microSeconds=o.microSeconds;n.type="native";function r(e){var t={time:(0,o.microSeconds)(),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){try{return e.bc.postMessage(t,!1),o.PROMISE_RESOLVED_VOID}catch(e){return Promise.reject(e)}}function a(e,t){e.messagesCallback=t}function c(){if("undefined"==typeof globalThis||!globalThis.Deno||!globalThis.Deno.args){if("undefined"==typeof window&&"undefined"==typeof self||"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 u(){return 150}n.NativeMethod={create:r,close:i,onMessage:a,postMessage:s,canBeUsed:c,type:"native",averageResponseTime:u,microSeconds:e}},{"../util.js":14}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.SimulateMethod=n.SIMULATE_DELAY_TIME=void 0,n.averageResponseTime=d,n.canBeUsed=l,n.close=s,n.create=i,n.microSeconds=void 0,n.onMessage=u,n.postMessage=c,n.type=void 0;var e=e("../util.js"),o=n.microSeconds=e.microSeconds,r=(n.type="simulate",new Set);function i(e){e={time:o(),name:e,messagesCallback:null};return r.add(e),e}function s(e){r.delete(e)}var a=n.SIMULATE_DELAY_TIME=5;function c(t,n){return new Promise(function(e){return setTimeout(function(){Array.from(r).forEach(function(e){e.name===t.name&&e!==t&&e.messagesCallback&&e.time<n.time&&e.messagesCallback(n)}),e()},a)})}function u(e,t){e.messagesCallback=t}function l(){return!0}function d(){return a}n.SimulateMethod={create:i,close:s,onMessage:u,postMessage:c,canBeUsed:l,type:"simulate",averageResponseTime:d,microSeconds:o}},{"../util.js":14}],13:[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);t.node.maxParallelWrites||(t.node.maxParallelWrites=2048);void 0===t.node.useFastPath&&(t.node.useFastPath=!0);return t}},{}],14:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.PROMISE_RESOLVED_VOID=n.PROMISE_RESOLVED_TRUE=n.PROMISE_RESOLVED_FALSE=void 0,n.isPromise=function(e){return e&&"function"==typeof e.then},n.microSeconds=function(){var e=1e3*Date.now();e<=o&&(e=o+1);return o=e},n.randomInt=function(e,t){return Math.floor(Math.random()*(t-e+1)+e)},n.randomToken=function(){return Math.random().toString(36).substring(2)},n.sleep=function(t,n){t=t||0;return new Promise(function(e){return setTimeout(function(){return e(n)},t)})},n.supportsWebLockAPI=function(){return"undefined"!=typeof navigator&&void 0!==navigator.locks&&"function"==typeof navigator.locks.request};n.PROMISE_RESOLVED_FALSE=Promise.resolve(!1),n.PROMISE_RESOLVED_TRUE=Promise.resolve(!0),n.PROMISE_RESOLVED_VOID=Promise.resolve();var o=0},{}],15:[function(e,t,n){function o(e){return t.exports=o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,o(e)}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},{}],16:[function(e,t,n){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&("get"in r?t.__esModule:!r.writable&&!r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){e[o=void 0===o?n:o]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&o(t,e,n);return r(t,e),t},n=(Object.defineProperty(n,"__esModule",{value:!0}),i(e("./index.js")));t.exports=n},{"./index.js":17}],17:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.now=n.removeTooOldValues=n.ObliviousSet=void 0;function o(e){for(var t=i()-e.ttl,n=e.map[Symbol.iterator]();;){var o=n.next().value;if(!o)return;var r=o[0];if(!(o[1]<t))return;e.map.delete(r)}}function i(){return Date.now()}n.ObliviousSet=class{ttl;map=new Map;_to=!1;constructor(e){this.ttl=e}has(e){return this.map.has(e)}add(e){this.map.set(e,i()),this._to||(this._to=!0,setTimeout(()=>{this._to=!1,o(this)},0))}clear(){this.map.clear()}},n.removeTooOldValues=o,n.now=i},{}],18:[function(e,t,n){var o,r,t=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}try{o="function"==typeof setTimeout?setTimeout:i}catch(e){o=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}function a(t){if(o===setTimeout)return setTimeout(t,0);if((o===i||!o)&&setTimeout)return(o=setTimeout)(t,0);try{return o(t,0)}catch(e){try{return o.call(null,t,0)}catch(e){return o.call(this,t,0)}}}var c,u=[],l=!1,d=-1;function f(){l&&c&&(l=!1,c.length?u=c.concat(u):d=-1,u.length)&&h()}function h(){if(!l){for(var e=a(f),t=(l=!0,u.length);t;){for(c=u,u=[];++d<t;)c&&c[d].run();d=-1,t=u.length}c=null,l=!1,!function(t){if(r===clearTimeout)return clearTimeout(t);if((r===s||!r)&&clearTimeout)return(r=clearTimeout)(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.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];u.push(new p(e,t)),1!==u.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}},{}],19:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.addBrowser=function(e){{var t;"function"==typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?(t=self.close.bind(self),self.close=function(){return e(),t()}):"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0))}}},{}],20:[function(a,e,c){!function(s){!function(){"use strict";Object.defineProperty(c,"__esModule",{value:!0}),c.add=function(e){if(r||(r=!0,n(i)),"function"!=typeof e)throw new Error("Listener is no function");return o.add(e),{remove:function(){return o.delete(e)},run:function(){return o.delete(e),e()}}},c.getSize=function(){return o.size},c.removeAll=function(){o.clear()},c.runAll=i;var e=a("./browser.js"),t=a("./node.js"),n="[object process]"===Object.prototype.toString.call(void 0!==s?s:0)?t.addNode:e.addBrowser,o=new Set,r=!1;function i(){var t=[];return o.forEach(function(e){t.push(e()),o.delete(e)}),Promise.all(t)}}.call(this)}.call(this,a("_process"))},{"./browser.js":19,"./node.js":21,_process:18}],21:[function(e,t,o){!function(n){!function(){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.addNode=function(t){n.on("exit",function(){return t()}),n.on("beforeExit",function(){return t().then(function(){return n.exit()})}),n.on("SIGINT",function(){return t().then(function(){return n.exit()})}),n.on("uncaughtException",function(e){return t().then(function(){console.trace(e),n.exit(101)})})}}.call(this)}.call(this,e("_process"))},{_process:18}]},{},[2]); |
@@ -20,2 +20,3 @@ "use strict"; | ||
var state = { | ||
time: (0, _util.microSeconds)(), | ||
messagesCallback: null, | ||
@@ -26,5 +27,5 @@ bc: new BroadcastChannel(channelName), | ||
state.bc.onmessage = function (msg) { | ||
state.bc.onmessage = function (msgEvent) { | ||
if (state.messagesCallback) { | ||
state.messagesCallback(msg.data); | ||
state.messagesCallback(msgEvent.data); | ||
} | ||
@@ -31,0 +32,0 @@ }; |
@@ -443,7 +443,9 @@ "use strict"; | ||
function writeMessage(channelName, readerUuid, messageJson, paths) { | ||
var time = messageJson.time; | ||
if (!time) { | ||
time = microSeconds(); | ||
} | ||
paths = paths || getPaths(channelName); | ||
var time = microSeconds(); | ||
var writeObject = { | ||
uuid: readerUuid, | ||
time: time, | ||
data: messageJson | ||
@@ -691,4 +693,4 @@ }; | ||
if (!state.messagesCallback) return false; // no listener | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older then onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older then channel | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older than onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older than channel | ||
@@ -695,0 +697,0 @@ state.emittedMessagesIds.add(msgObj.token); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.SimulateMethod = void 0; | ||
exports.SimulateMethod = exports.SIMULATE_DELAY_TIME = void 0; | ||
exports.averageResponseTime = averageResponseTime; | ||
@@ -22,2 +22,3 @@ exports.canBeUsed = canBeUsed; | ||
var state = { | ||
time: microSeconds(), | ||
name: channelName, | ||
@@ -32,2 +33,3 @@ messagesCallback: null | ||
} | ||
var SIMULATE_DELAY_TIME = exports.SIMULATE_DELAY_TIME = 5; | ||
function postMessage(channelState, messageJson) { | ||
@@ -37,13 +39,16 @@ return new Promise(function (res) { | ||
var channelArray = Array.from(SIMULATE_CHANNELS); | ||
channelArray.filter(function (channel) { | ||
return channel.name === channelState.name; | ||
}).filter(function (channel) { | ||
return channel !== channelState; | ||
}).filter(function (channel) { | ||
return !!channel.messagesCallback; | ||
}).forEach(function (channel) { | ||
return channel.messagesCallback(messageJson); | ||
channelArray.forEach(function (channel) { | ||
if (channel.name === channelState.name && | ||
// has same name | ||
channel !== channelState && | ||
// not own channel | ||
!!channel.messagesCallback && | ||
// has subscribers | ||
channel.time < messageJson.time // channel not created after postMessage() call | ||
) { | ||
channel.messagesCallback(messageJson); | ||
} | ||
}); | ||
res(); | ||
}, 5); | ||
}, SIMULATE_DELAY_TIME); | ||
}); | ||
@@ -58,3 +63,3 @@ } | ||
function averageResponseTime() { | ||
return 5; | ||
return SIMULATE_DELAY_TIME; | ||
} | ||
@@ -61,0 +66,0 @@ var SimulateMethod = exports.SimulateMethod = { |
@@ -41,6 +41,5 @@ "use strict"; | ||
var lastMs = 0; | ||
var additional = 0; | ||
/** | ||
* returns the current time in micro-seconds, | ||
* Returns the current unix time in micro-seconds, | ||
* WARNING: This is a pseudo-function | ||
@@ -52,11 +51,8 @@ * Performance.now is not reliable in webworkers, so we just make sure to never return the same time. | ||
function microSeconds() { | ||
var ms = Date.now(); | ||
if (ms === lastMs) { | ||
additional++; | ||
return ms * 1000 + additional; | ||
} else { | ||
lastMs = ms; | ||
additional = 0; | ||
return ms * 1000; | ||
var ret = Date.now() * 1000; // milliseconds to microseconds | ||
if (ret <= lastMs) { | ||
ret = lastMs + 1; | ||
} | ||
lastMs = ret; | ||
return ret; | ||
} | ||
@@ -63,0 +59,0 @@ |
{ | ||
"name": "broadcast-channel", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers, NodeJs, Deno and iframes", | ||
@@ -102,3 +102,3 @@ "exports": { | ||
"dependencies": { | ||
"@babel/runtime": "7.23.2", | ||
"@babel/runtime": "7.23.4", | ||
"oblivious-set": "1.4.0", | ||
@@ -109,12 +109,13 @@ "p-queue": "6.6.2", | ||
"devDependencies": { | ||
"@babel/cli": "7.23.0", | ||
"@babel/core": "7.23.2", | ||
"@babel/cli": "7.23.4", | ||
"@babel/core": "7.23.3", | ||
"@babel/plugin-proposal-object-rest-spread": "7.20.7", | ||
"@babel/plugin-transform-member-expression-literals": "7.22.5", | ||
"@babel/plugin-transform-property-literals": "7.22.5", | ||
"@babel/plugin-transform-runtime": "7.23.2", | ||
"@babel/plugin-transform-member-expression-literals": "7.23.3", | ||
"@babel/plugin-transform-property-literals": "7.23.3", | ||
"@babel/plugin-transform-runtime": "7.23.4", | ||
"@babel/polyfill": "7.12.1", | ||
"@babel/preset-env": "7.23.2", | ||
"@babel/types": "7.23.0", | ||
"@types/core-js": "2.5.7", | ||
"@babel/preset-env": "7.23.3", | ||
"@babel/types": "7.23.4", | ||
"@rollup/plugin-terser": "0.4.4", | ||
"@types/core-js": "2.5.8", | ||
"assert": "2.1.0", | ||
@@ -130,3 +131,3 @@ "async-test-util": "2.2.1", | ||
"detect-node": "2.1.0", | ||
"eslint": "8.52.0", | ||
"eslint": "8.54.0", | ||
"gzip-size-cli": "5.1.0", | ||
@@ -153,7 +154,6 @@ "http-server": "14.1.1", | ||
"rimraf": "5.0.5", | ||
"rollup": "4.1.5", | ||
"@rollup/plugin-terser": "0.4.4", | ||
"testcafe": "3.3.0", | ||
"rollup": "4.6.0", | ||
"testcafe": "3.4.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.2.2", | ||
"typescript": "5.3.2", | ||
"uglify-js": "3.17.4", | ||
@@ -160,0 +160,0 @@ "watchify": "4.0.0", |
@@ -196,3 +196,2 @@ import { | ||
return awaitPrepare.then(() => { | ||
const sendPromise = broadcastChannel.method.postMessage( | ||
@@ -253,15 +252,3 @@ broadcastChannel._state, | ||
.forEach(listenerObject => { | ||
/** | ||
* Getting the current time in JavaScript has no good precision. | ||
* So instead of only listening to events that happened 'after' the listener | ||
* was added, we also listen to events that happened 100ms before it. | ||
* This ensures that when another process, like a WebWorker, sends events | ||
* we do not miss them out because their timestamp is a bit off compared to the main process. | ||
* Not doing this would make messages missing when we send data directly after subscribing and awaiting a response. | ||
* @link https://johnresig.com/blog/accuracy-of-javascript-time/ | ||
*/ | ||
const hundredMsInMicro = 100 * 1000; | ||
const minMessageTime = listenerObject.time - hundredMsInMicro; | ||
if (msgObj.time >= minMessageTime) { | ||
if (msgObj.time >= listenerObject.time) { | ||
listenerObject.fn(msgObj.data); | ||
@@ -268,0 +255,0 @@ } |
@@ -13,2 +13,3 @@ | ||
const state = { | ||
time: micro(), | ||
messagesCallback: null, | ||
@@ -19,5 +20,5 @@ bc: new BroadcastChannel(channelName), | ||
state.bc.onmessage = msg => { | ||
state.bc.onmessage = msgEvent => { | ||
if (state.messagesCallback) { | ||
state.messagesCallback(msg.data); | ||
state.messagesCallback(msgEvent.data); | ||
} | ||
@@ -24,0 +25,0 @@ }; |
@@ -275,7 +275,11 @@ /** | ||
export function writeMessage(channelName, readerUuid, messageJson, paths) { | ||
let time = messageJson.time; | ||
if (!time) { | ||
time = microSeconds(); | ||
} | ||
paths = paths || getPaths(channelName); | ||
const time = microSeconds(); | ||
const writeObject = { | ||
uuid: readerUuid, | ||
time, | ||
data: messageJson | ||
@@ -455,4 +459,4 @@ }; | ||
if (!state.messagesCallback) return false; // no listener | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older then onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older then channel | ||
if (msgObj.time < state.messagesCallbackTime) return false; // not older than onMessageCallback | ||
if (msgObj.time < state.time) return false; // msgObj is older than channel | ||
@@ -459,0 +463,0 @@ state.emittedMessagesIds.add(msgObj.token); |
@@ -13,2 +13,3 @@ import { | ||
const state = { | ||
time: microSeconds(), | ||
name: channelName, | ||
@@ -18,3 +19,2 @@ messagesCallback: null | ||
SIMULATE_CHANNELS.add(state); | ||
return state; | ||
@@ -27,12 +27,19 @@ } | ||
export const SIMULATE_DELAY_TIME = 5; | ||
export function postMessage(channelState, messageJson) { | ||
return new Promise(res => setTimeout(() => { | ||
const channelArray = Array.from(SIMULATE_CHANNELS); | ||
channelArray | ||
.filter(channel => channel.name === channelState.name) | ||
.filter(channel => channel !== channelState) | ||
.filter(channel => !!channel.messagesCallback) | ||
.forEach(channel => channel.messagesCallback(messageJson)); | ||
channelArray.forEach(channel => { | ||
if ( | ||
channel.name === channelState.name && // has same name | ||
channel !== channelState && // not own channel | ||
!!channel.messagesCallback && // has subscribers | ||
channel.time < messageJson.time // channel not created after postMessage() call | ||
) { | ||
channel.messagesCallback(messageJson); | ||
} | ||
}); | ||
res(); | ||
}, 5)); | ||
}, SIMULATE_DELAY_TIME)); | ||
} | ||
@@ -50,3 +57,3 @@ | ||
export function averageResponseTime() { | ||
return 5; | ||
return SIMULATE_DELAY_TIME; | ||
} | ||
@@ -53,0 +60,0 @@ |
@@ -31,6 +31,5 @@ /** | ||
let lastMs = 0; | ||
let additional = 0; | ||
/** | ||
* returns the current time in micro-seconds, | ||
* Returns the current unix time in micro-seconds, | ||
* WARNING: This is a pseudo-function | ||
@@ -42,11 +41,8 @@ * Performance.now is not reliable in webworkers, so we just make sure to never return the same time. | ||
export function microSeconds() { | ||
const ms = Date.now(); | ||
if (ms === lastMs) { | ||
additional++; | ||
return ms * 1000 + additional; | ||
} else { | ||
lastMs = ms; | ||
additional = 0; | ||
return ms * 1000; | ||
let ret = Date.now() * 1000; // milliseconds to microseconds | ||
if (ret <= lastMs) { | ||
ret = lastMs + 1; | ||
} | ||
lastMs = ret; | ||
return ret; | ||
} | ||
@@ -53,0 +49,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98
535106
13847
+ Added@babel/runtime@7.23.4(transitive)
- Removed@babel/runtime@7.23.2(transitive)
Updated@babel/runtime@7.23.4