|
| 1 | +import { type JsonValue, Struct } from '@bufbuild/protobuf'; |
| 2 | +import type { CallOptions, PromiseClient } from '@connectrpc/connect'; |
| 3 | +import { PoseTrackerService } from '../../gen/component/posetracker/v1/pose_tracker_connect'; |
| 4 | +import type { RobotClient } from '../../robot'; |
| 5 | +import type { Options } from '../../types'; |
| 6 | +import { doCommandFromClient } from '../../utils'; |
| 7 | +import type { PoseTracker } from './pose-tracker'; |
| 8 | +import { GetGeometriesRequest } from '../../gen/common/v1/common_pb'; |
| 9 | + |
| 10 | +/** |
| 11 | + * A gRPC-web client for the Generic component. |
| 12 | + * |
| 13 | + * @group Clients |
| 14 | + */ |
| 15 | +export class PoseTrackerClient implements PoseTracker { |
| 16 | + private client: PromiseClient<typeof PoseTrackerService>; |
| 17 | + public readonly name: string; |
| 18 | + private readonly options: Options; |
| 19 | + public callOptions: CallOptions = { headers: {} as Record<string, string> }; |
| 20 | + |
| 21 | + constructor(client: RobotClient, name: string, options: Options = {}) { |
| 22 | + this.client = client.createServiceClient(PoseTrackerService); |
| 23 | + this.name = name; |
| 24 | + this.options = options; |
| 25 | + } |
| 26 | + |
| 27 | + async getGeometries(extra = {}, callOptions = this.callOptions) { |
| 28 | + const request = new GetGeometriesRequest({ |
| 29 | + name: this.name, |
| 30 | + extra: Struct.fromJson(extra), |
| 31 | + }); |
| 32 | + |
| 33 | + const response = await this.client.getGeometries(request, callOptions); |
| 34 | + return response.geometries; |
| 35 | + } |
| 36 | + |
| 37 | + async doCommand( |
| 38 | + command: Struct, |
| 39 | + callOptions = this.callOptions |
| 40 | + ): Promise<JsonValue> { |
| 41 | + return doCommandFromClient( |
| 42 | + this.client.doCommand, |
| 43 | + this.name, |
| 44 | + command, |
| 45 | + this.options, |
| 46 | + callOptions |
| 47 | + ); |
| 48 | + } |
| 49 | +} |
0 commit comments