-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (41 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
/* eslint-disable no-console */
const fs = require('fs');
const http = require('http');
const http2 = require('http2');
const Destination = require('./lib/Destination');
const createRequestListener = require('./lib/http');
const createStompRelay = require('./lib/slideshow');
const createMockPubSubRelay = require('./lib/pubsub');
/**
* This script sets up the destinations for the example, creates the HTTP
* server(s) and then a Stomp relay and example PubSub relay.
*
* All of these are connected together to provide the example environment.
*/
const stompRelay = { host: 'stomp.radiovis.api.bbci.co.uk', port: 61613 };
// create destinations
const destinations = [
new Destination('fm/ce1/c201/09710'),
new Destination(['fm/ce1/c202/08810', 'dab/ce1/ce15/c222/0']),
];
// setup HTTP servers
const requestListener = createRequestListener(destinations);
http.createServer(requestListener).listen(80);
console.log('HTTP/1 listening on port 80');
if (fs.existsSync('./cert.pem') && fs.existsSync('./key.pem')) {
const options = {
allowHTTP1: true,
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./key.pem'),
};
http2.createSecureServer(options, requestListener).listen(443);
console.log('HTTP/2 listening on port 443');
} else {
console.error('no cert/key pair found, launching HTTP/1.x support only');
}
// relay an existing Slideshow Stomp server to SSE
createStompRelay(stompRelay.host, stompRelay.port, destinations);
console.log(`Slideshow Stomp relay connected to ${stompRelay.host}:${stompRelay.port}`);
// forward received pub/sub payloads to SSE
createMockPubSubRelay(destinations);