-
Notifications
You must be signed in to change notification settings - Fork 2
/
upnp.js
50 lines (40 loc) · 1.25 KB
/
upnp.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
'use strict';
const ssdp = require('@achingbrain/ssdp');
const winston = require('winston');
const ServerUsn = 'urn:schemas-upnp-org:device:SmartThingsSmarterCoffee:1';
class Upnp
{
constructor() {
this.started = false;
this.bus = ssdp();
this.bus.on('error', err => {
winston.error(err);
});
}
start() {
if (this.started) return;
this.bus.advertise({
usn: ServerUsn,
details: {
device: {
friendlyName: 'SmartThingsSmarterCoffee server',
manufacturer: 'Peter Major',
manufacturerURL: 'https://github.com/petermajor/SmartThingsSmarterCoffee',
modelDescription: '',
modelName: 'SmartThingsSmarterCoffee',
modelURL: 'https://github.com/petermajor/SmartThingsSmarterCoffee',
serialNumber: '1'
}
}
});
this.started = true;
winston.info('Started SSDP server for %s', ServerUsn);
}
stop() {
if (!this.started) return;
this.bus.stop();
this.started = false;
winston.info('Stopped SSDP server');
}
}
module.exports = new Upnp();