* Start listening for incoming connections. * * @returns {Promise} Promise which resolves once the server is started.
()
| 852 | * @returns {Promise} Promise which resolves once the server is started. |
| 853 | */ |
| 854 | start(): Promise<void> { |
| 855 | const opts: dnssd.Options = { |
| 856 | name: this.name, |
| 857 | txt: { |
| 858 | path: '/', |
| 859 | }, |
| 860 | }; |
| 861 | |
| 862 | if (this.app.isTls) { |
| 863 | opts.txt.tls = '1'; |
| 864 | } |
| 865 | |
| 866 | this.mdns = new dnssd.Advertisement( |
| 867 | new dnssd.ServiceType('_webthing._tcp'), |
| 868 | this.port!, |
| 869 | opts |
| 870 | ); |
| 871 | this.mdns.on('error', (e) => { |
| 872 | console.debug(`mDNS error: ${e}`); |
| 873 | setTimeout(() => { |
| 874 | this.mdns.start(); |
| 875 | }, 10000); |
| 876 | }); |
| 877 | this.mdns.start(); |
| 878 | |
| 879 | return new Promise((resolve) => { |
| 880 | this.server.listen({port: this.port}, resolve); |
| 881 | }); |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Stop listening. |