|
1 | 1 | /* eslint-disable max-classes-per-file */
|
2 | 2 | import { grpc } from '@improbable-eng/grpc-web';
|
3 |
| -import { |
4 |
| - dialDirect, |
5 |
| - dialWebRTC, |
6 |
| - type Credentials, |
7 |
| - type DialOptions, |
8 |
| -} from '@viamrobotics/rpc'; |
| 3 | +import { dialDirect, dialWebRTC, type DialOptions } from '@viamrobotics/rpc'; |
9 | 4 | import { backOff } from 'exponential-backoff';
|
10 | 5 | import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
|
| 6 | +import { isCredential, type Credentials } from '../app/viam-transport'; |
11 | 7 | import { DIAL_TIMEOUT } from '../constants';
|
12 | 8 | import { EventDispatcher, MachineConnectionEvent } from '../events';
|
13 | 9 | import type {
|
@@ -36,7 +32,7 @@ import { SensorsServiceClient } from '../gen/service/sensors/v1/sensors_pb_servi
|
36 | 32 | import { SLAMServiceClient } from '../gen/service/slam/v1/slam_pb_service';
|
37 | 33 | import { VisionServiceClient } from '../gen/service/vision/v1/vision_pb_service';
|
38 | 34 | import { ViamResponseStream } from '../responses';
|
39 |
| -import { encodeResourceName, promisify, MetadataTransport } from '../utils'; |
| 35 | +import { MetadataTransport, encodeResourceName, promisify } from '../utils'; |
40 | 36 | import GRPCConnectionManager from './grpc-connection-manager';
|
41 | 37 | import type { Robot, RobotStatusStream } from './robot';
|
42 | 38 | import SessionManager from './session-manager';
|
@@ -443,14 +439,21 @@ export class RobotClient extends EventDispatcher implements Robot {
|
443 | 439 | try {
|
444 | 440 | const opts: DialOptions = {
|
445 | 441 | authEntity,
|
446 |
| - credentials: creds, |
447 | 442 | webrtcOptions: {
|
448 | 443 | disableTrickleICE: false,
|
449 | 444 | rtcConfig: this.webrtcOptions?.rtcConfig,
|
450 | 445 | },
|
451 | 446 | dialTimeout: dialTimeout ?? DIAL_TIMEOUT,
|
452 | 447 | };
|
453 | 448 |
|
| 449 | + if (creds) { |
| 450 | + if (isCredential(creds)) { |
| 451 | + opts.credentials = creds; |
| 452 | + } else { |
| 453 | + opts.accessToken = creds.payload; |
| 454 | + } |
| 455 | + } |
| 456 | + |
454 | 457 | // Webrtcoptions will always be defined, but TS doesn't know this
|
455 | 458 | if (priority !== undefined && opts.webrtcOptions) {
|
456 | 459 | opts.webrtcOptions.additionalSdpFields = { 'x-priority': priority };
|
|
0 commit comments