-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathNetwork.ts
More file actions
87 lines (68 loc) · 2.42 KB
/
Network.ts
File metadata and controls
87 lines (68 loc) · 2.42 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @license
* Copyright 2022-2026 Matter.js Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { MatterError } from "../MatterError.js";
import type { MaybePromise } from "../util/Promises.js";
import type { TcpConnection, TcpListener, TcpListenerOptions } from "./tcp/TcpConnection.js";
import type { UdpSocket, UdpSocketOptions } from "./udp/UdpSocket.js";
export class NetworkError extends MatterError {}
export class NoAddressAvailableError extends NetworkError {}
export class BindError extends NetworkError {}
export class AddressInUseError extends BindError {}
export class AddressUnreachableError extends NetworkError {}
export class NetworkUnreachableError extends NetworkError {}
export const STANDARD_MATTER_PORT = 5540;
/**
* @see {@link MatterSpecification.v11.Core} § 11.11.4.4
* Duplicated from the GeneralDiagnostics cluster to avoid circular dependencies.
*/
export enum InterfaceType {
/**
* Indicates an interface of an unspecified type.
*/
Unspecified = 0,
/**
* Indicates a Wi-Fi interface.
*/
WiFi = 1,
/**
* Indicates a Ethernet interface.
*/
Ethernet = 2,
/**
* Indicates a Cellular interface.
*/
Cellular = 3,
/**
* Indicates a Thread interface.
*/
Thread = 4,
}
export type NetworkInterface = {
name: string;
type?: InterfaceType;
};
export type NetworkInterfaceDetails = {
mac: string;
ipV4: string[];
ipV6: string[];
};
export type NetworkInterfaceDetailed = NetworkInterface & NetworkInterfaceDetails;
export abstract class Network {
abstract getNetInterfaces(configuration?: NetworkInterface[]): MaybePromise<NetworkInterface[]>;
abstract getIpMac(netInterface: string): MaybePromise<NetworkInterfaceDetails | undefined>;
abstract createUdpSocket(options: UdpSocketOptions): Promise<UdpSocket>;
/** Create a TCP server socket. Override in platform implementations that support TCP. */
createTcpListener(_options: TcpListenerOptions): Promise<TcpListener> {
throw new NetworkError("TCP server not supported on this platform");
}
/** Connect to a remote TCP endpoint. Override in platform implementations that support TCP. */
connectTcp(_host: string, _port: number, _options?: { timeout?: number }): Promise<TcpConnection> {
throw new NetworkError("TCP client not supported on this platform");
}
async close() {
// Nothing to do
}
}