window.esw.defineFeature("Broadcast",function(e){function c(){this.esw=e;this.callbacks={};e.noLocalStorageAvailable?e.noSessionStorageAvailable||(this.storage=window.sessionStorage):this.storage=window.localStorage;this.prefix="__broadcastAPI:";this.queue={};this.postedEvents=new Set;this.postedEvents2=new Set;this.on();this.off();this.send();window.addEventListener("storage",function(a){var b=a.newValue,d="";if(0===a.key.indexOf(this.prefix)&&null===a.oldValue){var f=a.key.replace(this.prefix,""); "undefined"!==b&&(d=JSON.parse(b));this.safariWorkaroundIgnoreSameTabEvents(a.key,d)||this.broadcast(f,d)}}.bind(this));window.addEventListener("storage",function(a){if(0===a.key.indexOf(this.prefix)&&null===a.newValue){var b=a.key.replace(this.prefix,"");!this.safariWorkaroundIgnoreSameTabEvents(a.key,JSON.parse(a.oldValue))&&b in this.queue&&(this.send(b,this.queue[b].shift()),0===this.queue[b].length&&delete this.queue[b])}}.bind(this))}c.prototype.on=function(a,b){a in this.callbacks||(this.callbacks[a]= []);this.callbacks[a].push(b)};c.prototype.off=function(a,b){if(a in this.callbacks){if("function"===typeof b){var d=this.callbacks[a].indexOf(b);this.callbacks[a].splice(d,1)}"function"===typeof b&&0!==this.callbacks[a].length||delete this.callbacks[a]}};c.prototype.send=function(a,b){this.storage&&(a=this.prefix+a,this.safariWorkaroundStoreOutgoingForTab(a,b),null===this.storage.getItem(a)?(this.storage.setItem(a,this.stringify(b)),this.storage.removeItem(a)):(a in this.queue||(this.queue[a]=[]), this.queue[a].push(b)))};c.prototype.broadcast=function(a,b){a in this.callbacks&&this.callbacks[a].forEach(function(d){d(b)})};c.prototype.stringify=function(a){return JSON.stringify(a,function(b,d){return void 0===d?null:d})};"none"!=e.getSafariType()?(c.prototype.safariWorkaroundStoreOutgoingForTab=function(a,b){a=this.stringify({key:a,data:b});this.postedEvents.add(a);this.postedEvents2.add(a)},c.prototype.safariWorkaroundIgnoreSameTabEvents=function(a,b){a=this.stringify({key:a,data:b});return this.postedEvents.delete(a)|| this.postedEvents2.delete(a)}):(c.prototype.safariWorkaroundStoreOutgoingForTab=function(a,b){},c.prototype.safariWorkaroundIgnoreSameTabEvents=function(a,b){return!1});e.broadcastAPI=new c});