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

sysend

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sysend - npm Package Compare versions

Comparing version 1.12.3 to 1.14.0

2

package.json
{
"name": "sysend",
"version": "1.12.3",
"version": "1.14.0",
"description": "Web application synchronization between different tabs",

@@ -5,0 +5,0 @@ "main": "sysend.js",

@@ -5,4 +5,4 @@ <p align="center">

[![npm](https://img.shields.io/badge/npm-1.12.3-blue.svg)](https://www.npmjs.com/package/sysend)
![bower](https://img.shields.io/badge/bower-1.12.3-yellow.svg)
[![npm](https://img.shields.io/badge/npm-1.14.0-blue.svg)](https://www.npmjs.com/package/sysend)
![bower](https://img.shields.io/badge/bower-1.14.0-yellow.svg)
![downloads](https://img.shields.io/npm/dt/sysend.svg)

@@ -124,3 +124,3 @@ [![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/sysend)](https://www.jsdelivr.com/package/npm/sysend)

| `emit(name, [, object])` | same as `broadcast()` but also invoke the even on same page | name - string - The name of the event<br>object - optional any data | 1.5.0 |
| `post(<window_id>, [, object])` | send any data to other window | window_id - string of the target window<br>object - any data | 1.6.0 |
| `post(<window_id>, [, object])` | send any data to other window | window_id - string of the target window (use `'primary'` to send to primary window)<br>object - any data | 1.6.0 / `'primary'` target 1.14.0 |
| `list()` | returns a Promise of objects `{id:<UUID>, primary}` for other windows, you can use those to send a message with `post()` | NA | 1.6.0 |

@@ -131,3 +131,5 @@ | `track(event, callback)` | track inter window communication events | event - any of the strings: `"open"`, `"close"`, `"primary"`, <br>`"secondary"`, `"message"`<br>callback - different function depend on the event:<br>* `"message"` - `{data, origin}` - where data is anything the `post()` sends, and origin is `id` of the sender.<br>* `"open"` - `{count, primary, id}` when new window/tab is opened<br>* `"close"` - `{count, primary, id, self}` when window/tab is closed<br>* `"primary"` and `"secondary"` function has no arguments and is called when window/tab become secondary or primary.<br>* `"ready"` - event when tracking is ready. | 1.6.0 except `ready` - 1.10.0 |

| `channel()` | function restrict cross domain communication to only allowed domains. You need to call this function on proxy iframe to limit number of domains (origins) that can listen and send events. | any number of origins (e.g. 'http://localhost:8080' or 'https://jcubic.github.io') you can also use valid URL. | 1.10.0 |
| `useLocalStorage([toggle])` | Function set or toggle localStorage mode. | argument is optional and can be `true` or `false`. | 1.14.0 |
To see details of using the API, see [demo.html source code](https://github.com/jcubic/sysend.js/blob/master/demo.html) or [TypeScript definition file](https://github.com/jcubic/sysend.js/blob/master/sysend.d.ts).

@@ -134,0 +136,0 @@

/**@license
* sysend.js - send messages between browser windows/tabs version 1.12.3
* sysend.js - send messages between browser windows/tabs version 1.14.0
*

@@ -4,0 +4,0 @@ * Copyright (C) 2014-2022 Jakub T. Jankiewicz <https://jcubic.pl/me>

/**@license
* sysend.js - send messages between browser windows/tabs version 1.12.3
* sysend.js - send messages between browser windows/tabs version 1.14.0
*

@@ -35,2 +35,3 @@ * Copyright (C) 2014-2022 Jakub T. Jankiewicz <https://jcubic.pl/me>

var primary = true;
var force_ls = false;
// we use id because storage event is not executed if message was not

@@ -43,3 +44,3 @@ // changed, and we want it if user send same object twice (before it will

// id of the window/tab
// id of the window/tabAnd two-way communication is tracked in
var target_id = generate_uuid();

@@ -66,3 +67,3 @@ var target_count = 1;

broadcast: function(event, data) {
if (channel) {
if (channel && !force_ls) {
channel.postMessage({name: event, data: serialize(data)});

@@ -205,3 +206,10 @@ } else {

return primary;
}
},
useLocalStorage: function(toggle) {
if (typeof toggle === 'boolean') {
force_ls = toggle;
} else {
force_ls = true;
}
},
};

@@ -376,2 +384,12 @@ // -------------------------------------------------------------------------

// -------------------------------------------------------------------------
var is_private_mode = (function is_private_mode() {
try {
localStorage.setItem(uniq_prefix, 1);
localStorage.removeItem(uniq_prefix);
return false;
} catch (e) {
return true;
}
})();
// -------------------------------------------------------------------------
function is_proxy_iframe() {

@@ -424,12 +442,2 @@ return is_iframe && proxy_mode;

// -------------------------------------------------------------------------
function is_private_mode() {
try {
localStorage.setItem(uniq_prefix, 1);
localStorage.removeItem(uniq_prefix);
return false;
} catch (e) {
return true;
}
}
// -------------------------------------------------------------------------
function init_visiblity() {

@@ -472,2 +480,28 @@ // ref: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

}
function setup_ls() {
// we need to clean up localStorage if broadcast called on unload
// because setTimeout will never fire, even setTimeout 0
var re = new RegExp('^' + uniq_prefix);
for(var key in localStorage) {
if (key.match(re)) {
localStorage.removeItem(key);
}
}
window.addEventListener('storage', function(e) {
// prevent event to be executed on remove in IE
if (e.key.match(re) && index++ % 2 === 0) {
var key = e.key.replace(re, '');
if (callbacks[key]) {
var value = e.newValue || get(key);
if (value && value != random_value) {
var obj = from_json(value);
// don't call on remove
if (obj && obj[1] != random_value) {
invoke(key, obj[2]);
}
}
}
}
}, false);
}
// -------------------------------------------------------------------------

@@ -496,32 +530,10 @@ function init() {

});
} else if (is_private_mode()) {
} else if (is_private_mode) {
warn('Your browser don\'t support localStorgage. ' +
'In Safari this is most of the time because ' +
'of "Private Browsing Mode"');
} else {
// we need to clean up localStorage if broadcast called on unload
// because setTimeout will never fire, even setTimeout 0
var re = new RegExp('^' + uniq_prefix);
for(var key in localStorage) {
if (key.match(re)) {
localStorage.removeItem(key);
}
}
window.addEventListener('storage', function(e) {
// prevent event to be executed on remove in IE
if (e.key.match(re) && index++ % 2 === 0) {
var key = e.key.replace(re, '');
if (callbacks[key]) {
var value = e.newValue || get(key);
if (value && value != random_value) {
var obj = from_json(value);
// don't call on remove
if (obj && obj[1] != random_value) {
invoke(key, obj[2]);
}
}
}
}
}, false);
}
if (!is_private_mode) {
setup_ls();
}

@@ -607,4 +619,6 @@ if (is_proxy_iframe()) {

sysend.on('__message__', function(data) {
if (data.target === target_id) {
if (data.target === 'primary' && primary) {
trigger(handlers.message, data);
} else if (data.target === target_id) {
trigger(handlers.message, data);
}

@@ -611,0 +625,0 @@ });

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc