1 | # Ionic Discover
|
2 |
|
3 | Simple UDP based protocol for service discovery implemented in pure JS. It is
|
4 | not mDNS or bonjour, but it tries to accomplish the same thing.
|
5 |
|
6 | ## Spec
|
7 |
|
8 | It uses a JSON based textual format:
|
9 |
|
10 | ```ts
|
11 | const 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 |
|
21 | return '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 | ```
|
37 | npm install @ionic/discover
|
38 | ```
|
39 |
|
40 | ## Usage
|
41 |
|
42 | ```ts
|
43 | import { Publisher } from '@ionic/discover';
|
44 |
|
45 | const namespace = 'your-service';
|
46 | const serviceName = 'Ionic thing!';
|
47 | const tcpPort = 8100;
|
48 | const service = new Publisher(namespace, serviceName, tcpPort);
|
49 |
|
50 | await service.start();
|
51 | ```
|