0.4.0 • Published 1 year ago

@musubi/broadcast-channel-link v0.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@musubi/broadcast-channel-link

Adapter for using Musubi in browser extension.

Documentation

Full documentation for musubi can be found here.

Installation

# npm
npm install @musubi/broadcast-channel-link

# Yarn
yarn add @musubi/broadcast-channel-link

Usage

// Service worker/shared worker script
import { createBroadcastChannelLink } from '@musubi/broadcast-channel-link';
import { MusubiReceiver } from '@musubi/core';
import { schema } from '../schema';

const channel = new BroadcastChannel('musubi');

async function main() {
  const link = createBroadcastChannelLink(channel);
  const receiver = new MusubiReceiver(schema, [
    link.receiver,
  ]);

  receiver.handleQuery('ping', async () => {
    return 'pong';
  });
}

main().catch(console.error);
// Inside your app
import { createBroadcastChannelLink } from '@musubi/broadcast-channel-link';
import { schema } from '../schema';

const channel = new BroadcastChannel('musubi');

const worker = new SharedWorker('worker.js');
// or if browser doesn't support SharedWorker
// const worker = new Worker('worker.js');

const link = createBroadcastChannelLink(channel);

// If you are using Worker, you can pass it into link instead of channel
// const link = createBroadcastChannelLink(worker);

const client = new MusubiClient(schema, [
  link.client,
]);

await client.query('ping') // 'pong'
0.3.0

1 year ago

0.4.0

1 year ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago