roslib
    Preparing search index...

    Class Service<TRequest, TResponse>

    A ROS service client.

    Type Parameters

    • TRequest
    • TResponse

    Hierarchy

    • EventEmitter
      • Service
    Index

    Constructors

    • Type Parameters

      • TRequest
      • TResponse

      Parameters

      • options: { name: string; ros: Ros; serviceType: string }
        • name: string

          The service name, like '/add_two_ints'.

        • ros: Ros

          The ROSLIB.Ros connection handle.

        • serviceType: string

          The service type, like 'rospy_tutorials/AddTwoInts'.

      Returns Service<TRequest, TResponse>

    Properties

    isAdvertised: boolean = false
    name: string
    ros: Ros
    serviceType: string
    prefixed: string | boolean

    Methods

    • Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
      • Optionalcontext: any

      Returns this

    • 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.

      Parameters

      • callback: (request: TRequest, response: Partial<TResponse>) => boolean

        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.

      Returns Promise<void>

    • An alternate form of Service advertisement that supports a modern Promise-based interface for use with async/await.

      Parameters

      • callback: (request: TRequest) => Promise<TResponse>

        An asynchronous callback processing the request and returning a response.

      Returns Promise<void>

    • Call the service. Returns the service response in the callback. Does nothing if this service is currently advertised.

      Parameters

      • request: TRequest

        The service request to send.

      • Optionalcallback: (response: TResponse) => void

        Function with the following params:

      • OptionalfailedCallback: (error: string) => void = console.error

        The callback function when the service call failed with params:

      • Optionaltimeout: number

        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.

      Returns void

    • Calls each of the listeners registered for a given event.

      Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • ...args: any[]

      Returns boolean

    • Return an array listing the events for which the emitter has registered listeners.

      Returns (string | symbol)[]

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

      Returns number

    • Return the listeners registered for a given event.

      Type Parameters

      • T extends string | symbol

      Parameters

      • event: T

      Returns ((...args: any[]) => void)[]

    • Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • Optionalfn: (...args: any[]) => void
      • Optionalcontext: any
      • Optionalonce: boolean

      Returns this

    • Add a listener for a given event.

      Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
      • Optionalcontext: any

      Returns this

    • Add a one-time listener for a given event.

      Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • fn: (...args: any[]) => void
      • Optionalcontext: any

      Returns this

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: string | symbol

      Returns this

    • Remove the listeners of a given event.

      Type Parameters

      • T extends string | symbol

      Parameters

      • event: T
      • Optionalfn: (...args: any[]) => void
      • Optionalcontext: any
      • Optionalonce: boolean

      Returns this