import { type ServiceType } from '@bufbuild/protobuf'; import { type CallOptions, type Client } from '@connectrpc/connect'; import { type Credentials } from '../app/viam-transport'; import { EventDispatcher, MachineConnectionEvent } from '../events'; import type { UploadMetadata } from '../gen/app/datasync/v1/data_sync_pb'; import type { PoseInFrame, Transform } from '../gen/common/v1/common_pb'; import { ArmService } from '../gen/component/arm/v1/arm_connect'; import { BaseService } from '../gen/component/base/v1/base_connect'; import { BoardService } from '../gen/component/board/v1/board_connect'; import { EncoderService } from '../gen/component/encoder/v1/encoder_connect'; import { GantryService } from '../gen/component/gantry/v1/gantry_connect'; import { GenericService } from '../gen/component/generic/v1/generic_connect'; import { GripperService } from '../gen/component/gripper/v1/gripper_connect'; import { InputControllerService } from '../gen/component/inputcontroller/v1/input_controller_connect'; import { MotorService } from '../gen/component/motor/v1/motor_connect'; import { MovementSensorService } from '../gen/component/movementsensor/v1/movementsensor_connect'; import { PowerSensorService } from '../gen/component/powersensor/v1/powersensor_connect'; import { ServoService } from '../gen/component/servo/v1/servo_connect'; import { RobotService } from '../gen/robot/v1/robot_connect'; import { type FrameSystemConfig, type GetCloudMetadataResponse, type GetMachineStatusResponse, type GetVersionResponse, type ModuleModel, type Operation, type ResourceRPCSubtype, type Session, type UploadDataFromPathResponse } from '../gen/robot/v1/robot_pb'; import { DiscoveryService } from '../gen/service/discovery/v1/discovery_connect'; import { MLModelService } from '../gen/service/mlmodel/v1/mlmodel_connect'; import { MotionService } from '../gen/service/motion/v1/motion_connect'; import { NavigationService } from '../gen/service/navigation/v1/navigation_connect'; import { SLAMService } from '../gen/service/slam/v1/slam_connect'; import { VisionService } from '../gen/service/vision/v1/vision_connect'; import { WorldStateStoreService } from '../gen/service/worldstatestore/v1/world_state_store_connect'; import { type ResourceName } from '../types'; import type { Robot } from './robot'; interface ICEServer { urls: string; username?: string; credential?: string; } /** Options required to dial a robot via WebRTC. */ export interface DialWebRTCConf { host: string; credentials?: Credentials; disableSessions?: boolean; noReconnect?: boolean; /** @default 10. */ reconnectMaxAttempts?: number; /** @default Number.POSITIVE_INFINITY */ reconnectMaxWait?: number; reconnectAbortSignal?: { abort: boolean; }; /** * Called when a non-retryable error is encountered during reconnection. Return true to treat the * error as retryable. Does not override reconnectMaxAttempts — retries are still bounded by that * limit. */ shouldRetryOnError?: () => boolean; serviceHost?: string; signalingAddress: string; iceServers?: ICEServer[]; priority?: number; /** * When true, sets ICE transport policy to relay-only so only TURN candidates are used. Useful for * testing relay connectivity through a TURN server. */ forceRelay?: boolean; /** * When true, strips TURN servers from the ICE configuration so only host and server-reflexive * candidates are used. Useful for testing direct connectivity without relay fallback. */ forceP2P?: boolean; /** * When set, filters the signaling server's TURN list to only the server whose parsed URI matches * (compared by scheme, host, port, and transport — defaulting transport to UDP if unspecified). * Example: `"turn:turn.viam.com:443"` */ turnUri?: string; /** Overrides the scheme of the matched TURN URI (`"turn"` or `"turns"`). */ turnScheme?: 'turn' | 'turns'; /** Overrides the transport of the matched TURN URI (`"tcp"` or `"udp"`). */ turnTransport?: 'tcp' | 'udp'; /** Overrides the port of the matched TURN URI. */ turnPort?: number; /** * When true, the connection to the signaling server is made over plain HTTP (no TLS). Use this * when connecting to a robot running with `no_tls: true`. */ signalingInsecure?: boolean; /** * Set timeout in milliseconds for dialing. Default is defined by DIAL_TIMEOUT. A value of 0 * disables the timeout. */ dialTimeoutMs?: number; extraHeaders?: Record; } /** Options required to dial a robot via gRPC. */ export interface DialDirectConf { host: string; credentials?: Credentials; disableSessions?: boolean; noReconnect?: boolean; reconnectMaxAttempts?: number; reconnectMaxWait?: number; reconnectAbortSignal?: { abort: boolean; }; /** * Called when a non-retryable error is encountered during reconnection. Return true to treat the * error as retryable. Does not override reconnectMaxAttempts — retries are still bounded by that * limit. */ shouldRetryOnError?: () => boolean; /** * Set timeout in milliseconds for dialing. Default is defined by DIAL_TIMEOUT. A value of 0 * disables the timeout. */ dialTimeoutMs?: number; extraHeaders?: Record; } /** Options required to dial a robot. */ export type DialConf = DialDirectConf | DialWebRTCConf; interface WebRTCOptions { enabled: boolean; host: string; signalingAddress: string; rtcConfig: RTCConfiguration; noReconnect?: boolean; reconnectMaxAttempts?: number; reconnectMaxWait?: number; shouldRetryOnError?: () => boolean; forceRelay?: boolean; forceP2P?: boolean; turnUri?: string; turnScheme?: 'turn' | 'turns'; turnTransport?: 'tcp' | 'udp'; turnPort?: number; signalingInsecure?: boolean; } interface DirectOptions { noReconnect?: boolean; reconnectMaxAttempts?: number; reconnectMaxWait?: number; shouldRetryOnError?: () => boolean; } interface SessionOptions { disabled: boolean; } export interface ConnectOptions { creds?: Credentials; priority?: number; /** * Set timeout in milliseconds for dialing. Default is defined by DIAL_TIMEOUT. A value of 0 * disables the timeout. */ dialTimeoutMs?: number; extraHeaders?: Record; } export declare const isDialWebRTCConf: (value: DialConf) => value is DialWebRTCConf; /** Validates a DialConf passed to createRobotClient. Throws an error for invalid configs. */ export declare const validateDialConf: (conf: DialConf) => void; interface RobotClientDispatchEvents { track: RTCTrackEvent; connectionstatechange: { eventType: MachineConnectionEvent; }; [MachineConnectionEvent.CONNECTING]: Record; [MachineConnectionEvent.CONNECTED]: Record; [MachineConnectionEvent.DISCONNECTING]: Record; [MachineConnectionEvent.DISCONNECTED]: Event | { error?: Error; }; [MachineConnectionEvent.DIALING]: { method: 'webrtc' | 'grpc'; attempt: number; }; [MachineConnectionEvent.RECONNECTING]: Event | undefined; [MachineConnectionEvent.RECONNECTION_FAILED]: { error: unknown; attempts: number; }; } /** * A gRPC-web client for a Robot. * * @group Clients */ export declare class RobotClient extends EventDispatcher implements Robot { private serviceHost; private readonly webrtcOptions; private readonly directOptions; private readonly sessionOptions; private gRPCConnectionManager; private sessionManager; private peerConn; private dataChannel; private transport; private connecting; private connectResolve; private dialing; private currentDialAbortSignal; private savedCreds; private closed; private robotServiceClient; private armServiceClient; private baseServiceClient; private boardServiceClient; private encoderServiceClient; private gantryServiceClient; private genericServiceClient; private gripperServiceClient; private mlModelServiceClient; private movementSensorServiceClient; private powerSensorServiceClient; private inputControllerServiceClient; private motorServiceClient; private navigationServiceClient; private discoveryServiceClient; private motionServiceClient; private visionServiceClient; private servoServiceClient; private slamServiceClient; private worldStateStoreServiceClient; private currentRetryAttempt; private isReconnecting; private connectionId; private onICEConnectionStateChange?; private onDataChannelClose?; private onTrack?; constructor(serviceHost?: string, webrtcOptions?: WebRTCOptions, sessionOptions?: SessionOptions, directOptions?: DirectOptions); private cleanupEventListeners; private onDisconnect; private get noReconnect(); private get reconnectMaxAttempts(); private get reconnectMaxWait(); private get shouldRetryOnError(); get sessionId(): string; private static readonly notConnectedYetStr; get robotService(): Client; get armService(): Client; get baseService(): Client; get boardService(): Client; get encoderService(): Client; get gantryService(): Client; get genericService(): Client; get gripperService(): Client; get mlModelService(): Client; get movementSensorService(): Client; get powerSensorService(): Client; get inputControllerService(): Client; get motorService(): Client; get navigationService(): Client; get discoveryService(): Client; get motionService(): Client; get visionService(): Client; get servoService(): Client; get slamService(): Client; get worldStateStoreService(): Client; createServiceClient(svcType: T): Client; get peerConnection(): RTCPeerConnection | undefined; private get clientTransport(); private dialWebRTC; private dialDirect; private resetDialing; dial(conf: DialConf): Promise; private createBackOffOpts; private tryWebRTCDial; private tryDirectDial; private performDial; disconnect(): Promise; isConnected(): boolean; connect({ creds, priority, dialTimeoutMs, extraHeaders, }?: ConnectOptions): Promise; getSessions(): Promise; getOperations(): Promise; cancelOperation(id: string): Promise; blockForOperation(id: string): Promise; stopAll(): Promise; frameSystemConfig(transforms: Transform[]): Promise; transformPose(source: PoseInFrame, destination: string, supplementalTransforms: Transform[], callOptions?: CallOptions): Promise; transformPCD(pointCloudPCD: Uint8Array, source: string, destination: string): Promise; getModelsFromModules(): Promise; getCloudMetadata(): Promise; resourceNames(): Promise; resourceRPCSubtypes(): Promise; getMachineStatus(): Promise; getVersion(): Promise; restartModule(moduleId?: string, moduleName?: string): Promise; getPose(componentName: string, destinationFrame: string, supplementalTransforms: Transform[]): Promise; uploadDataFromPath(path: string, uploadMetadata?: UploadMetadata, extra?: {}): Promise; } export {};