https://github.com/mat-sz/tabcast
⚡️ TypeScript message passing (broadcasting) across multiple tabs of same origin.
https://github.com/mat-sz/tabcast
browser javascript-library message-passing typescript-library
Last synced: about 1 year ago
JSON representation
⚡️ TypeScript message passing (broadcasting) across multiple tabs of same origin.
- Host: GitHub
- URL: https://github.com/mat-sz/tabcast
- Owner: mat-sz
- License: bsd-3-clause-clear
- Created: 2020-08-19T16:12:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-18T17:12:56.000Z (over 4 years ago)
- Last Synced: 2024-04-25T18:43:14.816Z (about 2 years ago)
- Topics: browser, javascript-library, message-passing, typescript-library
- Language: TypeScript
- Homepage:
- Size: 81.1 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
tabcast
TypeScript message passing (broadcasting) across multiple tabs of same origin.
## Installation
Tabcast is available on [npm](https://www.npmjs.com/package/tabcast), you can install it with either npm or yarn:
```sh
npm install tabcast
# or:
yarn install tabcast
```
## Example usage
```ts
import Tabcast from 'tabcast';
const cast = new Tabcast(); // or new Tabcast('channel');
cast.on('message', (message: any) => {
console.log(message);
});
cast.broadcast('Hello, world!');
```
## Events
## message
Emitted when a valid message is received.
The only argument contains an object of type T with a deserialized message.
## API
```
on(eventType: 'message', listener: (message: T) => void);
off(eventType: 'message', listener: (message: T) => void);
constructor(private channel: string);
broadcast(message: T);
```