import * as miniseed from "./miniseed.mjs"; import * as mseed3 from "./mseed3.mjs"; import { DateTime } from "luxon"; /** const for websocket subprotocol for datalink, DataLink1.0 */ export declare const WS_DATALINK_SUBPROTOCOL = "DataLink1.1"; /** enum for modes, either QUERY or STREAM */ export declare enum MODE { Query = "QUERY", Stream = "STREAM" } /** const for query mode, QUERY */ export declare const QUERY_MODE = MODE.Query; /** const for streaming mode, STREAM */ export declare const STREAM_MODE = MODE.Stream; /** const for maximum process number to create fake number for datalink id, 2^16-2 */ export declare const MAX_PROC_NUM: number; /** const for fake user name for datalink id, browser */ export declare const USER_BROWSER = "browser"; /** const for fake program name for datalink id, seisplotjs */ export declare const DEFAULT_PROGRAM = "seisplotjs"; /** const for fake architecture for datalink id, javascript */ export declare const DEFAULT_ARCH = "javascript"; /** const for error response, ERROR */ export declare const ERROR = "ERROR"; /** const for ok response, OK */ export declare const OK = "OK"; /** const for info response, INFO */ export declare const INFO = "INFO"; /** const for id response, ID */ export declare const ID = "ID"; export declare const PACKET = "PACKET"; export declare const STREAM = "STREAM"; export declare const ENDSTREAM = "ENDSTREAM"; export declare const MSEED_TYPE = "/MSEED"; export declare const MSEED3_TYPE = "/MSEED3"; export declare const JSON_TYPE = "/JSON"; export declare const IRIS_RINGSERVER_URL = "wss://rtserve.iris.washington.edu/datalink"; export declare const EARTHSCOPE_RINGSERVER_URL = "wss://rtserve.earthscope.org/datalink"; export declare function extractDLProto(lines: Array): string; /** * A websocket based Datalink connection. * * Note this cannot connect directly to a native TCP socket, instead it * sends the datalink protocol over a websocket. * * Currently only the IRIS * ringserver, https://github.com/iris-edu/ringserver, * supports websockets, but it may be possible to use third party * tools to proxy the websocket to a TCP datalink socket. * * The datalink protocol is documented here * https://earthscope.github.io/libdali/datalink-protocol.html * * @param url websocket url to the ringserver * @param packetHandler callback for packets as they arrive * @param errorHandler callback for errors */ export declare class DataLinkConnection { url: string; /** @private */ _mode: MODE; packetHandler: (packet: DataLinkPacket) => void; errorHandler: (error: Error) => void; logCommandFn: null | ((cmd: string) => void); closeHandler: null | ((close: CloseEvent) => void); serverId: string | null; clientIdNum: number; programname: string; username: string; architecture: string; /** @private */ _responseResolve: null | ((response: DataLinkResponse) => void); /** @private */ _responseReject: null | ((error: Error) => void); webSocket: WebSocket | null; subprotocol: string; dlproto: string; constructor(url: string, packetHandler: (packet: DataLinkPacket) => void, errorHandler: (error: Error) => void); /** * Set a callback function called when the connection is closed. * * @param closeHandler callback function */ setOnClose(closeHandler: (close: CloseEvent) => void): void; /** * creates the websocket connection and sends the client ID. * * @returns a Promise that resolves to the server's ID. */ connect(): Promise; /** * @returns true if the websocket is connected (non-null) */ isConnected(): boolean; /** * @returns the current mode, QUERY_MODE or STREAM_MODE */ get mode(): string; /** * Switches to streaming mode to receive data packets from the ringserver. * * @returns promise to the response */ stream(): Promise; /** * Switches back to query mode to enable commands to be sent to the ringserver. */ endStream(): void; /** * Closes the connection and the underlying websocket. No communication * is possible until connect() is called again. */ close(): void; /** * Send a ID Command. Command is a string. * * @returns a Promise that resolves to the response from the ringserver. */ sendId(): Promise; /** * encodes as a Datalink packet, header with optional data section as * binary Uint8Array. Size of the binary data is appended * to the header if present. * * @param header the command/header string * @param data optional data portion * @returns datalink packet as an ArrayBufferLike */ encodeDL(header: string, data?: Uint8Array): ArrayBuffer; /** * sends the header with optional binary data * as the data section. Size of the data is appended * to the header before sending if present. * * @param header header to send * @param data optional data to send */ sendDLBinary(header: string, data?: Uint8Array): void; /** * sends the command as header with optional dataString * as the data section. Size of the dataString is appended * to the header before sending. * * @param command the command/header string * @param dataString optional data portion of packet */ sendDLCommand(command: string, dataString?: string): void; /** * Send a DataLink Command and await the response. Command is a string. * * @param header packet header * @param data optional data portion of packet * @returns a Promise that resolves with the webSocket MessageEvent. */ awaitDLBinary(header: string, data?: Uint8Array): Promise; /** * Send a DataLink Command and await the response. Command is a string. * Returns a Promise that resolves with the webSocket MessageEvent. * * @param command the command/header string * @param dataString optional data portion of packet * @returns promise to server's response */ awaitDLCommand(command: string, dataString?: string): Promise; /** * Writes data to the ringserver and awaits a acknowledgement. * * @param streamid stream id for packet header * @param hpdatastart start of timewindow the packet covers * @param hpdataend end of timewindow the packet covers * @param data optional data to send * @returns promise to server's response */ writeAck(streamid: string, hpdatastart: DateTime, hpdataend: DateTime, data?: Uint8Array): Promise; /** * Makes sure a response actually is a DataLinkResponse * * @param dl datalink packet/response * @returns DataLinkResponse after checking instanceof * @throws Error if not a DataLinkResponse */ static ensureDataLinkResponse(dl: DataLinkResponse | DataLinkPacket): DataLinkResponse; /** * Makes sure a response actually is a DataLinkPacket * * @param dl datalink packet/response * @returns DataLinkPacket after checking instanceof * @throws Error if not a DataLinkPacket */ static ensureDataLinkPacket(dl: DataLinkResponse | DataLinkPacket): DataLinkPacket; /** * Send id and await server's response. All of these are can more or less * be filled with dummy values. They are mostly used for logging and debugging * on the server side. * * @param programname name of program, ex seisplotjs * @param username name of user, ex browser * @param processid process number, used to differentiate between multiple running instances * @param architecture cpu architecture, ex javascript * @returns promise to servers response */ id(programname: string, username: string, processid: string, architecture: string): Promise; /** * Send info command for infoType. * * @param infoType type to get info for * @returns promise to server's response */ info(infoType: string): Promise; infoStatus(): Promise; infoStreams(): Promise; infoConnections(): Promise; /** * Send position after command. * * @param time time to position after * @returns promise to server's response */ positionAfter(time: DateTime): Promise; /** * Send position after command. * * @param hpTime time to position after * @returns promise to server's response */ positionAfterHPTime(hpTime: number): Promise; /** * Send match command. * * @param pattern regular expression to match streams * @returns promise to server's response */ match(pattern: string): Promise; /** * Send reject command. * * @param pattern regular expression to reject streams * @returns promise to server's response */ reject(pattern: string): Promise; /** * Read a single packet for the given id. * * @param packetId id of the packet of interest * @returns promise to server's response */ read(packetId: string): Promise; /** * Handles a web socket message from the data link connection. * * @private * @param wsEvent web socket event to handle */ handle(wsEvent: MessageEvent): void; handleArrayBuffer(rawData: ArrayBufferLike): void; /** * handle errors that arise * * @private * @param error the error */ handleError(error: Error): void; } /** * Datalink response, used for ID, INFO, OK and ERROR responses. */ export declare class DataLinkResponse { type: string; value: string; message: string; constructor(type: string, value: string, message: string); isError(): boolean; toString(): string; static parse(header: string, data?: DataView): DataLinkResponse; } /** * Represents a Datalink packet from the ringserver. * */ export declare class DataLinkPacket { header: string; data: DataView; streamId: string; pktid: string; hppackettime: string; hppacketstart: string; hppacketend: string; dataSize: number; _miniseed: null | miniseed.DataRecord; _mseed3: null | mseed3.MSeed3Record; _json: null | object; constructor(header: string, dataview: DataView); /** * Packet start time as a DateTime. * * @returns start time */ get packetStart(): DateTime; /** * Packet end time as a DateTime. * * @returns end time */ get packetEnd(): DateTime; /** * Packet time as a DateTime. * * @returns packet time */ get packetTime(): DateTime; /** * is this packet a miniseed packet * * @returns true if it is miniseed */ isMiniseed(): boolean; /** * Parsed payload as a miniseed data record, if the streamid * ends with '/MSEED', null otherwise. * * @returns miniseed DataRecord or null */ asMiniseed(): miniseed.DataRecord | null; /** * is this packet a miniseed3 packet * * @returns true if it is miniseed3 */ isMiniseed3(): boolean; /** * Parsed payload as a miniseed3 data record, if the data format is 3, null otherwise. * * @returns miniseed3 DataRecord or null */ asMiniseed3(): mseed3.MSeed3Record | null; /** * is this packet a json packet * * @returns true if it is json */ isJson(): boolean; /** * Parsed payload as a json if is json, null otherwise. * * @returns JSON object or null */ asJson(): object | null; } export declare class DataLinkIdStats { version: string; serverId: string; capabilities: Array; constructor(version: string, serverId: string, capabilities: Array); /** * Parses the attributes of a xml element. * * @param statusEl DataLink XML element * @returns the id stats */ static parseXMLAttributes(statusEl: Element): DataLinkIdStats; toString(): string; } export declare class DataLinkStats { startTime: DateTime; ringVersion: string; ringSize: number; packetSize: number; maximumPacketID: number; maximumPackets: number; memoryMappedRing: boolean; volatileRing: boolean; totalConnections: number; totalStreams: number; txPacketRate: number; txByteRate: number; rxPacketRate: number; rxByteRate: number; earliestPacketID: number; earliestPacketCreationTime: DateTime; earliestPacketDataStartTime: DateTime; earliestPacketDataEndTime: DateTime; latestPacketID: number; latestPacketCreationTime: DateTime; latestPacketDataStartTime: DateTime; latestPacketDataEndTime: DateTime; constructor(startTime: DateTime, ringVersion: string, ringSize: number, packetSize: number, maximumPacketID: number, maximumPackets: number, memoryMappedRing: boolean, volatileRing: boolean, totalConnections: number, totalStreams: number, txPacketRate: number, txByteRate: number, rxPacketRate: number, rxByteRate: number, earliestPacketID: number, earliestPacketCreationTime: DateTime, earliestPacketDataStartTime: DateTime, earliestPacketDataEndTime: DateTime, latestPacketID: number, latestPacketCreationTime: DateTime, latestPacketDataStartTime: DateTime, latestPacketDataEndTime: DateTime); /** * Parses the attributes of a xml element. * * @param statusEl DataLink XML element * @returns the stats */ static parseXMLAttributes(statusEl: Element): DataLinkStats; toString(): string; } export declare class ThreadStat { flags: Array; type: Array; port: number; constructor(flags: Array, type: Array, port: number); /** * Parses the attributes of a xml element. * * @param statusEl DataLink XML element * @returns the stats */ static parseXMLAttributes(statusEl: Element): ThreadStat; toString(): string; } export declare class StatusResponse { idStats: DataLinkIdStats; datalinkStats: DataLinkStats; threadStats: Array; rawXml: string; constructor(idStats: DataLinkIdStats, datalinkStats: DataLinkStats, threadStats: Array); static fromDatalinkResponse(daliResp: DataLinkResponse): StatusResponse; static fromXML(daliXML: Element): StatusResponse; toString(): string; } export declare class StreamStat { name: string; earliestPacketID: number; earliestPacketDataStartTime: DateTime; earliestPacketDataEndTime: DateTime; latestPacketID: number; latestPacketDataStartTime: DateTime; latestPacketDataEndTime: DateTime; dataLatency: number; constructor(name: string, earliestPacketID: number, earliestPacketDataStartTime: DateTime, earliestPacketDataEndTime: DateTime, latestPacketID: number, latestPacketDataStartTime: DateTime, latestPacketDataEndTime: DateTime, dataLatency: number); static parseXMLAttributes(statusEl: Element): StreamStat; toString(): string; } export declare class StreamsResponse { datalinkStats: DataLinkStats; streams: Array; constructor(datalinkStats: DataLinkStats, streams: Array); static fromDatalinkResponse(daliResp: DataLinkResponse): StreamsResponse; static fromXML(daliXML: Element): StreamsResponse; toString(): string; } /** * Non implementation, just stores xml as a string. Unlikely * to be useful remotely as ringserver doesn't allow. * * @param daliXML raw xml form server */ export declare class ConnectionsResponse { daliXML: string; constructor(daliXML: string); static fromDatalinkResponse(daliResp: DataLinkResponse): ConnectionsResponse; static fromXML(daliXML: Element): ConnectionsResponse; toString(): string; } /** * Convert DataLink style dates, like "2022-10-04 15:11:24.786990" * to ISO form for DateTime * * @param dalitime datalink time * @returns DateTime */ export declare function daliDateTime(dalitime: string): DateTime; /** * Convert DateTime to a HPTime number. * * @param m DateTime to convert * @returns microseconds since epoch */ export declare function dateTimeToHPTime(m: DateTime): number; /** * Convert hptime number to a DateTime. * * @param hptime hptime to convert * @returns DateTime in utc for the hptime */ export declare function hpTimeToDateTime(hptime: number): DateTime; /** * Encode string into a Uint8Array. * * @param dataString String to encode. * @returns String as bytes in Uint8Array. */ export declare function stringToUint8Array(dataString?: string): Uint8Array; //# sourceMappingURL=datalink.d.mts.map