npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lopatnov/browser-tab-ipc

v1.2.1

Published

Inter-process communication mechanism between browser tabs. A bus network between browser tabs.

Downloads

11

Readme

@lopatnov/browser-tab-ipc Twitter LinkedIn

npm NPM version License GitHub issues GitHub forks GitHub stars GitHub top language

Build and Test package Publish NPM package Dependencies

With this client technology, you can exchange messages between browser tabs. This is a bus network among browser tabs, inter-process communication mechanism between browser tabs. This technology allows to create a chat between browser tabs. It allows create features to optimize the performance of high-demand applications, decrease amount of http requests or socket connections. It also allows synchronize changes in different browser tabs.

This technology supports two transport type connections. The messages can be transferred through a storage or through a JavaScript worker. Transport technology can be chosen automatically.

Install

https://nodei.co/npm/@lopatnov/browser-tab-ipc.png?downloads=true&downloadRank=true&stars=true

npm install @lopatnov/browser-tab-ipc

Browser

<script src="https://lopatnov.github.io/browser-tab-ipc/dist/library.min.js"></script>

<!-- Example: how to use in browser -->
<script>
  //...
  var BrowserTabIPC = browserTabIpc.BrowserTabIPC;
  ipc = new BrowserTabIPC();
  ipc.message(function (message) {
    console.log(message);
  });
  ipc
    .connect({
      sharedWorkerUri: '//lopatnov.github.io/browser-tab-ipc/dist/ipc-worker.js', // Please copy this file `dist/ipc-worker.js` to your project and replace this url
    })
    .then(function (state) {
      console.log(state);
    });
  var id = Math.trunc(Math.random() * 10000);
  setInterval(() => {
    ipc.postMessage('Hello browser Tab! I am page with ID: ' + id);
  }, 200);
  //...
</script>

Post Install

Copy ~/node_modules/@lopatnov/browser-tab-ipc/dist/ipc-worker.js file to your project to use Worker transport technology and avoid CORS issues. Provide the path to this file for Worker transport connection.

Import package to the project

TypeScript

import {BrowserTabIPC, TransportType, ConnectionState} from '@lopatnov/browser-tab-ipc';

JavaScript

var library = require('@lopatnov/browser-tab-ipc');
var BrowserTabIPC = library.BrowserTabIPC;
var TransportType = library.TransportType;
var ConnectionState = library.ConnectionState;

API

class BrowserTabIPC

Provides methods to connect/disconnect ipc technology using one of some possible transports and send a message through it.

This class extends from EventEmitter class and can use EventConnected, EventConnectionError, EventDisconnected, EventMessage events, however it's not obligatory.

import {EventConnected, EventConnectionError, EventDisconnected, EventMessage} from '@lopatnov/browser-tab-ipc';

ipc.on(EventConnected, (state) => {
  console.log('connected', state);
});

constructor(options?: ConnectionOptions)

Creates an instance of BrowserTabIPC class.

  • options?: ConnectionOptions Optional parameter options provides connection options to create a new instance.
const ipc = new BrowserTabIPC({
  transportTypes: [TransportType.sharedWorker, TransportType.sessionStorage],
});

connect(options?: ConnectionOptions): Promise<ConnectionState>

Connects BrowserTabIPC instance to a bus network among browser tabs using one of possible transport provided in constructor.

  • options?: ConnectionOptions Optional parameter options extends connection options to IPC instance.
    • transportTypes?: TransportType | TransportType[]; An enum value or array of enum TransportType. That's possible transports that IPC technology can use.
    • sharedWorkerUri?: string; Worker transport option. A link to IPC worker.
    • storageKey?: string; Storage transport option. A key, that IPC technology uses in local storage to identify IPC messages
    • storageExpiredTime?: number; Storage transport option. Timeout constant that technology uses to remove old messages

returns Promise<ConnectionState> a state of connection.

  • type: TransportType | null; Used transport type
  • connected: boolean; Is connected?
  • error?: any; An error

BrowserTabIPC also have defaultWorkerUri static variable, that uses when sharedWorkerUri option wasn't provided.

const state = await ipc.connect({
  sharedWorkerUri: '//lopatnov.github.io/browser-tab-ipc/dist/ipc-worker.js',
  storageKey: 'ipc',
  storageExpiredTime: 30000,
});

disconnect(): Promise<ConnectionState>

Disconnects BrowserTabIPC instance.

returns Promise<ConnectionState> a state of connection.

ipc.disconnect();

postMessage(message: any): Promise<void>

Sends a message of any serializable type.

ipc.postMessage('Hello browser Tab!');

connected(callback: Action1<ConnectionState>)

Adds a callback to EventConnected event.

ipc.connected(function (connectionState) {
  console.log('Connected. Current connection state is ', connectionState);
});

connectionError(callback: Action1<ConnectionState>)

Adds a callback to EventConnectionError event.

ipc.connectionError(function (connectionState) {
  console.log('Connection error. Current connection state is ', connectionState);
});

disconnected(callback: Action1<ConnectionState>)

Adds a callback to EventDisconnected event.

ipc.disconnected(function (connectionState) {
  console.log('Disconnected. Current connection state is ', connectionState);
});

message(callback: Action1<any>)

Adds a callback to EventMessage event.

ipc.message(function (message) {
  console.log('Received a message: ', message);
});

Troubleshooting

Module '"events"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

Edit tsconfig.json, set "allowSyntheticDefaultImports": true,

Donate

Charity Health LinkedIn Volunteer

Open source software is just a hobby. I am making it just for fun. A small amount of help will be more significant for charitable foundations. I propose to pay attention to the various local funds or to the volunteers in my country. I hope this will make someone's life better.

Rights and Agreements LinkedIn

Contact me in LinkedIn, I will consider profitable business offers. I am Computer Software Engineer, individual entrepreneur. I develop software of various complexity for the web, desktop, mobile and embedded devices. I have expertise in web development using .NET, Angular and React frameworks, Microsoft and Google technologies, working with the North American and European markets through reseller companies by B2B business model. I was a part of development teams and worked independently with enterprise projects, digital technologies, fintech projects, real estate, barcode software and petroleum industry. I would like to note that I have not bad analytical skills. I'm improving my skills continuously and I have recommendations.

License Apache-2.0

Copyright 2022 Oleksandr Lopatnov