Skip to content

Commit 3034273

Browse files
millerxcodacy-production[bot]
authored andcommitted
[STREAM-151] Codacy any -> unknown
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
1 parent 1715ee5 commit 3034273

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/stats-aggregator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,6 @@ export class StatsAggregator {
229229

230230
this.sdk.logger.debug('Sending stats over XMPP');
231231
this.sdk._streamingConnection._webrtcSessions.sendIq(iq)
232-
.catch((err: any) => this.sdk.logger.warn('Failed to send stats via XMPP', err));
232+
.catch((err: unknown) => this.sdk.logger.warn('Failed to send stats via XMPP', err));
233233
}
234234
}

test/unit/stats-aggregator.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('StatsAggregator', () => {
1414
describe('shouldGatherImmediately / eager persistent connection', () => {
1515
it('should not start gathering stats immediately for eager persistent connections (privAnswerMode === Auto)', () => {
1616
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
17-
(mockSession as any).privAnswerMode = 'Auto';
17+
(mockSession as unknown as Record<string, unknown>).privAnswerMode = 'Auto';
1818
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
1919
const statsAggregator = new StatsAggregator(mockSession, sdk);
2020

@@ -24,7 +24,7 @@ describe('StatsAggregator', () => {
2424

2525
it('should start gathering stats immediately for non-eager sessions', () => {
2626
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
27-
(mockSession as any).privAnswerMode = 'Manual';
27+
(mockSession as unknown as Record<string, unknown>).privAnswerMode = 'Manual';
2828
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
2929
const statsAggregator = new StatsAggregator(mockSession, sdk);
3030

@@ -35,27 +35,27 @@ describe('StatsAggregator', () => {
3535
describe('onSessionStarted', () => {
3636
it('should start gathering stats and set baseline when the matching session starts', () => {
3737
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
38-
(mockSession as any).privAnswerMode = 'Auto';
38+
(mockSession as unknown as Record<string, unknown>).privAnswerMode = 'Auto';
3939
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
4040
const statsAggregator = new StatsAggregator(mockSession, sdk);
4141

4242
expect(statsAggregator['statsGatherer']).toBeFalsy();
4343

4444
// Emit sessionStarted with the same session
45-
(sdk as any).emit('sessionStarted', mockSession);
45+
(sdk as unknown as SimpleMockSdk).emit('sessionStarted', mockSession);
4646

4747
expect(statsAggregator['statsGatherer']).toBeTruthy();
4848
expect(statsAggregator['setBaseline']).toBe(true);
4949
});
5050

5151
it('should not start gathering stats for a different session', () => {
5252
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
53-
(mockSession as any).privAnswerMode = 'Auto';
53+
(mockSession as unknown as Record<string, unknown>).privAnswerMode = 'Auto';
5454
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
5555
const statsAggregator = new StatsAggregator(mockSession, sdk);
5656

5757
const otherSession = new MockSession() as unknown as IExtendedMediaSession;
58-
(sdk as any).emit('sessionStarted', otherSession);
58+
(sdk as unknown as SimpleMockSdk).emit('sessionStarted', otherSession);
5959

6060
expect(statsAggregator['statsGatherer']).toBeFalsy();
6161
});
@@ -69,7 +69,7 @@ describe('StatsAggregator', () => {
6969

7070
expect(statsAggregator['statsGatherer']).toBeTruthy();
7171

72-
(sdk as any).emit('sessionEnded', mockSession);
72+
(sdk as unknown as SimpleMockSdk).emit('sessionEnded', mockSession);
7373

7474
expect(statsAggregator['statsGatherer']).toBeFalsy();
7575
});
@@ -80,7 +80,7 @@ describe('StatsAggregator', () => {
8080
const statsAggregator = new StatsAggregator(mockSession, sdk);
8181

8282
const otherSession = new MockSession() as unknown as IExtendedMediaSession;
83-
(sdk as any).emit('sessionEnded', otherSession);
83+
(sdk as unknown as SimpleMockSdk).emit('sessionEnded', otherSession);
8484

8585
expect(statsAggregator['statsGatherer']).toBeTruthy();
8686
});
@@ -94,13 +94,13 @@ describe('StatsAggregator', () => {
9494

9595
expect(statsAggregator['statsGatherer']).toBeTruthy();
9696

97-
const listenerCountBefore = (sdk as any).listenerCount('sessionStarted');
97+
const listenerCountBefore = (sdk as unknown as SimpleMockSdk).listenerCount('sessionStarted');
9898

99-
(mockSession as any).emit('terminated');
99+
(mockSession as unknown as MockSession).emit('terminated');
100100

101101
expect(statsAggregator['statsGatherer']).toBeFalsy();
102102
// SDK listeners for sessionStarted/sessionEnded should be removed
103-
expect((sdk as any).listenerCount('sessionStarted')).toBe(listenerCountBefore - 1);
103+
expect((sdk as unknown as SimpleMockSdk).listenerCount('sessionStarted')).toBe(listenerCountBefore - 1);
104104
});
105105
});
106106

@@ -331,7 +331,7 @@ describe('StatsAggregator', () => {
331331
it('should call sendIq with correct IQ stanza', () => {
332332
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
333333
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
334-
const sendIqMock = (sdk as any)._streamingConnection._webrtcSessions.sendIq;
334+
const sendIqMock = (sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions.sendIq;
335335
const statsAggregator = new StatsAggregator(mockSession, sdk);
336336
const rtpStats = {
337337
packetsReceived: 5,
@@ -341,7 +341,7 @@ describe('StatsAggregator', () => {
341341
const participant = {
342342
calls: [{ id: 'testCall' }]
343343
};
344-
mockSession.pcParticipant = participant as any;
344+
(mockSession as unknown as MockSession).pcParticipant = participant;
345345

346346
statsAggregator['sendStats'](rtpStats, new Date());
347347

@@ -362,7 +362,7 @@ describe('StatsAggregator', () => {
362362
it('should not call sendIq if there is no participant', () => {
363363
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
364364
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
365-
const sendIqMock = (sdk as any)._streamingConnection._webrtcSessions.sendIq;
365+
const sendIqMock = (sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions.sendIq;
366366
const statsAggregator = new StatsAggregator(mockSession, sdk);
367367
const rtpStats = {
368368
packetsReceived: 5,
@@ -378,7 +378,7 @@ describe('StatsAggregator', () => {
378378
it('should not call sendIq if there are no calls for the participant', () => {
379379
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
380380
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
381-
const sendIqMock = (sdk as any)._streamingConnection._webrtcSessions.sendIq;
381+
const sendIqMock = (sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions.sendIq;
382382
const statsAggregator = new StatsAggregator(mockSession, sdk);
383383
const rtpStats = {
384384
packetsReceived: 5,
@@ -387,28 +387,28 @@ describe('StatsAggregator', () => {
387387
};
388388

389389
const participantA = { calls: [] };
390-
mockSession.pcParticipant = participantA as any;
390+
(mockSession as unknown as MockSession).pcParticipant = participantA;
391391
statsAggregator['sendStats'](rtpStats, new Date());
392392
expect(sendIqMock).not.toHaveBeenCalled();
393393

394394
const participantB = {};
395-
mockSession.pcParticipant = participantB as any;
395+
(mockSession as unknown as MockSession).pcParticipant = participantB;
396396
statsAggregator['sendStats'](rtpStats, new Date());
397397
expect(sendIqMock).not.toHaveBeenCalled();
398398
});
399399

400400
it('should not call sendIq if session.peerID is falsy', () => {
401401
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
402-
(mockSession as any).peerID = '';
402+
(mockSession as unknown as MockSession).peerID = '';
403403
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
404-
const sendIqMock = (sdk as any)._streamingConnection._webrtcSessions.sendIq;
404+
const sendIqMock = (sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions.sendIq;
405405
const statsAggregator = new StatsAggregator(mockSession, sdk);
406406
const rtpStats = {
407407
packetsReceived: 5,
408408
averageJitter: 0.1,
409409
estimatedAverageMos: 5
410410
};
411-
mockSession.pcParticipant = { calls: [{ id: 'testCall' }] } as any;
411+
(mockSession as unknown as MockSession).pcParticipant = { calls: [{ id: 'testCall' }] };
412412

413413
statsAggregator['sendStats'](rtpStats, new Date());
414414

@@ -418,14 +418,14 @@ describe('StatsAggregator', () => {
418418
it('should not throw when streaming connection webrtcSessions is unavailable', () => {
419419
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
420420
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
421-
(sdk as any)._streamingConnection._webrtcSessions = null;
421+
(sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions = null as unknown as SimpleMockSdk['_streamingConnection']['_webrtcSessions'];
422422
const statsAggregator = new StatsAggregator(mockSession, sdk);
423423
const rtpStats = {
424424
packetsReceived: 5,
425425
averageJitter: 0.1,
426426
estimatedAverageMos: 5
427427
};
428-
mockSession.pcParticipant = { calls: [{ id: 'testCall' }] } as any;
428+
(mockSession as unknown as MockSession).pcParticipant = { calls: [{ id: 'testCall' }] };
429429

430430
expect(() => {
431431
statsAggregator['sendStats'](rtpStats, new Date());
@@ -435,14 +435,14 @@ describe('StatsAggregator', () => {
435435
it('should catch sendIq rejection and log a warning', async () => {
436436
const mockSession = new MockSession() as unknown as IExtendedMediaSession;
437437
const sdk = new SimpleMockSdk() as unknown as GenesysCloudWebrtSdk;
438-
(sdk as any)._streamingConnection._webrtcSessions.sendIq = jest.fn().mockRejectedValue(new Error('XMPP error'));
438+
(sdk as unknown as SimpleMockSdk)._streamingConnection._webrtcSessions.sendIq = jest.fn().mockRejectedValue(new Error('XMPP error'));
439439
const statsAggregator = new StatsAggregator(mockSession, sdk);
440440
const rtpStats = {
441441
packetsReceived: 5,
442442
averageJitter: 0.1,
443443
estimatedAverageMos: 5
444444
};
445-
mockSession.pcParticipant = { calls: [{ id: 'testCall' }] } as any;
445+
(mockSession as unknown as MockSession).pcParticipant = { calls: [{ id: 'testCall' }] };
446446

447447
statsAggregator['sendStats'](rtpStats, new Date());
448448

0 commit comments

Comments
 (0)