https://github.com/thalesrc/hermes
Javascript messaging library
https://github.com/thalesrc/hermes
chrome chrome-extension extension hermes library messaging typescript
Last synced: about 1 year ago
JSON representation
Javascript messaging library
- Host: GitHub
- URL: https://github.com/thalesrc/hermes
- Owner: thalesrc
- License: mit
- Created: 2019-01-24T17:42:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-11-29T16:17:17.000Z (over 2 years ago)
- Last Synced: 2025-04-23T21:15:49.691Z (about 1 year ago)
- Topics: chrome, chrome-extension, extension, hermes, library, messaging, typescript
- Language: TypeScript
- Size: 88.9 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# hermes

[](https://www.npmjs.com/package/@thalesrc/hermes)
[](https://www.npmjs.com/package/@thalesrc/hermes)
[](https://codecov.io/gh/thalesrc/hermes)
[](https://www.typescriptlang.org/)
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
```typescript
// inside iframe
import { IframeMessageClient, Request } from '@thalesrc/hermes/iframe';
class MessageSenderService extends IframeMessageClient {
@Request('hello')
public sayHello(name: string): Observable {
return null;
}
}
const service = new MessageSenderService();
service.sayHello('John').subscribe(message => {
console.log(message);
});
// 'Hi John, here are some data for you'
// 'Thales Rocks!!'
```
```typescript
// 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 {
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.
```typescript
// content-script or a page etc.
import { ChromeMessageClient, Request } from '@thalesrc/hermes/chrome';
class MessageSenderService extends ChromeMessageClient {
@Request('hello')
public sayHello(name: string): Observable {
return null;
}
}
const service = new MessageSenderService();
service.sayHello('John').subscribe(message => {
console.log(message);
});
// 'Hi John, here are some data for you'
// 'Thales Rocks!!'
```
```typescript
// 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 {
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