6.1.1 • Published 5 months ago

@thalesrc/hermes v6.1.1

Weekly downloads
16
License
MIT
Repository
github
Last release
5 months ago

hermes

publish build npm npm codecov TypeScript

Javascript messaging library

Installation

npm i @thalesrc/hermes or yarn add @thalesrc/hermes

Usage

The main concept is sending messages via MessageClient's and answering them via MessageHost's.


Iframe

Send and recieve messages accross iframes and parent windows

// inside iframe
import { IframeMessageClient, Request } from '@thalesrc/hermes/iframe';

class MessageSenderService extends IframeMessageClient {
  @Request('hello')
  public sayHello(name: string): Observable<string> {
    return null;
  }
}

const service = new MessageSenderService();

service.sayHello('John').subscribe(message => {
  console.log(message);
});

// 'Hi John, here are some data for you'
// 'Thales Rocks!!'
// inside parent window
import { IframeMessageHost, Listen, UpcomingMessage } from '@thalesrc/hermes/iframe';
import { of } from 'rxjs';

class MessageListenerService extends IframeMessageHost {
  @Listen('hello')
  public listenHello({data, sender}: UpcomingMessage): Observable<string> {
    return of(
      'Hi ' + data + ', here is some data for you',
      'Thales Rocks!!'
    );
  }
}

const listener = new MessageListener();

Chrome Extensions

Send and recieve messages accross tabs, background-scripts, content-scripts etc.

// content-script or a page etc.
import { ChromeMessageClient, Request } from '@thalesrc/hermes/chrome';

class MessageSenderService extends ChromeMessageClient {
  @Request('hello')
  public sayHello(name: string): Observable<string> {
    return null;
  }
}

const service = new MessageSenderService();

service.sayHello('John').subscribe(message => {
  console.log(message);
});

// 'Hi John, here are some data for you'
// 'Thales Rocks!!'
// background-script etc.
import { ChromeMessageHost, Listen } from '@thalesrc/hermes/chrome';
import { of } from 'rxjs';

class MessageListenerService extends ChromeMessageHost {
  @Listen('hello')
  public listenHello(name: string): Observable<string> {
    return of(
      'Hi ' + name + ', here is some data for you',
      'Thales Rocks!!'
    );
  }
}

const listener = new MessageListener();

Workers

Implemented but not documented yet


Broadcast

Implemented but not documented yet

6.0.1

6 months ago

6.1.1

5 months ago

5.3.3

2 years ago

5.3.2

2 years ago

5.3.1

3 years ago

5.2.1-beta

3 years ago

5.3.0

3 years ago

5.2.1

3 years ago

5.2.0-beta

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.0.0

3 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.0

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.0.1

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.3.6

3 years ago

2.3.5

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.0

4 years ago

2.2.1

4 years ago

2.2.2

4 years ago

2.2.0

4 years ago

2.1.9

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.3

5 years ago