/*! Copyright (c) 2018 Siemens AG. Licensed under the MIT License. */ import * as bonjourFunc from "bonjour"; import { Configuration, Container } from ".."; /** * Node.js specific utility functions to be used by Coaty agent services. */ export declare class NodeUtils { /** * Provide a Configuration from the specified local JSON or JS file. * * The value of this option must be the relative or absolute filename of a * JSON config file or a CommonJS module file that exports a Configuration * object. * * If unspecified the default file looked up is app.config.js, then * app.config.json in the current working directory of the server process. * * This option can only be used in a server-side environment (Node.js), not * in a browser runtime. * * @param localConfigFile a local configuration file */ static provideConfiguration(localConfigFile?: string): Configuration; /** * Asynchrounously provides a Configuration from the given Url expecting a * Configuration object in JSON format. * * This option can only be used in a server-side environment (Node.js), not * in a browser runtime. * * @param configurationUrl a Url to load the configuration from */ static provideConfigurationAsync(configurationUrl: string): Promise; /** * Perform synchronous and asynchronous cleanup of allocated resources (e.g. * file descriptors, handles, DB connections, etc.) before shutting down the * Node.js process. * * @param cleanup callback function for synchronous cleanup (optional) * @param cleanupAsync callback function for asynchronous cleanup (optional) */ static handleProcessTermination(cleanup?: () => void, cleanupAsync?: () => Promise): void; /** * Log changes in online/offline communication state (i.e. agent connection * to Coaty broker) to the console. * * @param container a Coaty container */ static logCommunicationState(container: Container): void; /** * Log the given informational message to console, also providing the logging date. * * @param message informational message to log * @param isoDateString date string in ISO format or unspecified to use current data (optional) */ static logInfo(message: string, isoDateString?: string): void; /** * Log the given error to console, also providing the logging date. * * @param error error * @param message an extra message (optional) * @param isoDateString date string in ISO format or unspecified to use current data (optional) */ static logError(error: any, message?: string, isoDateString?: string): void; /** * Log the given event to console, also providing the logging date. * * @param message message to log * @param eventName name of event to log (optional) * @param eventDirection direction of event to log (in or out) */ static logEvent(message: string, eventName?: string, eventDirection?: "In" | "Out"): void; /** * Gets the first IPv4 address of the specified network interface of the * local machine. If no network interface name is specified, the first IPv4 * address of the first network interface that provides an IPv4 address is * returned. Returns `undefined` if no IPv4 address could be looked up. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. */ static getLocalIpV4Address(networkInterface?: string): string; /** * Gets the first IPv6 address of the specified network interface of the * local machine. If no network interface name is specified, the first IPv6 * address of the first network interface that provides an IPv6 address is * returned. Returns `undefined` if no IPv6 address could be looked up. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. */ static getLocalIpV6Address(networkInterface?: string): string; private static _getLocalIpAddress; } /** * Represents a multicast DNS service object as resolved by the `MulticastDnsDiscovery.findMulticastDnsService` and * `MulticastDnsDiscovery.publishMulticastDnsService` methods. * * Note: This interface just reexposes the members of the `bonjour.BaseService` interface defined * in the npm `bonjour` package. */ export interface MulticastDnsService extends bonjourFunc.BaseService { } /** * Provides static methods to publish and find multicast DNS services. */ export declare class MulticastDnsDiscovery { private static readonly bonjour; /** * Publish a multicast DNS (a.k.a mDNS, Bonjour, Zeroconf) service with the * given parameters. Typically used for discovering the Coaty broker/router * or for discovering Coaty configuration URLs hosted on a web server. The * published mDNS service contains a JSON TXT record including specific * connection parameters. The keys and values of these parameters are always * strings so you can easily concat them to form a URL, etc. * * Note that the `host` parameter is optional. By default, the local * hostname is used (not the local host IP address!). To resolve this * hostname, your network DNS system must be configured properly. If this is * not the case, you can pass the target IP address of your mDNS service * explicitely. * * The function returns a promise that is resolved with the published * service object of type `MulticastDnsService`. If an error occurs while * publishing, the promise is rejected. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @param name the name of the mDNS service * @param type the type of the mDNS service * @param port the port of the mDNS service * @param txtRecord the TXT record containing additional key value pairs * (optional) * @param host the host IP address to be published with the service * (optional, defaults to local hostname) */ static publishMulticastDnsService(name: string, type: string, port: number, txtRecord?: { [key: string]: string; }, host?: string): Promise; /** * Publish Coaty MQTT broker information using a multicast DNS (a.k.a mDNS, * Bonjour) service with the given parameters. * * Note that the `host` parameter is optional. By default, the local * hostname is used (not the local host IP address!). To resolve this * hostname, your network DNS system must be configured properly. If this is * not the case, you can pass the target IP address of your mDNS service * explicitely. * * The function returns a promise that is resolved with the published * service object of type `MulticastDnsService`. If an error occurs while * publishing, the promise is rejected. * * The broker's websocket port (`ws-port`) is published in the TXT record of * the service. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @remarks If published with default arguments, the FQDN (fully qualified * domain name) of the Coaty MQTT broker mDNS service is "Coaty MQTT * Broker._coaty-mqtt._tcp.local". Since the used mDNS library does not * handle "_services._dns-sd._udp." meta-queries for browsing, Coaty MQTT * Broker information can only be discovered if you provide the mDNS service * name explicitely. * * @param port the broker's port (default value is 1883) * @param wsPort the broker's websocket port (default value is 9883) * @param name the name of the mDNS service (default value is `Coaty MQTT * Broker`) * @param type the type of the mDNS service (default value is `coaty-mqtt`) * @param host the broker IP address to be published with the service * (default is local hostname) */ static publishMqttBrokerService(port?: number, wsPort?: number, name?: string, type?: string, host?: string): Promise; /** * Publish Coaty WAMP router information using a multicast DNS (a.k.a mDNS, * Bonjour) service with the given parameters. * * Note that the `host` parameter is optional. By default, the local * hostname is used (not the local host IP address!). To resolve this * hostname, your network DNS system must be configured properly. If this is * not the case, you can pass the target IP address of your mDNS service * explicitely. * * The function returns a promise that is resolved with the published * service object of type `MulticastDnsService`. If an error occurs while * publishing, the promise is rejected. * * The WAMP router's URL path (`path`) and realm (`realm`) is published in * the TXT record of the service. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @remarks If published with default arguments, the FQDN (fully qualified * domain name) of the WAMP router mDNS service is "Coaty WAMP * Broker._coaty-wamp._tcp.local". Since the used mDNS library does not * handle "_services._dns-sd._udp." meta-queries for browsing, Coaty WAMP * Router information can only be discovered if you provide the mDNS service * name explicitely. * * @param path the router's URL path (default value is `/`) * @param realm the router's realm (default value is `coaty`) * @param port the router's port (default value is 80) * @param name the name of the mDNS service (default value is `Coaty WAMP * Router`) * @param type the type of the mDNS service (default value is `coaty-wamp`) * @param host the router IP address to be published with the service * (default is local hostname) */ static publishWampRouterService(path?: string, realm?: string, port?: number, name?: string, type?: string, host?: string): Promise; /** * Unpublish all published multicast DNS services. Returns a promise that is resolved after all * services have been unpublished. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. */ static unpublishMulticastDnsServices(): Promise; /** * Finds the first multicast DNS service of the given name and type. * Returns a promise that is resolved with the given service object * or rejected if the service cannot be discovered within the given timeout * interval. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @param name the name of the mDNS service to find * @param name the type of the mDNS service to find * @param timeout the number of milliseconds after which the returned promise is rejected (optional, default is 2147483647) */ static findMulticastDnsService(name: string, type: string, timeout?: number): Promise; /** * Finds the first multicast DNS service publishing Coaty MQTT broker information. * Returns a promise that is resolved with the given service object * or rejected if the service cannot be discovered within the given timeout * interval. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @param timeout the number of milliseconds after which the returned promise is rejected (defaults to 2147483647) * @param name the name of the mDNS service to find (defaults to `Coaty MQTT Broker`) * @param type the type of the mDNS service to find (defaults to `coaty-mqtt`) */ static findMqttBrokerService(timeout?: number, name?: string, type?: string): Promise; /** * Finds the first multicast DNS service publishing Coaty WAMP router information. * Returns a promise that is resolved with the given service object * or rejected if the service cannot be discovered within the given timeout * interval. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. * * @param timeout the number of milliseconds after which the returned promise is rejected (defaults to 2147483647) * @param name the name of the mDNS service to find (defaults to `Coaty WAMP Router`) * @param type the type of the mDNS service to find (defaults to `coaty-wamp`) */ static findWampRouterService(timeout?: number, name?: string, type?: string): Promise; /** * @deprecated since 2.3.0. Use `NodeUtils.getLocalIpV4Address()` instead. * * Gets the first IPv4 address of the specified network interface of the * local machine. If no network interface name is specified, the first IPv4 * address of the first network interface that provides an IPv4 address is * returned. Returns `undefined` if no IPv4 address could be looked up. * * This function can only be used in a server-side environment (Node.js), * not in a browser runtime. */ static getLocalIpV4Address(networkInterface?: string): string; }