New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tabex

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tabex - npm Package Compare versions

Comparing version

to
1.1.0

support/demo_template/index.pug

7

CHANGELOG.md

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

1.1.0 / 2018-03-05
------------------
- Cleanup timers on router destroy, #16.
- Dev deps bump.
1.0.6 / 2017-03-02

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

13

dist/tabex.js

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

/*! tabex 1.0.6 https://github.com//nodeca/tabex @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.tabex = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*! tabex 1.1.0 https://github.com//nodeca/tabex @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.tabex = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
// Base client class

@@ -438,3 +438,5 @@ //

this.__check_master__();
Timer.setInterval(function () {
// Instell timers & remember those to cleanup in __destroy__()
this.__timer_cm__ = Timer.setInterval(function () {
self.__check_master__();

@@ -444,3 +446,3 @@ }, UPDATE_INTERVAL);

// Remove outdated lock records
Timer.setInterval(function () {
this.__timer_lc__ = Timer.setInterval(function () {
self.__locks_cleanup__();

@@ -690,3 +692,3 @@ }, 1000);

// Page unload handler. Remove tab data from store
// Page unload handler. Remove tab data from store & kill timers
//

@@ -700,2 +702,5 @@ Router.prototype.__destroy__ = function () {

Timer.clearInterval(this.__timer_cm__);
Timer.clearInterval(this.__timer_lc__);
this.__ls__.removeItem(this.__router_id_prefix__ + this.__node_id__);

@@ -702,0 +707,0 @@ this.__ls__.removeItem(this.__router_channels_prefix__ + this.__node_id__);

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

/*! tabex 1.0.6 https://github.com//nodeca/tabex @license MIT */
!function(_){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=_();else if("function"==typeof define&&define.amd)define([],_);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.tabex=_()}}(function(){return function _(e,t,i){function n(r,o){if(!t[r]){if(!e[r]){var a="function"==typeof require&&require;if(!o&&a)return a(r,!0);if(s)return s(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var h=t[r]={exports:{}};e[r][0].call(h.exports,function(_){var t=e[r][1][_];return n(t?t:_)},h,h.exports,_,e,t,i)}return t[r].exports}for(var s="function"==typeof require&&require,r=0;r<i.length;r++)n(i[r]);return n}({1:[function(_,e){"use strict";function t(_){var e=this;this.__filters_in__=[],this.__filters_out__=[],this.__subscriptions__=[],this.__node_id__=Math.floor(1e10*Math.random())+1,this.__last_message_cnt__=0,this.__ignore_list__={},this.__router__=_.router,this.__router__.onmessage(function(_,t){e.__onmessage__(_,t)}),this.__lock_handlers__={},this.filterOut(function(_,t,i){if("!sys.lock.request"===_){var n=t.data.fn,s=t.data.id;delete t.data.fn,e.__lock_handlers__[t.id]=function(){n(function(){e.emit("!sys.lock.release",{id:s})})}}i(_,t)}),this.filterIn(function(_,t,i){"!sys.lock.acquired"===_&&e.__lock_handlers__[t.data.request_id]&&(e.__lock_handlers__[t.data.request_id](),delete e.__lock_handlers__[t.data.request_id]),i(_,t)})}var i=_("./utils");t.prototype.emit=function(_,e,t){var n=this,s={id:this.__node_id__+"_"+this.__last_message_cnt__++,node_id:this.__node_id__,data:e};t||(this.__ignore_list__[s.id]=!0),i.asyncEach(this.__filters_out__,_,s,function(_,e){n.__router__.broadcast(_,e)})},t.prototype.on=function(_,e){return this.__subscriptions__.push({channel:_,handler:e}),this.emit("!sys.channels.add",{channel:_}),this},t.prototype.off=function(_,e){var t=this;this.__subscriptions__=this.__subscriptions__.reduce(function(i,n){return n.channel!==_||e&&e!==n.handler?(i.push(n),i):(t.emit("!sys.channels.remove",{channel:_}),i)},[])},t.prototype.lock=function(_,e,t){t||(t=e,e=5e3),this.emit("!sys.lock.request",{id:_,timeout:e,fn:t})},t.prototype.filterIn=function(_){return this.__filters_in__.push(_),this},t.prototype.filterOut=function(_){return this.__filters_out__.push(_),this},t.prototype.__onmessage__=function(_,e){var t=this;i.asyncEach(this.__filters_in__,_,e,function(_,e){t.__ignore_list__[e.id]||t.__subscriptions__.forEach(function(t){t.channel===_&&t.handler(e.data,_)})})},e.exports=t},{"./utils":7}],2:[function(_,e){"use strict";var t=_("./router"),i=_("./client"),n=_("./tunnel"),s={},r={_:{}};r._.Router=t,r._.Client=i,r._.Tunnel=n,r.client=function(_){_=_||{};var e,r=_.namespace||"tabex_default_";return _.iframe?e=new n.TunnelClient(_):(s[r]||(s[r]=new t({namespace:r})),e=s[r]),new i({router:e})},r.router=function(_){_=_||{};var e=_.namespace||"tabex_default_";return s[e]||(s[e]=new t({namespace:e})),new n.TunnelRouter({router:s[e],namespace:e,origin:_.origin}),s[e]},e.exports=r},{"./client":1,"./router":4,"./tunnel":6}],3:[function(_,e){"use strict";function t(){}var i,n={},s=function(){try{if(i=window.localStorage,!i)return!1;i.setItem("live_local_storage_is_writable_test",""),i.removeItem("live_local_storage_is_writable_test")}catch(_){return!1}return document.documentMode&&document.documentMode<9?!1:navigator.userAgent.match("CriOS")?!1:!0}();Object.defineProperty(t.prototype,"length",{get:function(){return s?i.length:Object.keys(n).length}}),t.prototype.getItem=function(_){return s?i.getItem(_):n.hasOwnProperty(_)?n[_]:null},t.prototype.setItem=function(_,e){s?i.setItem(_,e):n[_]=e},t.prototype.removeItem=function(_){s?i.removeItem(_):n[_]=null},t.prototype.key=function(_){return s?i.key(_):Object.keys(n)[_]},e.exports=t},{}],4:[function(_,e){"use strict";function t(_){var e=this;_=_||{},this.__namespace__=_.namespace||"tabex_default_",this.__node_id__=Math.floor(1e10*Math.random())+1,this.__last_message_cnt__=0,this.__handlers__=[],this.__router_channels__={},this.__router_id_prefix__=this.__namespace__+"router_",this.__router_channels_prefix__=this.__namespace__+"subscribed_",this.__lock_prefix__=this.__namespace__+"lock_",this.__storage_events_filter__=[];for(var t=0;100>t;t++)this.__storage_events_filter__.push("");this.__ls__=new n,this.__master_id__=null,s.addEvent(window,"storage",function(_){return null===_.key?void e.__check_master__():"onstoragecommit"in document?void setTimeout(function(){e.__on_changed__(_)},1):void e.__on_changed__(_)}),this.__destroyed__=!1,s.addEvent(window,"beforeunload",function(){e.__destroy__()}),s.addEvent(window,"unload",function(){e.__destroy__()}),this.__check_master__(),i.setInterval(function(){e.__check_master__()},o),i.setInterval(function(){e.__locks_cleanup__()},1e3)}var i=_("./timer"),n=_("./local_storage"),s=_("./utils"),r=4e3,o=r/4;t.prototype.broadcast=function(_,e){if("!sys.channels.add"===_)return this.__router_channels__[e.data.channel]=this.__router_channels__[e.data.channel]||0,this.__router_channels__[e.data.channel]++,void this.__update_channels_list__();if("!sys.channels.remove"===_)return this.__router_channels__[e.data.channel]=this.__router_channels__[e.data.channel]||0,this.__router_channels__[e.data.channel]--,void this.__update_channels_list__();if("!sys.lock.request"===_)return void this.__lock__(e.data.id,e.id,e.data.timeout);if("!sys.lock.release"===_)return void this.__ls__.removeItem(this.__lock_prefix__+e.data.id);var t=JSON.stringify({channel:_,message:e,random:Math.floor(1e10*Math.random())});this.__storage_events_filter__.shift(),this.__storage_events_filter__.push(this.__namespace__+"broadcast_"+t),this.__ls__.setItem(this.__namespace__+"broadcast",t),this.__handlers__.forEach(function(t){t(_,e)})},t.prototype.onmessage=function(_){var e=this;this.__handlers__.push(_),setTimeout(function(){_("!sys.master",{data:{node_id:e.__node_id__,master_id:e.__master_id__},node_id:e.__node_id__,id:e.__node_id__+"_"+e.__last_message_cnt__++}),e.__on_channels_list_changed__()},0)},t.prototype.__lock__=function(_,e,t){var i=this,n=this.__lock_prefix__+_,s=this.__ls__.getItem(n);if(s)try{s=JSON.parse(s)}catch(r){s=null}s&&s.expire>Date.now()||(this.__ls__.setItem(n,JSON.stringify({expire:t+Date.now(),requestId:e})),setTimeout(function(){if(s=i.__ls__.getItem(n))try{s=JSON.parse(s)}catch(_){s=null}s&&s.requestId===e&&i.__handlers__.forEach(function(_){_("!sys.lock.acquired",{data:{request_id:e},node_id:i.__node_id__,id:i.__node_id__+"_"+i.__last_message_cnt__++})})},30))},t.prototype.__locks_cleanup__=function(){for(var _,e,t=0;t<this.__ls__.length;t++)if(_=this.__ls__.key(t),0===_.indexOf(this.__lock_prefix__)){e=this.__ls__.getItem(_);try{e=JSON.parse(e)}catch(i){e=null}(!e||e.expire<Date.now())&&this.__ls__.removeItem(_)}},t.prototype.__on_master_changed__=function(_){var e=this;return _?(this.__master_id__=+_,this.__handlers__.forEach(function(_){_("!sys.master",{data:{node_id:e.__node_id__,master_id:e.__master_id__},node_id:e.__node_id__,id:e.__node_id__+"_"+e.__last_message_cnt__++})}),e.__update_channels_list__(!0),void e.__on_channels_list_changed__()):void(this.__get_alive_router_ids__().sort()[0]===this.__node_id__&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__namespace__+"master_"+this.__node_id__),this.__ls__.setItem(this.__namespace__+"master",this.__node_id__),this.__on_master_changed__(this.__node_id__)))},t.prototype.__on_changed__=function(_){if(-1===this.__storage_events_filter__.indexOf(_.key+"_"+_.newValue)&&(_.key===this.__namespace__+"master"&&this.__on_master_changed__(_.newValue),0===_.key.indexOf(this.__router_channels_prefix__)&&this.__on_channels_list_changed__(),_.key===this.__namespace__+"broadcast")){var e=JSON.parse(_.newValue);this.__handlers__.forEach(function(_){_(e.channel,e.message)})}},t.prototype.__destroy__=function(){this.__destroyed__||(this.__destroyed__=!0,this.__ls__.removeItem(this.__router_id_prefix__+this.__node_id__),this.__ls__.removeItem(this.__router_channels_prefix__+this.__node_id__),this.__master_id__===this.__node_id__&&this.__ls__.removeItem(this.__namespace__+"master"))},t.prototype.__get_alive_router_ids__=function(){for(var _,e,t=Date.now()-r,i=[],n=0;n<this.__ls__.length;n++)e=this.__ls__.key(n),0===e.indexOf(this.__router_id_prefix__)&&(_=+e.substr(this.__router_id_prefix__.length),this.__ls__.getItem(e)<t?(this.__ls__.removeItem(e),this.__ls__.removeItem(this.__router_channels_prefix__+_)):i.push(_));return i},t.prototype.__update_channels_list__=function(_){var e=this,t=[];Object.keys(this.__router_channels__).forEach(function(_){e.__router_channels__[_]>0&&t.push(_)});var i=JSON.stringify(t.sort());this.__ls__.getItem(this.__router_channels_prefix__+this.__node_id__)!==i&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__router_channels_prefix__+this.__node_id__+"_"+i),this.__ls__.setItem(this.__router_channels_prefix__+this.__node_id__,i),_||this.__on_channels_list_changed__())},t.prototype.__on_channels_list_changed__=function(){for(var _,e=this,t=[],i=0;i<this.__ls__.length;i++)_=this.__ls__.key(i),0===_.indexOf(this.__router_channels_prefix__)&&(t=t.concat(JSON.parse(this.__ls__.getItem(_))));t=t.reduce(function(_,e){return-1===_.indexOf(e)&&_.push(e),_},[]),this.__handlers__.forEach(function(_){_("!sys.channels.refresh",{id:e.__node_id__+"_"+e.__last_message_cnt__++,node_id:e.__node_id__,data:{channels:t}})})},t.prototype.__check_master__=function(){this.__ls__.setItem(this.__router_id_prefix__+this.__node_id__,Date.now()),this.__master_id__=+this.__ls__.getItem(this.__namespace__+"master"),-1===this.__get_alive_router_ids__().indexOf(this.__master_id__)&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__namespace__+"master_"+this.__node_id__),this.__ls__.setItem(this.__namespace__+"master",this.__node_id__),this.__on_master_changed__(this.__node_id__))},e.exports=t},{"./local_storage":3,"./timer":5,"./utils":7}],5:[function(_,e,t){"use strict";function i(_){var e={};_.onmessage=function(t){switch(t.data.type){case"ping":_.postMessage({type:"pong"});break;case"set_timeout":e[t.data.id]=setTimeout(function(){_.postMessage({type:"tick",id:t.data.id})},t.data.delay);break;case"clear_timeout":clearTimeout(e[t.data.id]);break;case"set_interval":e[t.data.id]=setInterval(function(){_.postMessage({type:"tick",id:t.data.id})},t.data.interval);break;case"clear_interval":clearInterval(e[t.data.id])}}}function n(_){var e=this;this.__ww__=_,this.__timer_handlers__={},this.__ww__.onmessage=function(_){"tick"===_.data.type&&e.__timer_handlers__[_.data.id]()}}function s(){this.__timers__={}}function r(_){function e(){r&&o.revokeObjectURL(r),l&&l.terminate(),t&&clearTimeout(t)}if(h)return void _(h);if(d.push(_),1===d.length){var t,r,l;try{r=o.createObjectURL(new a(["("+i.toString()+")(this)"],{type:"text/javascript"})),l=new c(r)}catch(u){return e(),h=new s,void d.forEach(function(_){_(h)})}l.onmessage=function(_){"pong"===_.data.type&&(clearInterval(t),h=new n(l),d.forEach(function(_){_(h)}))},t=setTimeout(function(){e(),h=new s,d.forEach(function(_){_(h)})},300),l.postMessage({type:"ping"})}}var o=window.URL,a=window.Blob,c=window.Worker;n.prototype.setTimeout=function(_,e,t){this.__timer_handlers__[_]=e,this.__ww__.postMessage({type:"set_timeout",delay:t,id:_})},n.prototype.clearTimeout=function(_){this.__ww__.postMessage({type:"clear_timeout",id:_}),delete this.__timer_handlers__[_]},n.prototype.setInterval=function(_,e,t){this.__timer_handlers__[_]=e,this.__ww__.postMessage({type:"set_interval",interval:t,id:_})},n.prototype.clearInterval=function(_){this.__ww__.postMessage({type:"clear_interval",id:_}),delete this.__timer_handlers__[_]},s.prototype.setTimeout=function(_,e,t){this.__timers__[_]=setTimeout(e,t)},s.prototype.clearTimeout=function(_){clearInterval(this.__timers__[_])},s.prototype.setInterval=function(_,e,t){this.__timers__[_]=setInterval(e,t)},s.prototype.clearInterval=function(_){clearInterval(this.__timers__[_])};var h=null,d=[],l=1;t.setTimeout=function(_,e){var t=l++;return r(function(i){i.setTimeout(t,_,e)}),t},t.clearTimeout=function(_){r(function(e){e.clearTimeout(_)})},t.setInterval=function(_,e){var t=l++;return r(function(i){i.setInterval(t,_,e)}),t},t.clearInterval=function(_){r(function(e){e.clearInterval(_)})}},{}],6:[function(_,e,t){"use strict";function i(_){var e=this;this.__namespace__=_.namespace||"tabex_default_",this.__handlers__=[],this.__iframe_url__=_.iframe,this.__iframe_done__=!1,this.__pending__=[],this.__iframe__=document.createElement("iframe"),this.__iframe__.style.left="-1000px",this.__iframe__.style.position="absolute",this.__iframe__.onload=function(){e.__iframe__.contentWindow.postMessage(JSON.stringify({origin:window.location.origin||window.location.protocol+"//"+window.location.host,namespace:e.__namespace__}),e.__iframe_url__),e.__iframe_done__=!0,e.__pending__.forEach(function(_){e.__iframe__.contentWindow.postMessage(JSON.stringify(_),e.__iframe_url__)}),e.__pending__=null},s.addEvent(window,"message",function(_){if(0===e.__iframe_url__.indexOf(_.origin)){var t;try{t=JSON.parse(_.data)}catch(i){return}t.namespace===e.__namespace__&&e.__handlers__.forEach(function(_){_(t.channel,t.message)})}}),this.__iframe__.src=this.__iframe_url__;var t=function(){document.body.appendChild(e.__iframe__)};"loading"===document.readyState?s.addEvent(document,"DOMContentLoaded",t):t()}function n(_){var e,t=this;for(this.__namespace__=_.namespace||"tabex_default_",this.__origin_first_check__=_.origin||window.location.origin||window.location.protocol+"//"+window.location.host,Array.isArray(this.__origin_first_check__)||(this.__origin_first_check__=[this.__origin_first_check__]),e=0;e<this.__origin_first_check__.length;e++)this.__origin_first_check__[e]=this.__origin_first_check__[e].replace(/[-\/\\^$+?.()|[\]{}]/g,"\\$&"),this.__origin_first_check__[e]=this.__origin_first_check__[e].replace(/[*]/g,".+?"),this.__origin_first_check__[e]=new RegExp(this.__origin_first_check__[e]);this.__origin__=null,this.__router__=_.router,s.addEvent(window,"message",function(_){var i=!1;if(!t.__origin__||t.__origin__!==_.origin){for(e=0;e<t.__origin_first_check__.length;e++)if(t.__origin_first_check__[e].test(_.origin)){i=!0;break}if(!i)return}var n;try{n=JSON.parse(_.data)}catch(s){return}if(n.namespace===t.__namespace__)return!t.__origin__&&n.origin?(t.__origin__=n.origin,void t.__router__.onmessage(function(_,e){window.parent.postMessage(JSON.stringify({channel:_,message:e,namespace:t.__namespace__}),t.__origin__)})):void t.__router__.broadcast(n.channel,n.message)})}var s=_("./utils");i.prototype.broadcast=function(_,e){this.__iframe_done__?this.__iframe__.contentWindow.postMessage(JSON.stringify({channel:_,message:e,namespace:this.__namespace__}),this.__iframe_url__):this.__pending__.push({channel:_,message:e,namespace:this.__namespace__})},i.prototype.onmessage=function(_){this.__handlers__.push(_)},t.TunnelClient=i,t.TunnelRouter=n},{"./utils":7}],7:[function(_,e,t){"use strict";t.asyncEach=function(_){function e(){if(0===_.length)return void t.apply(this,arguments);var i=_.shift();i.apply(this,Array.prototype.slice.call(arguments,0).concat(e))}_=_.slice(0);var t=arguments[arguments.length-1],i=Array.prototype.slice.call(arguments,1);i.pop(),e.apply(this,i)},t.addEvent=function(_,e,t){return document.addEventListener?void _.addEventListener(e,t):void _.attachEvent("on"+e,t)}},{}],8:[function(_,e){"use strict";e.exports=_("./lib")},{"./lib":2}]},{},[8])(8)});
!function(_){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=_();else if("function"==typeof define&&define.amd)define([],_);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tabex=_()}}(function(){return function s(r,a,o){function c(t,_){if(!a[t]){if(!r[t]){var e="function"==typeof require&&require;if(!_&&e)return e(t,!0);if(h)return h(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=a[t]={exports:{}};r[t][0].call(n.exports,function(_){var e=r[t][1][_];return c(e||_)},n,n.exports,s,r,a,o)}return a[t].exports}for(var h="function"==typeof require&&require,_=0;_<o.length;_++)c(o[_]);return c}({1:[function(_,e,t){"use strict";var s=_("./utils");function i(_){var s=this;this.__filters_in__=[],this.__filters_out__=[],this.__subscriptions__=[],this.__node_id__=Math.floor(1e10*Math.random())+1,this.__last_message_cnt__=0,this.__ignore_list__={},this.__router__=_.router,this.__router__.onmessage(function(_,e){s.__onmessage__(_,e)}),this.__lock_handlers__={},this.filterOut(function(_,e,t){if("!sys.lock.request"===_){var i=e.data.fn,n=e.data.id;delete e.data.fn,s.__lock_handlers__[e.id]=function(){i(function(){s.emit("!sys.lock.release",{id:n})})}}t(_,e)}),this.filterIn(function(_,e,t){"!sys.lock.acquired"===_&&s.__lock_handlers__[e.data.request_id]&&(s.__lock_handlers__[e.data.request_id](),delete s.__lock_handlers__[e.data.request_id]),t(_,e)})}i.prototype.emit=function(_,e,t){var i=this,n={id:this.__node_id__+"_"+this.__last_message_cnt__++,node_id:this.__node_id__,data:e};t||(this.__ignore_list__[n.id]=!0),s.asyncEach(this.__filters_out__,_,n,function(_,e){i.__router__.broadcast(_,e)})},i.prototype.on=function(_,e){return this.__subscriptions__.push({channel:_,handler:e}),this.emit("!sys.channels.add",{channel:_}),this},i.prototype.off=function(t,i){var n=this;this.__subscriptions__=this.__subscriptions__.reduce(function(_,e){return e.channel!==t||i&&i!==e.handler?_.push(e):n.emit("!sys.channels.remove",{channel:t}),_},[])},i.prototype.lock=function(_,e,t){t||(t=e,e=5e3),this.emit("!sys.lock.request",{id:_,timeout:e,fn:t})},i.prototype.filterIn=function(_){return this.__filters_in__.push(_),this},i.prototype.filterOut=function(_){return this.__filters_out__.push(_),this},i.prototype.__onmessage__=function(_,e){var i=this;s.asyncEach(this.__filters_in__,_,e,function(e,t){i.__ignore_list__[t.id]||i.__subscriptions__.forEach(function(_){_.channel===e&&_.handler(t.data,e)})})},e.exports=i},{"./utils":7}],2:[function(_,e,t){"use strict";var i=_("./router"),n=_("./client"),s=_("./tunnel"),r={},a={_:{}};a._.Router=i,a._.Client=n,a._.Tunnel=s,a.client=function(_){var e,t=(_=_||{}).namespace||"tabex_default_";return _.iframe?e=new s.TunnelClient(_):(r[t]||(r[t]=new i({namespace:t})),e=r[t]),new n({router:e})},a.router=function(_){var e=(_=_||{}).namespace||"tabex_default_";return r[e]||(r[e]=new i({namespace:e})),new s.TunnelRouter({router:r[e],namespace:e,origin:_.origin}),r[e]},e.exports=a},{"./client":1,"./router":4,"./tunnel":6}],3:[function(_,e,t){"use strict";var i,n={},s=function(){try{if(!(i=window.localStorage))return!1;i.setItem("live_local_storage_is_writable_test",""),i.removeItem("live_local_storage_is_writable_test")}catch(_){return!1}return!(document.documentMode&&document.documentMode<9)&&!navigator.userAgent.match("CriOS")}();function r(){}Object.defineProperty(r.prototype,"length",{get:function(){return s?i.length:Object.keys(n).length}}),r.prototype.getItem=function(_){return s?i.getItem(_):n.hasOwnProperty(_)?n[_]:null},r.prototype.setItem=function(_,e){s?i.setItem(_,e):n[_]=e},r.prototype.removeItem=function(_){s?i.removeItem(_):n[_]=null},r.prototype.key=function(_){return s?i.key(_):Object.keys(n)[_]},e.exports=r},{}],4:[function(_,e,t){"use strict";var i=_("./timer"),n=_("./local_storage"),s=_("./utils"),r=1e3;function a(_){var e=this;_=_||{},this.__namespace__=_.namespace||"tabex_default_",this.__node_id__=Math.floor(1e10*Math.random())+1,this.__last_message_cnt__=0,this.__handlers__=[],this.__router_channels__={},this.__router_id_prefix__=this.__namespace__+"router_",this.__router_channels_prefix__=this.__namespace__+"subscribed_",this.__lock_prefix__=this.__namespace__+"lock_",this.__storage_events_filter__=[];for(var t=0;t<100;t++)this.__storage_events_filter__.push("");this.__ls__=new n,this.__master_id__=null,s.addEvent(window,"storage",function(_){null!==_.key?"onstoragecommit"in document?setTimeout(function(){e.__on_changed__(_)},1):e.__on_changed__(_):e.__check_master__()}),this.__destroyed__=!1,s.addEvent(window,"beforeunload",function(){e.__destroy__()}),s.addEvent(window,"unload",function(){e.__destroy__()}),this.__check_master__(),this.__timer_cm__=i.setInterval(function(){e.__check_master__()},r),this.__timer_lc__=i.setInterval(function(){e.__locks_cleanup__()},1e3)}a.prototype.broadcast=function(e,t){if("!sys.channels.add"===e)return this.__router_channels__[t.data.channel]=this.__router_channels__[t.data.channel]||0,this.__router_channels__[t.data.channel]++,void this.__update_channels_list__();if("!sys.channels.remove"===e)return this.__router_channels__[t.data.channel]=this.__router_channels__[t.data.channel]||0,this.__router_channels__[t.data.channel]--,void this.__update_channels_list__();if("!sys.lock.request"!==e)if("!sys.lock.release"!==e){var _=JSON.stringify({channel:e,message:t,random:Math.floor(1e10*Math.random())});this.__storage_events_filter__.shift(),this.__storage_events_filter__.push(this.__namespace__+"broadcast_"+_),this.__ls__.setItem(this.__namespace__+"broadcast",_),this.__handlers__.forEach(function(_){_(e,t)})}else this.__ls__.removeItem(this.__lock_prefix__+t.data.id);else this.__lock__(t.data.id,t.id,t.data.timeout)},a.prototype.onmessage=function(_){var e=this;this.__handlers__.push(_),setTimeout(function(){_("!sys.master",{data:{node_id:e.__node_id__,master_id:e.__master_id__},node_id:e.__node_id__,id:e.__node_id__+"_"+e.__last_message_cnt__++}),e.__on_channels_list_changed__()},0)},a.prototype.__lock__=function(_,e,t){var i=this,n=this.__lock_prefix__+_,s=this.__ls__.getItem(n);if(s)try{s=JSON.parse(s)}catch(_){s=null}s&&s.expire>Date.now()||(this.__ls__.setItem(n,JSON.stringify({expire:t+Date.now(),requestId:e})),setTimeout(function(){if(s=i.__ls__.getItem(n))try{s=JSON.parse(s)}catch(_){s=null}s&&s.requestId===e&&i.__handlers__.forEach(function(_){_("!sys.lock.acquired",{data:{request_id:e},node_id:i.__node_id__,id:i.__node_id__+"_"+i.__last_message_cnt__++})})},30))},a.prototype.__locks_cleanup__=function(){for(var _,e,t=0;t<this.__ls__.length;t++)if(0===(_=this.__ls__.key(t)).indexOf(this.__lock_prefix__)){e=this.__ls__.getItem(_);try{e=JSON.parse(e)}catch(_){e=null}(!e||e.expire<Date.now())&&this.__ls__.removeItem(_)}},a.prototype.__on_master_changed__=function(_){var e=this;_?(this.__master_id__=+_,this.__handlers__.forEach(function(_){_("!sys.master",{data:{node_id:e.__node_id__,master_id:e.__master_id__},node_id:e.__node_id__,id:e.__node_id__+"_"+e.__last_message_cnt__++})}),e.__update_channels_list__(!0),e.__on_channels_list_changed__()):this.__get_alive_router_ids__().sort()[0]===this.__node_id__&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__namespace__+"master_"+this.__node_id__),this.__ls__.setItem(this.__namespace__+"master",this.__node_id__),this.__on_master_changed__(this.__node_id__))},a.prototype.__on_changed__=function(_){if(-1===this.__storage_events_filter__.indexOf(_.key+"_"+_.newValue)&&(_.key===this.__namespace__+"master"&&this.__on_master_changed__(_.newValue),0===_.key.indexOf(this.__router_channels_prefix__)&&this.__on_channels_list_changed__(),_.key===this.__namespace__+"broadcast")){var e=JSON.parse(_.newValue);this.__handlers__.forEach(function(_){_(e.channel,e.message)})}},a.prototype.__destroy__=function(){this.__destroyed__||(this.__destroyed__=!0,i.clearInterval(this.__timer_cm__),i.clearInterval(this.__timer_lc__),this.__ls__.removeItem(this.__router_id_prefix__+this.__node_id__),this.__ls__.removeItem(this.__router_channels_prefix__+this.__node_id__),this.__master_id__===this.__node_id__&&this.__ls__.removeItem(this.__namespace__+"master"))},a.prototype.__get_alive_router_ids__=function(){for(var _,e,t=Date.now()-4e3,i=[],n=0;n<this.__ls__.length;n++)0===(e=this.__ls__.key(n)).indexOf(this.__router_id_prefix__)&&(_=+e.substr(this.__router_id_prefix__.length),this.__ls__.getItem(e)<t?(this.__ls__.removeItem(e),this.__ls__.removeItem(this.__router_channels_prefix__+_)):i.push(_));return i},a.prototype.__update_channels_list__=function(_){var e=this,t=[];Object.keys(this.__router_channels__).forEach(function(_){0<e.__router_channels__[_]&&t.push(_)});var i=JSON.stringify(t.sort());this.__ls__.getItem(this.__router_channels_prefix__+this.__node_id__)!==i&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__router_channels_prefix__+this.__node_id__+"_"+i),this.__ls__.setItem(this.__router_channels_prefix__+this.__node_id__,i),_||this.__on_channels_list_changed__())},a.prototype.__on_channels_list_changed__=function(){for(var _,e=this,t=[],i=0;i<this.__ls__.length;i++)0===(_=this.__ls__.key(i)).indexOf(this.__router_channels_prefix__)&&(t=t.concat(JSON.parse(this.__ls__.getItem(_))));t=t.reduce(function(_,e){return-1===_.indexOf(e)&&_.push(e),_},[]),this.__handlers__.forEach(function(_){_("!sys.channels.refresh",{id:e.__node_id__+"_"+e.__last_message_cnt__++,node_id:e.__node_id__,data:{channels:t}})})},a.prototype.__check_master__=function(){this.__ls__.setItem(this.__router_id_prefix__+this.__node_id__,Date.now()),this.__master_id__=+this.__ls__.getItem(this.__namespace__+"master"),-1===this.__get_alive_router_ids__().indexOf(this.__master_id__)&&(this.__storage_events_filter__.pop(),this.__storage_events_filter__.push(this.__namespace__+"master_"+this.__node_id__),this.__ls__.setItem(this.__namespace__+"master",this.__node_id__),this.__on_master_changed__(this.__node_id__))},e.exports=a},{"./local_storage":3,"./timer":5,"./utils":7}],5:[function(_,e,t){"use strict";var s=window.URL,r=window.Blob,a=window.Worker;function o(_){var e=this;this.__ww__=_,this.__timer_handlers__={},this.__ww__.onmessage=function(_){"tick"===_.data.type&&e.__timer_handlers__[_.data.id]()}}function c(){this.__timers__={}}o.prototype.setTimeout=function(_,e,t){this.__timer_handlers__[_]=e,this.__ww__.postMessage({type:"set_timeout",delay:t,id:_})},o.prototype.clearTimeout=function(_){this.__ww__.postMessage({type:"clear_timeout",id:_}),delete this.__timer_handlers__[_]},o.prototype.setInterval=function(_,e,t){this.__timer_handlers__[_]=e,this.__ww__.postMessage({type:"set_interval",interval:t,id:_})},o.prototype.clearInterval=function(_){this.__ww__.postMessage({type:"clear_interval",id:_}),delete this.__timer_handlers__[_]},c.prototype.setTimeout=function(_,e,t){this.__timers__[_]=setTimeout(e,t)},c.prototype.clearTimeout=function(_){clearInterval(this.__timers__[_])},c.prototype.setInterval=function(_,e,t){this.__timers__[_]=setInterval(e,t)},c.prototype.clearInterval=function(_){clearInterval(this.__timers__[_])};var h=null,l=[];function n(_){if(h)_(h);else if(l.push(_),1===l.length){var e,t,i;try{t=s.createObjectURL(new r(["("+function(e){var t={};e.onmessage=function(_){switch(_.data.type){case"ping":e.postMessage({type:"pong"});break;case"set_timeout":t[_.data.id]=setTimeout(function(){e.postMessage({type:"tick",id:_.data.id})},_.data.delay);break;case"clear_timeout":clearTimeout(t[_.data.id]);break;case"set_interval":t[_.data.id]=setInterval(function(){e.postMessage({type:"tick",id:_.data.id})},_.data.interval);break;case"clear_interval":clearInterval(t[_.data.id])}}}.toString()+")(this)"],{type:"text/javascript"})),i=new a(t)}catch(_){return n(),h=new c,void l.forEach(function(_){_(h)})}i.onmessage=function(_){"pong"===_.data.type&&(clearInterval(e),h=new o(i),l.forEach(function(_){_(h)}))},e=setTimeout(function(){n(),h=new c,l.forEach(function(_){_(h)})},300),i.postMessage({type:"ping"})}function n(){t&&s.revokeObjectURL(t),i&&i.terminate(),e&&clearTimeout(e)}}var d=1;t.setTimeout=function(e,t){var i=d++;return n(function(_){_.setTimeout(i,e,t)}),i},t.clearTimeout=function(e){n(function(_){_.clearTimeout(e)})},t.setInterval=function(e,t){var i=d++;return n(function(_){_.setInterval(i,e,t)}),i},t.clearInterval=function(e){n(function(_){_.clearInterval(e)})}},{}],6:[function(_,e,t){"use strict";var s=_("./utils");function i(_){var t=this;this.__namespace__=_.namespace||"tabex_default_",this.__handlers__=[],this.__iframe_url__=_.iframe,this.__iframe_done__=!1,this.__pending__=[],this.__iframe__=document.createElement("iframe"),this.__iframe__.style.left="-1000px",this.__iframe__.style.position="absolute",this.__iframe__.onload=function(){t.__iframe__.contentWindow.postMessage(JSON.stringify({origin:window.location.origin||window.location.protocol+"//"+window.location.host,namespace:t.__namespace__}),t.__iframe_url__),t.__iframe_done__=!0,t.__pending__.forEach(function(_){t.__iframe__.contentWindow.postMessage(JSON.stringify(_),t.__iframe_url__)}),t.__pending__=null},s.addEvent(window,"message",function(_){if(0===t.__iframe_url__.indexOf(_.origin)){var e;try{e=JSON.parse(_.data)}catch(_){return}e.namespace===t.__namespace__&&t.__handlers__.forEach(function(_){_(e.channel,e.message)})}}),this.__iframe__.src=this.__iframe_url__;var e=function(){document.body.appendChild(t.__iframe__)};"loading"===document.readyState?s.addEvent(document,"DOMContentLoaded",e):e()}i.prototype.broadcast=function(_,e){this.__iframe_done__?this.__iframe__.contentWindow.postMessage(JSON.stringify({channel:_,message:e,namespace:this.__namespace__}),this.__iframe_url__):this.__pending__.push({channel:_,message:e,namespace:this.__namespace__})},i.prototype.onmessage=function(_){this.__handlers__.push(_)},t.TunnelClient=i,t.TunnelRouter=function(_){var i,n=this;for(this.__namespace__=_.namespace||"tabex_default_",this.__origin_first_check__=_.origin||window.location.origin||window.location.protocol+"//"+window.location.host,Array.isArray(this.__origin_first_check__)||(this.__origin_first_check__=[this.__origin_first_check__]),i=0;i<this.__origin_first_check__.length;i++)this.__origin_first_check__[i]=this.__origin_first_check__[i].replace(/[-\/\\^$+?.()|[\]{}]/g,"\\$&"),this.__origin_first_check__[i]=this.__origin_first_check__[i].replace(/[*]/g,".+?"),this.__origin_first_check__[i]=new RegExp(this.__origin_first_check__[i]);this.__origin__=null,this.__router__=_.router,s.addEvent(window,"message",function(_){var e,t=!1;if(!n.__origin__||n.__origin__!==_.origin){for(i=0;i<n.__origin_first_check__.length;i++)if(n.__origin_first_check__[i].test(_.origin)){t=!0;break}if(!t)return}try{e=JSON.parse(_.data)}catch(_){return}if(e.namespace===n.__namespace__)return!n.__origin__&&e.origin?(n.__origin__=e.origin,void n.__router__.onmessage(function(_,e){window.parent.postMessage(JSON.stringify({channel:_,message:e,namespace:n.__namespace__}),n.__origin__)})):void n.__router__.broadcast(e.channel,e.message)})}},{"./utils":7}],7:[function(_,e,t){"use strict";t.asyncEach=function(e){e=e.slice(0);var t=arguments[arguments.length-1],_=Array.prototype.slice.call(arguments,1);_.pop(),function _(){0!==e.length?e.shift().apply(this,Array.prototype.slice.call(arguments,0).concat(_)):t.apply(this,arguments)}.apply(this,_)},t.addEvent=function(_,e,t){document.addEventListener?_.addEventListener(e,t):_.attachEvent("on"+e,t)}},{}],8:[function(_,e,t){"use strict";e.exports=_("./lib")},{"./lib":2}]},{},[8])(8)});

@@ -86,3 +86,5 @@ // LocalStorage router

this.__check_master__();
Timer.setInterval(function () {
// Instell timers & remember those to cleanup in __destroy__()
this.__timer_cm__ = Timer.setInterval(function () {
self.__check_master__();

@@ -92,3 +94,3 @@ }, UPDATE_INTERVAL);

// Remove outdated lock records
Timer.setInterval(function () {
this.__timer_lc__ = Timer.setInterval(function () {
self.__locks_cleanup__();

@@ -338,3 +340,3 @@ }, 1000);

// Page unload handler. Remove tab data from store
// Page unload handler. Remove tab data from store & kill timers
//

@@ -348,2 +350,5 @@ Router.prototype.__destroy__ = function () {

Timer.clearInterval(this.__timer_cm__);
Timer.clearInterval(this.__timer_lc__);
this.__ls__.removeItem(this.__router_id_prefix__ + this.__node_id__);

@@ -350,0 +355,0 @@ this.__ls__.removeItem(this.__router_channels_prefix__ + this.__node_id__);

{
"name": "tabex",
"version": "1.0.6",
"version": "1.1.0",
"description": "Cross-tab message bus for browsers.",

@@ -21,4 +21,4 @@ "keywords": [

"devDependencies": {
"browserify": "^10.2.1",
"uglifyjs": "^2.4.10",
"autoprefixer-stylus": "^0.14.0",
"browserify": "^16.1.0",
"chai": "^2.3.0",

@@ -30,6 +30,6 @@ "eslint": "0.18.0",

"phantomjs": "^1.9.17",
"autoprefixer-stylus": "^0.7.0",
"jade": "^1.10.0",
"stylus": "^0.51.1"
"pug-cli": "^1.0.0-alpha6",
"stylus": "^0.54.5",
"uglify-js": "^3.3.13"
}
}

@@ -238,3 +238,3 @@ tabex

We also do "transparent" subscribe to faye channels when user subscribes with
tabex client. Since user can wish to do local broacasts too, strict separation
tabex client. Since user can wish to do local broadcasts too, strict separation
required for "local" and "remote". We do it with addind "remote.*" prefix for

@@ -241,0 +241,0 @@ channels which require server subscribtions.