diff --git a/package-lock.json b/package-lock.json index 73dd3160e..4c2a592f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.4.0", "license": "Apache-2.0", "dependencies": { - "@viamrobotics/rpc": "^0.1.37", + "@viamrobotics/rpc": "^0.1.38", "exponential-backoff": "^3.1.1" }, "devDependencies": { @@ -1385,9 +1385,9 @@ } }, "node_modules/@viamrobotics/rpc": { - "version": "0.1.37", - "resolved": "https://registry.npmjs.org/@viamrobotics/rpc/-/rpc-0.1.37.tgz", - "integrity": "sha512-gR95RMtpkCRDmScY7gpuygPF3S+oIJdl8ELTUm5J2Nnyyk88XVZHFM6xiKdsdAFdsUe5oX6Y6TvpNh39tVxDhQ==", + "version": "0.1.38", + "resolved": "https://registry.npmjs.org/@viamrobotics/rpc/-/rpc-0.1.38.tgz", + "integrity": "sha512-NWCXv0nKR/Ru2wor3CPy8v+0C2HRO+5epa7zw1O0zEPIRa5u6dvRQ3YNXJmE0DJhR83uLS7lWIhPqP0o/pIIPQ==", "dependencies": { "@improbable-eng/grpc-web": "^0.13.0", "google-protobuf": "^3.14.0" @@ -10615,9 +10615,9 @@ "requires": {} }, "@viamrobotics/rpc": { - "version": "0.1.37", - "resolved": "https://registry.npmjs.org/@viamrobotics/rpc/-/rpc-0.1.37.tgz", - "integrity": "sha512-gR95RMtpkCRDmScY7gpuygPF3S+oIJdl8ELTUm5J2Nnyyk88XVZHFM6xiKdsdAFdsUe5oX6Y6TvpNh39tVxDhQ==", + "version": "0.1.38", + "resolved": "https://registry.npmjs.org/@viamrobotics/rpc/-/rpc-0.1.38.tgz", + "integrity": "sha512-NWCXv0nKR/Ru2wor3CPy8v+0C2HRO+5epa7zw1O0zEPIRa5u6dvRQ3YNXJmE0DJhR83uLS7lWIhPqP0o/pIIPQ==", "requires": { "@improbable-eng/grpc-web": "^0.13.0", "google-protobuf": "^3.14.0" diff --git a/package.json b/package.json index e87763e12..9d819faa8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "homepage": "https://github.com/viamrobotics/viam-typescript-sdk#readme", "dependencies": { - "@viamrobotics/rpc": "^0.1.37", + "@viamrobotics/rpc": "^0.1.38", "exponential-backoff": "^3.1.1" }, "devDependencies": { diff --git a/src/robot/client.ts b/src/robot/client.ts index b307d9e8b..d70d75cc3 100644 --- a/src/robot/client.ts +++ b/src/robot/client.ts @@ -55,6 +55,12 @@ interface SessionOptions { disabled: boolean; } +export interface ConnectOptions { + authEntity?: string; + creds?: Credentials; + priority?: number; +} + abstract class ServiceClient { constructor(public serviceHost: string, public options?: grpc.RpcOptions) {} } @@ -369,10 +375,11 @@ export class RobotClient extends EventDispatcher implements Robot { return this.peerConn?.iceConnectionState === 'connected'; } - public async connect( + public async connect({ authEntity = this.savedAuthEntity, - creds = this.savedCreds - ) { + creds = this.savedCreds, + priority, + }: ConnectOptions = {}) { if (this.connecting) { // This lint is clearly wrong due to how the event loop works such that after an await, the condition may no longer be true. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition @@ -407,6 +414,11 @@ export class RobotClient extends EventDispatcher implements Robot { }, }; + // Webrtcoptions will always be defined, but TS doesn't know this + if (priority !== undefined && opts.webrtcOptions) { + opts.webrtcOptions.additionalSdpFields = { 'x-priority': priority }; + } + // Save authEntity, creds this.savedAuthEntity = authEntity; this.savedCreds = creds; diff --git a/src/robot/dial.ts b/src/robot/dial.ts index 03fa58126..715cf08c4 100644 --- a/src/robot/dial.ts +++ b/src/robot/dial.ts @@ -58,7 +58,7 @@ const dialDirect = async (conf: DialDirectConf): Promise => { if (conf.credential) { creds = conf.credential; } - await client.connect(conf.authEntity, creds); + await client.connect({ authEntity: conf.authEntity, creds }); // eslint-disable-next-line no-console console.debug('connected via gRPC'); @@ -90,6 +90,7 @@ export interface DialWebRTCConf { // WebRTC signalingAddress: string; iceServers?: ICEServer[]; + priority?: number; } const dialWebRTC = async (conf: DialWebRTCConf): Promise => { @@ -120,7 +121,11 @@ const dialWebRTC = async (conf: DialWebRTCConf): Promise => { if (conf.credential) { creds = conf.credential; } - await client.connect(conf.authEntity || impliedURL, creds); + await client.connect({ + authEntity: conf.authEntity || impliedURL, + creds, + priority: conf.priority, + }); // eslint-disable-next-line no-console console.debug('connected via WebRTC');