Skip to content

Commit

Permalink
RSDK-5228 - allow setting sdp values (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 authored Oct 27, 2023
1 parent dd7b33c commit a886344
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 15 additions & 3 deletions src/robot/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/robot/dial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const dialDirect = async (conf: DialDirectConf): Promise<RobotClient> => {
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');
Expand Down Expand Up @@ -90,6 +90,7 @@ export interface DialWebRTCConf {
// WebRTC
signalingAddress: string;
iceServers?: ICEServer[];
priority?: number;
}

const dialWebRTC = async (conf: DialWebRTCConf): Promise<RobotClient> => {
Expand Down Expand Up @@ -120,7 +121,11 @@ const dialWebRTC = async (conf: DialWebRTCConf): Promise<RobotClient> => {
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');
Expand Down

0 comments on commit a886344

Please sign in to comment.