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.1.0 to 1.2.0

iframe.html

2

package.json
{
"name": "sysend",
"version": "1.1.0",
"version": "1.2.0",
"description": "Send messages to other tabs/windows in the same origin and browser",

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

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

[![npm](https://img.shields.io/badge/npm-1.2.0-blue.svg)](https://www.npmjs.com/package/sysend)
![bower](https://img.shields.io/badge/bower-1.2.0-yellow.svg)
## sysend.js

@@ -5,9 +8,13 @@

open in the same browser. They need to be in same domain. The library don't use
any dependencies and use HTML5 LocalStorage API. You can send any object that
can be serialized to JSON or just send empty notification.
any dependencies and use HTML5 LocalStorage API or BroadcastChannel API.
If your browser don't support BroadcastChannel (see [Can I Use](https://caniuse.com/#feat=broadcastchannel))
then you can send any object that can be serialized to JSON with BroadcastChannel you can send any object
(it will not be serialized to string). You can also send empty notification.
Tested on:
GNU/Linux: in Chromium 34, FireFox 29, Opera 12.16 (64bit)<br/>
Windows 10 64bit: in IE11 and Edge 38
Windows 10 64bit: in IE11 and Edge 38, Chrome 56, Firefox 51<br/>
MacOS X El Captain: Safari 9, Chrome 56, Firefox 51

@@ -29,2 +36,5 @@ ## Instalation

you can also get it from [unpkg.com CDN](https://unpkg.com/sysend)
## Usage

@@ -49,3 +59,3 @@

The demo also use iframe proxy to send message to different domain
The demo also use iframe proxy to send message to different domain (on firefox you need to add CORS for the iframe see [Cross-Domain LocalStorage](https://jcubic.wordpress.com/2014/06/20/cross-domain-localstorage/))

@@ -62,3 +72,3 @@ ## API

Copyright (C) 2014 [Jakub Jankiewicz](http://jcubic.pl)<br/>
Copyright (C) 2014-2017 [Jakub Jankiewicz](http://jcubic.pl)<br/>
Released under the [MIT license](https://opensource.org/licenses/MIT)

@@ -65,0 +75,0 @@

/**@license
* sysend.js - send messages between browser windows/tabs
* Copyright (C) 2014 Jakub Jankiewicz <http://jcubic.pl>
* sysend.js - send messages between browser windows/tabs version 1.2.0
*
* Copyright (C) 2014-2018 Jakub Jankiewicz <http://jcubic.pl/me>
* Released under the MIT license
*
* The idea for this implementation came from this StackOverflow question:
* The idea for localStorage implementation came from this StackOverflow question:
* http://stackoverflow.com/q/24182409/387194
*
*/
/* global define, module, exports, localStorage, setTimeout */
(function (root, factory) {

@@ -62,27 +64,47 @@ if (typeof define === 'function' && define.amd) {

var callbacks = {};
window.addEventListener('storage', function(e) {
if (e.key.match(re)) {
var key = e.key.replace(re, '');
if (callbacks[key]) {
var value = e.newValue || get(key);
if (value != random_value) {
var obj = JSON.parse(value);
if (obj && obj[1] != random_value) {
// don't call on remove
callbacks[key].forEach(function(fn) {
fn(obj[2], key);
});
var index = 0;
var channel;
if (typeof window.BroadcastChannel === 'function') {
channel = new window.BroadcastChannel(uniq_prefix);
channel.addEventListener('message', function(event) {
if (event.target.name === uniq_prefix) {
var key = event.data && event.data.name;
if (callbacks[key]) {
callbacks[key].forEach(function(fn) {
fn(event.data.data, key);
});
}
}
});
} else {
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 = JSON.parse(value);
if (obj && obj[1] != random_value) {
// don't call on remove
callbacks[key].forEach(function(fn) {
fn(obj[2], key);
});
}
}
}
}
}
origin_page = false;
}, false);
}, false);
}
return {
broadcast: function(event, message) {
set(event, to_json(message));
// clean up localstorage
setTimeout(function() {
remove(event);
}, 0);
if (channel) {
channel.postMessage({name: event, data: message});
} else {
set(event, to_json(message));
// clean up localstorage
setTimeout(function() {
remove(event);
}, 0);
}
},

@@ -89,0 +111,0 @@ on: function(event, fn) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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