UNPKG

1.1 kBMarkdownView Raw
1# Ionic Discover
2
3Simple UDP based protocol for service discovery implemented in pure JS. It is
4not mDNS or bonjour, but it tries to accomplish the same thing.
5
6## Spec
7
8It uses a JSON based textual format:
9
10```ts
11const message = {
12 t: now,
13 id: 'unique',
14 name: this.name,
15 host: os.hostname(),
16 ip: iface.address,
17 port: number1,
18 commPort: number2
19};
20
21return 'ION_DP' + JSON.stringify(message);
22```
23
24| key | description
25|------------|-------------
26| `t` | unix timestamp in second
27| `id` | unique id for this session
28| `name` | name of the announced service
29| `host` | hostname of the machine announcing the service
30| `ip` | ipv4 address
31| `port` | tcp port of the announced service
32| `commPort` | optional websocket port of the communication server
33
34## Installation
35
36```
37npm install @ionic/discover
38```
39
40## Usage
41
42```ts
43import { Publisher } from '@ionic/discover';
44
45const namespace = 'your-service';
46const serviceName = 'Ionic thing!';
47const tcpPort = 8100;
48const service = new Publisher(namespace, serviceName, tcpPort);
49
50await service.start();
51```