1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const logging_1 = require("../logging");
|
4 | const Constants_1 = require("./Constants");
|
5 | const Message_1 = require("./Message");
|
6 | const SocketBase_1 = require("./SocketBase");
|
7 |
|
8 |
|
9 |
|
10 | class NotifySocket extends SocketBase_1.SocketBase {
|
11 | |
12 |
|
13 |
|
14 |
|
15 | constructor(addresses) {
|
16 | super();
|
17 | this.addresses = addresses;
|
18 | }
|
19 | onListening() {
|
20 | logging_1.log('NotifySocket#onListening - %s:%d', this.socket.address().address, this.socket.address().port);
|
21 | for (const address of this.addresses) {
|
22 | logging_1.log('NotifySocket#onListening - add membership to %s', address);
|
23 | try {
|
24 | this.socket.addMembership(Constants_1.SSDP_MULTICAST_ADDRESS, address);
|
25 | }
|
26 | catch (error) {
|
27 | logging_1.log('NotifySocket#onListening - %o', error);
|
28 | }
|
29 | }
|
30 | }
|
31 | onMessage(messageBuffer, remote) {
|
32 | const message = new Message_1.Message(remote.address, messageBuffer);
|
33 | if (message.method !== 'NOTIFY * HTTP/1.1' ||
|
34 | message.nt !== 'urn:axis-com:service:BasicService:1') {
|
35 | return;
|
36 | }
|
37 | if (message.nts === 'ssdp:alive') {
|
38 | this.emit('hello', message);
|
39 | }
|
40 | else if (message.nts === 'ssdp:byebye') {
|
41 | this.emit('goodbye', message);
|
42 | }
|
43 | }
|
44 | bind() {
|
45 | return new Promise((resolve) => {
|
46 | this.socket.bind(Constants_1.SSDP_PORT, undefined, () => resolve());
|
47 | });
|
48 | }
|
49 | }
|
50 | exports.NotifySocket = NotifySocket;
|
51 |
|
\ | No newline at end of file |