Skip to content

Commit

Permalink
call connect with options
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 committed Oct 25, 2023
1 parent c648352 commit 0269ef3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 11 additions & 5 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 {
priority?: number;
authEntity?: string;
creds?: Credentials;
}

abstract class ServiceClient {
constructor(public serviceHost: string, public options?: grpc.RpcOptions) {}
}
Expand Down Expand Up @@ -164,7 +170,7 @@ export class RobotClient extends EventDispatcher implements Robot {
console.debug('connection closed, will try to reconnect');
void backOff(
() =>
this.connect().then(
this.connect({}).then(
() => {
// eslint-disable-next-line no-console
console.debug('reconnected successfully!');
Expand Down Expand Up @@ -369,11 +375,11 @@ export class RobotClient extends EventDispatcher implements Robot {
return this.peerConn?.iceConnectionState === 'connected';
}

public async connect(
priority?: number,
public async connect({
priority,
authEntity = this.savedAuthEntity,
creds = this.savedCreds
) {
creds = this.savedCreds,
}: 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
8 changes: 6 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(undefined, conf.authEntity, creds);
await client.connect({ authEntity: conf.authEntity, creds: creds });

// eslint-disable-next-line no-console
console.debug('connected via gRPC');
Expand Down Expand Up @@ -121,7 +121,11 @@ const dialWebRTC = async (conf: DialWebRTCConf): Promise<RobotClient> => {
if (conf.credential) {
creds = conf.credential;
}
await client.connect(conf.priority, conf.authEntity || impliedURL, creds);
await client.connect({
priority: conf.priority,
authEntity: conf.authEntity || impliedURL,
creds: creds,
});

// eslint-disable-next-line no-console
console.debug('connected via WebRTC');
Expand Down

0 comments on commit 0269ef3

Please sign in to comment.