A generic communication transporter(iframe/Broadcast/Web Worker/Service Worker/Browser Extension/WebRTC/Electron, etc.)


GitHub – unadlib/data-transport: A generic communication transporter(iframe/Broadcast/Web Worker/Service Worker/Browser Extension/WebRTC/Electron, etc.)






A generic communication transporter(iframe/Broadcast/Web Worker/Service Worker/Browser Extension/WebRTC/Electron, etc.)

Files

Permalink

Failed to load latest commit information.

Type

Name

Latest commit message

Commit time

Aug 26, 2020

Aug 27, 2020

Sep 10, 2020

Aug 29, 2020

Sep 10, 2020

Sep 10, 2020

Aug 26, 2020

Aug 26, 2020

Aug 26, 2020

Sep 5, 2020

Sep 5, 2020

Aug 26, 2020

Aug 24, 2020

Sep 10, 2020

Aug 29, 2020

Sep 10, 2020

Sep 9, 2020

Aug 29, 2020

Sep 8, 2020

Node CI
npm version

A generic communication transporter

Support Transport

  • iframe
  • Broadcast
  • Web Worker
  • Service Worker
  • Browser Extension
  • WebRTC
  • Electron

Usage

  • Installation
yarn add data-transport
  • Define type
type IFrame = {
  hello: TransportData<{ num: number }, { text: string }>;
};
  • Implement class
class InternalTransport extends IFrameTransport.IFrame<IFrame> {
  async sayHello() {
    const response = await this.emit('hello', { num: 42 });
    return response;
  }
}

class ExternalTransport extends IFrameTransport.Main implements Receiver<IFrame> {
  @listen
  hello({ request, respond }: Listen<IFrame['hello']>) {
    respond({
      text: `hello ${request.num}`,
    });
  }
}

const internal = new InternalTransport();
const external = new ExternalTransport();

expect(await internal.sayHello()).toEqual({ text: 'hello 42' });

TODO

Examples

Online about Broadcast

About

A generic communication transporter(iframe/Broadcast/Web Worker/Service Worker/Browser Extension/WebRTC/Electron, etc.)

Topics

Resources

License

No releases published

No packages published



You can’t perform that action at this time.

Author: admin

Leave a Reply

Your email address will not be published.