Skip to content

Commit 1449855

Browse files
authored
Fix ice candidate proto to webrtc interface conversion (#386)
1 parent 72b8298 commit 1449855

13 files changed

+77
-47
lines changed

.eslintrc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ module.exports = {
3030
'@typescript-eslint/no-explicit-any': 'warn',
3131
'@typescript-eslint/prefer-promise-reject-errors': 'warn',
3232
'unicorn/prefer-add-event-listener': 'warn',
33+
'@typescript-eslint/strict-boolean-expressions': [
34+
'error',
35+
{
36+
allowNullableBoolean: true,
37+
},
38+
],
3339
},
3440
overrides: [
3541
{

playwright.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ export default defineConfig({
44
testDir: 'e2e/tests',
55
outputDir: 'e2e/artifacts',
66
forbidOnly: Boolean(process.env.CI),
7-
retries: process.env.CI ? 1 : 0,
8-
workers: process.env.CI ? 1 : 3,
7+
retries: process.env.CI === undefined ? 0 : 1,
8+
workers: process.env.CI === undefined ? 3 : 1,
99
reporter: [['html', { open: 'never' }]],
1010
use: {
1111
baseURL: 'http://localhost:5173',
12-
trace: process.env.CI ? 'on-first-retry' : 'retain-on-failure',
12+
trace:
13+
process.env.CI === undefined ? 'retain-on-failure' : 'on-first-retry',
1314
},
1415

1516
projects: [

src/app/data-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class DataClient {
113113
) {
114114
const dataReq = {
115115
filter,
116-
limit: limit ? BigInt(limit) : undefined,
116+
limit: limit === undefined ? undefined : BigInt(limit),
117117
sortOrder,
118118
last,
119119
};
@@ -185,7 +185,7 @@ export class DataClient {
185185
) {
186186
const dataReq = {
187187
filter,
188-
limit: limit ? BigInt(limit) : undefined,
188+
limit: limit === undefined ? undefined : BigInt(limit),
189189
sortOrder,
190190
last,
191191
};

src/app/viam-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class ViamClient {
7777
locationId = mainPart.locationId;
7878
}
7979

80-
if (!address) {
80+
if (address === undefined || address === '') {
8181
throw new Error(
8282
'Host was not provided and could not be obtained from the machine ID'
8383
);

src/robot/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class RobotClient extends EventDispatcher implements Robot {
196196
private onDisconnect(event?: Event) {
197197
this.emit(MachineConnectionEvent.DISCONNECTED, event ?? {});
198198

199-
if (this.noReconnect) {
199+
if (this.noReconnect !== undefined && this.noReconnect) {
200200
return;
201201
}
202202

@@ -220,10 +220,10 @@ export class RobotClient extends EventDispatcher implements Robot {
220220
return true;
221221
},
222222
};
223-
if (this.reconnectMaxWait) {
223+
if (this.reconnectMaxWait !== undefined) {
224224
backOffOpts.maxDelay = this.reconnectMaxWait;
225225
}
226-
if (this.reconnectMaxAttempts) {
226+
if (this.reconnectMaxAttempts !== undefined) {
227227
backOffOpts.numOfAttempts = this.reconnectMaxAttempts;
228228
}
229229
void backOff(async () => this.connect(), backOffOpts)

src/robot/dial.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ export const createRobotClient = async (
173173
return !conf.reconnectAbortSignal?.abort;
174174
},
175175
};
176-
if (conf.reconnectMaxWait) {
176+
if (conf.reconnectMaxWait !== undefined) {
177177
backOffOpts.maxDelay = conf.reconnectMaxWait;
178178
}
179-
if (conf.reconnectMaxAttempts) {
179+
if (conf.reconnectMaxAttempts !== undefined) {
180180
backOffOpts.numOfAttempts = conf.reconnectMaxAttempts;
181181
}
182182

@@ -221,12 +221,15 @@ const validateDialConf = (conf: DialConf) => {
221221
}
222222
}
223223

224-
if (conf.reconnectMaxAttempts && !isPosInt(conf.reconnectMaxAttempts)) {
224+
if (
225+
conf.reconnectMaxAttempts !== undefined &&
226+
!isPosInt(conf.reconnectMaxAttempts)
227+
) {
225228
throw new Error(
226229
`Value of max reconnect attempts (${conf.reconnectMaxAttempts}) should be a positive integer`
227230
);
228231
}
229-
if (conf.reconnectMaxWait && !isPosInt(conf.reconnectMaxWait)) {
232+
if (conf.reconnectMaxWait !== undefined && !isPosInt(conf.reconnectMaxWait)) {
230233
throw new Error(
231234
`Value of max reconnect wait (${conf.reconnectMaxWait}) should be a positive integer`
232235
);

src/robot/grpc-connection-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class GRPCConnectionManager {
4444
};
4545

4646
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
47-
if (window.Worker) {
47+
if (globalThis.Worker !== undefined) {
4848
const url = window.URL.createObjectURL(timeoutBlob);
4949
worker = new Worker(url);
5050
URL.revokeObjectURL(url);

src/robot/session-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class SessionManager {
104104
* case in the future we make this toggleable (e.g. foreground).
105105
*/
106106
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
107-
if (this.backgroundHeartbeat && globalThis.Worker) {
107+
if (this.backgroundHeartbeat && globalThis.Worker !== undefined) {
108108
const url = window.URL.createObjectURL(timeoutBlob);
109109
worker = new Worker(url);
110110
URL.revokeObjectURL(url);

src/rpc/dial.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,24 @@ export const dialDirect = async (
115115

116116
// Client already has access token with no external auth, skip Authenticate process.
117117
if (
118-
opts?.accessToken &&
119-
!(opts.externalAuthAddress && opts.externalAuthToEntity)
118+
opts?.accessToken !== undefined &&
119+
opts.accessToken !== '' &&
120+
!(
121+
opts.externalAuthAddress !== undefined &&
122+
opts.externalAuthAddress !== '' &&
123+
opts.externalAuthToEntity !== undefined &&
124+
opts.externalAuthToEntity !== ''
125+
)
120126
) {
121127
const headers = new Headers(opts.extraHeaders);
122128
headers.set('authorization', `Bearer ${opts.accessToken}`);
123129
return new AuthenticatedTransport(transportOpts, createTransport, headers);
124130
}
125131

126-
if (!opts || (!opts.credentials && !opts.accessToken)) {
132+
if (
133+
opts === undefined ||
134+
(opts.credentials === undefined && opts.accessToken === undefined)
135+
) {
127136
return createTransport(transportOpts);
128137
}
129138

@@ -146,7 +155,7 @@ const makeAuthenticatedTransport = async (
146155
const authHeaders = new Headers(opts.extraHeaders);
147156

148157
let accessToken;
149-
if (!opts.accessToken || opts.accessToken === '') {
158+
if (opts.accessToken === undefined || opts.accessToken === '') {
150159
const request = new AuthenticateRequest({
151160
entity:
152161
isCredential(opts.credentials) && opts.credentials.authEntity
@@ -169,7 +178,12 @@ const makeAuthenticatedTransport = async (
169178
accessToken = opts.accessToken;
170179
}
171180

172-
if (opts.externalAuthAddress && opts.externalAuthToEntity) {
181+
if (
182+
opts.externalAuthAddress !== undefined &&
183+
opts.externalAuthAddress !== '' &&
184+
opts.externalAuthToEntity !== undefined &&
185+
opts.externalAuthToEntity !== ''
186+
) {
173187
const extAuthHeaders = new Headers();
174188
extAuthHeaders.set('authorization', `Bearer ${accessToken}`);
175189

@@ -385,7 +399,7 @@ export const dialWebRTC = async (
385399
);
386400
try {
387401
// set timeout for dial attempt if a timeout is specified
388-
if (dialOpts?.dialTimeout) {
402+
if (dialOpts?.dialTimeout !== undefined) {
389403
setTimeout(() => {
390404
if (!successful) {
391405
exchange.terminate();
@@ -395,10 +409,13 @@ export const dialWebRTC = async (
395409

396410
const cc = await exchange.doExchange();
397411

398-
if (dialOpts?.externalAuthAddress) {
412+
if (
413+
dialOpts?.externalAuthAddress !== undefined &&
414+
dialOpts.externalAuthAddress !== ''
415+
) {
399416
// TODO(GOUT-11): prepare AuthenticateTo here for client channel.
400417
// eslint-disable-next-line sonarjs/no-duplicated-branches
401-
} else if (dialOpts?.credentials?.type) {
418+
} else if (dialOpts?.credentials?.type !== undefined) {
402419
// TODO(GOUT-11): prepare Authenticate here for client channel
403420
}
404421

@@ -477,14 +494,16 @@ const processSignalingExchangeOpts = (
477494
if (dialOpts) {
478495
optsCopy = { ...dialOpts } as DialOptions;
479496

480-
if (!dialOpts.accessToken) {
497+
if (dialOpts.accessToken === undefined) {
481498
if (
482499
isCredential(optsCopy.credentials) &&
483500
!optsCopy.credentials.authEntity
484501
) {
485-
optsCopy.credentials.authEntity = optsCopy.externalAuthAddress
486-
? optsCopy.externalAuthAddress.replace(addressCleanupRegex, '')
487-
: signalingAddress.replace(addressCleanupRegex, '');
502+
optsCopy.credentials.authEntity =
503+
optsCopy.externalAuthAddress !== undefined &&
504+
optsCopy.externalAuthAddress !== ''
505+
? optsCopy.externalAuthAddress.replace(addressCleanupRegex, '')
506+
: signalingAddress.replace(addressCleanupRegex, '');
488507
}
489508
optsCopy.credentials = dialOpts.webrtcOptions?.signalingCredentials;
490509
optsCopy.accessToken = dialOpts.webrtcOptions?.signalingAccessToken;
@@ -504,18 +523,18 @@ const validateDialOptions = (opts?: DialOptions) => {
504523
return;
505524
}
506525

507-
if (opts.accessToken && opts.accessToken.length > 0) {
526+
if (opts.accessToken !== undefined && opts.accessToken.length > 0) {
508527
if (opts.credentials) {
509528
throw new Error('cannot set credentials with accessToken');
510529
}
511530

512-
if (opts.webrtcOptions) {
513-
if (opts.webrtcOptions.signalingAccessToken) {
531+
if (opts.webrtcOptions !== undefined) {
532+
if (opts.webrtcOptions.signalingAccessToken !== undefined) {
514533
throw new Error(
515534
'cannot set webrtcOptions.signalingAccessToken with accessToken'
516535
);
517536
}
518-
if (opts.webrtcOptions.signalingCredentials) {
537+
if (opts.webrtcOptions.signalingCredentials !== undefined) {
519538
throw new Error(
520539
'cannot set webrtcOptions.signalingCredentials with accessToken'
521540
);
@@ -524,9 +543,9 @@ const validateDialOptions = (opts?: DialOptions) => {
524543
}
525544

526545
if (
527-
opts.webrtcOptions?.signalingAccessToken &&
546+
opts.webrtcOptions?.signalingAccessToken !== undefined &&
528547
opts.webrtcOptions.signalingAccessToken.length > 0 &&
529-
opts.webrtcOptions.signalingCredentials
548+
opts.webrtcOptions.signalingCredentials !== undefined
530549
) {
531550
throw new Error(
532551
'cannot set webrtcOptions.signalingCredentials with webrtcOptions.signalingAccessToken'

src/rpc/signaling-exchange.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ export class SignalingExchange {
242242
try {
243243
await this.pc.addIceCandidate(cand);
244244
} catch (error) {
245+
console.log('error adding ice candidate', error); // eslint-disable-line no-console
245246
await this.sendError(JSON.stringify(error));
246-
return false;
247+
throw error;
247248
}
248249

249250
return true;
@@ -263,7 +264,7 @@ export class SignalingExchange {
263264
return;
264265
}
265266

266-
if (!this.callUuid) {
267+
if (this.callUuid === undefined || this.callUuid === '') {
267268
throw new Error(callUUIDUnset);
268269
}
269270

@@ -307,7 +308,7 @@ export class SignalingExchange {
307308
if (this.sentDoneOrErrorOnce) {
308309
return;
309310
}
310-
if (!this.callUuid) {
311+
if (this.callUuid === undefined || this.callUuid === '') {
311312
throw new Error(callUUIDUnset);
312313
}
313314
this.sentDoneOrErrorOnce = true;
@@ -337,7 +338,7 @@ export class SignalingExchange {
337338
if (this.sentDoneOrErrorOnce) {
338339
return;
339340
}
340-
if (!this.callUuid) {
341+
if (this.callUuid === undefined || this.callUuid === '') {
341342
throw new Error(callUUIDUnset);
342343
}
343344
this.sentDoneOrErrorOnce = true;
@@ -365,30 +366,30 @@ const iceCandidateFromProto = (i: ICECandidate) => {
365366
const candidate: RTCIceCandidateInit = {
366367
candidate: i.candidate,
367368
};
368-
if (i.sdpMid) {
369+
if (i.sdpMid !== undefined) {
369370
candidate.sdpMid = i.sdpMid;
370371
}
371-
if (i.sdpmLineIndex) {
372+
if (i.sdpmLineIndex !== undefined) {
372373
candidate.sdpMLineIndex = i.sdpmLineIndex;
373374
}
374-
if (i.usernameFragment) {
375+
if (i.usernameFragment !== undefined) {
375376
candidate.usernameFragment = i.usernameFragment;
376377
}
377378
return candidate;
378379
};
379380

380381
const iceCandidateToProto = (i: RTCIceCandidateInit) => {
381382
const candidate = new ICECandidate();
382-
if (i.candidate) {
383+
if (i.candidate !== undefined) {
383384
candidate.candidate = i.candidate;
384385
}
385-
if (i.sdpMid) {
386+
if (i.sdpMid !== undefined && i.sdpMid !== null) {
386387
candidate.sdpMid = i.sdpMid;
387388
}
388-
if (i.sdpMLineIndex) {
389+
if (i.sdpMLineIndex !== undefined && i.sdpMLineIndex !== null) {
389390
candidate.sdpmLineIndex = i.sdpMLineIndex;
390391
}
391-
if (i.usernameFragment) {
392+
if (i.usernameFragment !== undefined && i.usernameFragment !== null) {
392393
candidate.usernameFragment = i.usernameFragment;
393394
}
394395
return candidate;

0 commit comments

Comments
 (0)