UNPKG

roslib

Version:

The standard ROS Javascript Library

50 lines (49 loc) 2.28 kB
import { EventEmitter } from 'eventemitter3'; import { default as Ros } from './Ros.ts'; /** * A ROS service client. */ export default class Service<TRequest = unknown, TResponse = unknown> extends EventEmitter { #private; isAdvertised: boolean; ros: Ros; name: string; serviceType: string; /** * @param options * @param options.ros - The ROSLIB.Ros connection handle. * @param options.name - The service name, like '/add_two_ints'. * @param options.serviceType - The service type, like 'rospy_tutorials/AddTwoInts'. */ constructor({ ros, name, serviceType, }: { ros: Ros; name: string; serviceType: string; }); /** * Call the service. Returns the service response in the * callback. Does nothing if this service is currently advertised. * * @param request - The service request to send. * @param [callback] - Function with the following params: * @param [failedCallback] - The callback function when the service call failed with params: * @param [timeout] - Optional timeout, in seconds, for the service call. A non-positive value means no timeout. * If not provided, the rosbridge server will use its default value. */ callService(request: TRequest, callback?: (response: TResponse) => void, failedCallback?: (error: string) => void, timeout?: number): void; /** * Advertise the service. This turns the Service object from a client * into a server. The callback will be called with every request * that's made on this service. * * @param callback This works similarly to the callback for a C++ service in that you should take care not to overwrite the response object. * Instead, only modify the values within. */ advertise(callback: (request: TRequest, response: Partial<TResponse>) => boolean): Promise<void>; unadvertise(): Promise<void>; /** * An alternate form of Service advertisement that supports a modern Promise-based interface for use with async/await. * @param callback An asynchronous callback processing the request and returning a response. */ advertiseAsync(callback: (request: TRequest) => Promise<TResponse>): Promise<void>; }