@viamrobotics/sdk 0.2.1 → 0.2.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import type { Credentials } from '@viamrobotics/rpc/src/dial';
2
2
  import type { grpc } from '@improbable-eng/grpc-web';
3
+ import { EventDispatcher } from '../events';
3
4
  import proto from '../gen/robot/v1/robot_pb';
4
5
  import type { PoseInFrame, ResourceName, Transform } from '../gen/common/v1/common_pb';
5
6
  import { ArmServiceClient } from '../gen/component/arm/v1/arm_pb_service';
@@ -40,7 +41,7 @@ declare abstract class ServiceClient {
40
41
  *
41
42
  * @group Clients
42
43
  */
43
- export declare class RobotClient implements Robot {
44
+ export declare class RobotClient extends EventDispatcher implements Robot {
44
45
  private readonly serviceHost;
45
46
  private readonly webrtcOptions;
46
47
  private readonly sessionOptions;
@@ -91,6 +92,7 @@ export declare class RobotClient implements Robot {
91
92
  createServiceClient<T extends ServiceClient>(SC: new (serviceHost: string, options?: grpc.RpcOptions) => T): T;
92
93
  get peerConnection(): RTCPeerConnection | undefined;
93
94
  disconnect(): Promise<void>;
95
+ isConnected(): boolean;
94
96
  connect(authEntity?: string | undefined, creds?: Credentials | undefined): Promise<void>;
95
97
  getOperations(): Promise<proto.Operation[]>;
96
98
  cancelOperation(id: string): Promise<void>;
@@ -1,8 +1,10 @@
1
1
  import type { PoseInFrame, ResourceName, Transform } from '../gen/common/v1/common_pb';
2
2
  import type { StructType } from '../types';
3
+ import { DISCONNECTED, RECONNECTED } from '../events';
3
4
  import type proto from '../gen/robot/v1/robot_pb';
4
5
  import type { ResponseStream } from '../gen/robot/v1/robot_pb_service';
5
6
  export type RobotStatusStream = ResponseStream<proto.Status[]>;
7
+ type Callback = (args: unknown) => void;
6
8
  export interface Robot {
7
9
  /**
8
10
  * Get the list of operations currently running on the robot.
@@ -116,4 +118,16 @@ export interface Robot {
116
118
  * @alpha
117
119
  */
118
120
  streamStatus(resourceNames?: ResourceName.AsObject[], durationMs?: number): RobotStatusStream;
121
+ /**
122
+ * Call a function when an event of either 'reconnected' or 'disconnected' is
123
+ * triggered. Note that these events will only be triggered on WebRTC
124
+ * connections.
125
+ *
126
+ * @param type - The event ('reconnected' or 'disconnected') that was
127
+ * triggered.
128
+ * @param listener - The function to call
129
+ * @alpha
130
+ */
131
+ on: (type: typeof RECONNECTED | typeof DISCONNECTED, listener: Callback) => void;
119
132
  }
133
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2-rc.0",
4
4
  "description": "",
5
5
  "main": "./dist/main.umd.js",
6
6
  "module": "./dist/main.es.js",