UNPKG

matterbridge

Version:
140 lines 6.09 kB
/** * @description This file contains the class Dgram. * @file dgram.ts * @author Luca Liguori * @created 2025-03-22 * @version 1.0.0 * @license Apache-2.0 * * Copyright 2025, 2026, 2027 Luca Liguori. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import dgram from 'node:dgram'; import EventEmitter from 'node:events'; import { AddressInfo } from 'node:net'; import { AnsiLogger } from 'node-ansi-logger'; /** * Represents the Dgram events. */ interface DgramEvents { error: [error: Error]; close: []; connect: []; message: [msg: Buffer, rinfo: dgram.RemoteInfo]; listening: [address: AddressInfo]; sent: [msg: Buffer, serverAddress: string, serverPort: number]; ready: [address: AddressInfo]; bound: [address: AddressInfo]; } /** * This class implements a dgram socket. */ export declare class Dgram extends EventEmitter<DgramEvents> { log: AnsiLogger; socket: dgram.Socket; bound: boolean; socketType: 'udp4' | 'udp6'; interfaceName?: string; interfaceAddress?: string; interfaceNetmask?: string; /** * Creates an instance of Dgram. * * @param {string} name - The name of the socket. * @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6). * @param {boolean | undefined} reuseAddr - Whether to allow address reuse. * @param {string} [interfaceName] - The name of the network interface to bind to. * @param {string} [interfaceAddress] - The address of the network interface to bind to. */ constructor(name: string, socketType: 'udp4' | 'udp6', reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string); /** * Sends a message to the specified server. * * @param {Buffer} msg - The message buffer to send. * @param {string} serverAddress - The IPv4 address of the destination server. * @param {number} serverPort - The port of the destination server. */ send(msg: Buffer, serverAddress: string, serverPort: number): void; onError(error: Error): void; onClose(): void; onConnect(): void; onSent(msg: Buffer, serverAddress: string, serverPort: number): void; onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void; onListening(address: AddressInfo): void; onReady(address: AddressInfo): void; /** * Retrieves the IPv4 address of the specified network interface or the first external IPv4 interface if no interface is specified. * Throws an error if no suitable interface or address is found. * * @param {string} networkInterface - The name of the network interface to retrieve the IPv4 address from. If not specified, the first external IPv4 interface will be used. * @returns {string | undefined} The IPv4 address of the specified network interface or the first external IPv4 interface. * @throws Error if no suitable interface or address is found. */ getIpv4InterfaceAddress(networkInterface?: string): string | undefined; /** * Retrieves the IPv6 address of the specified network interface or the first external IPv6 interface if no interface is specified. * Throws an error if no suitable interface or address is found. * * @param {string} [networkInterface] - The name of the network interface to retrieve the IPv6 address from. If not specified, the first external IPv6 interface will be used. * @returns {string | undefined} The IPv6 address of the specified network interface or the first external IPv6 interface. * @throws {Error} If no suitable interface or address is found. */ getIpv6InterfaceAddress(networkInterface?: string): string | undefined; /** * Retrieves the names of all available network interfaces. * * @returns {string[]} An array of network interface names. */ getInterfacesNames(): string[]; /** * Retrieves the scope ID for all interfaces address '::'. * * @returns {string} The scope ID of the first found IPv6 address or an empty string. */ getIpv6ScopeIdForAllInterfacesAddress(): string; /** * Retrieves the interface name from the scope id of an IPv6 address. * * @param {number} scopeId - The scope id of the IPv6 address. * @returns {string | undefined} The interface name or undefined if not found. */ getInterfaceNameFromScopeId(scopeId: number): string | undefined; /** * Retrieves the netmask of the specified interface address. * * @param {string} interfaceAddress - The interface address for which to retrieve the netmask. * @returns {string | undefined} The netmask of the specified interface address or undefined if not found. */ getNetmask(interfaceAddress: string): string | undefined; /** * Computes the broadcast address given an IPv4 address and netmask. * * @param {string | undefined} [ipAddress] - The IPv4 address e.g. "192.168.1.20" * @param {string | undefined} [netmask] - The IPv4 netmask e.g. "255.255.255.0" * @returns {string | undefined} The computed broadcast address, e.g. "192.168.1.255" */ getIpv4BroadcastAddress(ipAddress: string | undefined, netmask: string | undefined): string | undefined; /** * Returns the broadcast IPv6 address. * * @returns {string} The broadcast IPv6 address, e.g. "ff02::1" */ getIpv6BroadcastAddress(): string; /** * Logs all available network interfaces and their details. */ listNetworkInterfaces(): void; } export {}; //# sourceMappingURL=dgram.d.ts.map