Comparing version 1.8.0 to 1.8.1
{ | ||
"name": "sysend", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"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.8.0-blue.svg)](https://www.npmjs.com/package/sysend) | ||
![bower](https://img.shields.io/badge/bower-1.8.0-yellow.svg) | ||
[![npm](https://img.shields.io/badge/npm-1.8.1-blue.svg)](https://www.npmjs.com/package/sysend) | ||
![bower](https://img.shields.io/badge/bower-1.8.1-yellow.svg) | ||
![downloads](https://img.shields.io/npm/dt/sysend.svg) | ||
@@ -121,2 +121,3 @@ [![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/sysend)](https://www.jsdelivr.com/package/npm/sysend) | ||
| `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. | 1.6.0 | | ||
| `untrack(event [,callback])` | remove sigle event listener all all listeners for a given event | event - any of the strings `'open'`, `'close'`, `'primary'`, `'secondary'`, or `'message'`. | 1.6.0 | | ||
| `isPrimary()` | function returns true if window is primary (first open or last that remain) | NA | 1.6.0 | | ||
@@ -123,0 +124,0 @@ |
/**@license | ||
* sysend.js - send messages between browser windows/tabs version 1.8.0 | ||
* sysend.js - send messages between browser windows/tabs version 1.8.1 | ||
* | ||
@@ -4,0 +4,0 @@ * Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jcubic.pl/me> |
/**@license | ||
* sysend.js - send messages between browser windows/tabs version 1.8.0 | ||
* sysend.js - send messages between browser windows/tabs version 1.8.1 | ||
* | ||
@@ -383,2 +383,8 @@ * Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jcubic.pl/me> | ||
// ------------------------------------------------------------------------- | ||
function become_primary() { | ||
primary = true; | ||
trigger(handlers.primary); | ||
sysend.emit('__primary__'); | ||
} | ||
// ------------------------------------------------------------------------- | ||
function init() { | ||
@@ -445,6 +451,5 @@ if (typeof window.BroadcastChannel === 'function') { | ||
sysend.track('visbility', function(visible) { | ||
console.log({visible, has_primary}); | ||
if (visible && !has_primary) { | ||
primary = true; | ||
trigger(handlers.primary); | ||
sysend.emit('__primary__'); | ||
become_primary(); | ||
} | ||
@@ -488,2 +493,7 @@ }); | ||
}; | ||
// we need to trigger primary when tab is in different window | ||
// and is not be hidden | ||
if (!document.hidden) { | ||
become_primary(); | ||
} | ||
trigger(handlers.close, payload); | ||
@@ -490,0 +500,0 @@ }); |
30275
555
132