Skip to content

Commit 000e35a

Browse files
author
Aidan Zimmermann
committed
STREAM-599: fix codacy recs
1 parent 64c8ce6 commit 000e35a

8 files changed

Lines changed: 65 additions & 15 deletions

File tree

react-demo-app/src/components/AudioDevices.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function AudioDevices() {
3030
}
3131
>
3232
<GuxListbox>
33-
{deviceState.audioDevices.map((device: any) => (
33+
{deviceState.audioDevices.map((device: MediaDeviceInfo) => (
3434
<GuxOption key={device.deviceId} value={device.deviceId}>
3535
{device.label}
3636
</GuxOption>

react-demo-app/src/components/HandledPendingSessionsTable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { GuxTable } from 'genesys-spark-components-react';
22
import { useSelector } from 'react-redux';
33
import Card from './Card';
44
import { RootState } from '../types/store';
5+
import { IPendingSession } from 'genesys-cloud-webrtc-sdk';
56

67
export default function HandledPendingSessionsTable() {
78
const handledPendingSessions = useSelector(
@@ -23,7 +24,7 @@ export default function HandledPendingSessionsTable() {
2324
</tr>
2425
</thead>
2526
<tbody>
26-
{handledPendingSessions.map((convo: any) => (
27+
{handledPendingSessions.map((convo: IPendingSession) => (
2728
<tr key={convo.conversationId}>
2829
<td>{convo.conversationId}</td>
2930
<td>{convo.sessionId}</td>

react-demo-app/src/components/OutputDevices.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function OutputDevices() {
2020
}
2121
>
2222
<GuxListbox>
23-
{deviceState.outputDevices.map((device: any) => (
23+
{deviceState.outputDevices.map((device: MediaDeviceInfo) => (
2424
<GuxOption key={device.deviceId} value={device.deviceId}>
2525
{device.label}
2626
</GuxOption>

react-demo-app/src/components/PendingSessionsTable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GuxTable, GuxButton } from 'genesys-spark-components-react';
33
import { useSelector } from 'react-redux';
44
import Card from './Card';
55
import { RootState } from '../types/store';
6+
import { IPendingSession } from 'genesys-cloud-webrtc-sdk';
67

78
export default function PendingSessionsTable() {
89
const conversations = useSelector(
@@ -41,7 +42,7 @@ export default function PendingSessionsTable() {
4142
</tr>
4243
</thead>
4344
<tbody>
44-
{conversations.map((convo: any) => (
45+
{conversations.map((convo: IPendingSession) => (
4546
<tr key={convo.conversationId}>
4647
<td>{convo.conversationId}</td>
4748
<td>{convo.sessionId}</td>

react-demo-app/src/components/VideoDevices.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function VideoDevices() {
1818
}
1919
>
2020
<GuxListbox>
21-
{deviceState.videoDevices.map((device: any) => (
21+
{deviceState.videoDevices.map((device: MediaDeviceInfo) => (
2222
<GuxOption key={device.deviceId} value={device.deviceId}>
2323
{device.label}
2424
</GuxOption>

react-demo-app/src/features/sdkSlice.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2+
import { MinimalSdk } from '../types/sdk';
23

34
interface SdkState {
4-
sdk: any;
5+
sdk: MinimalSdk | null;
56
}
67

78
const initialState: SdkState = {
@@ -12,7 +13,7 @@ export const sdkSlice = createSlice({
1213
name: 'sdk',
1314
initialState: initialState,
1415
reducers: {
15-
setSdk: (state, action: PayloadAction<any>) => {
16+
setSdk: (state, action: PayloadAction<MinimalSdk>) => {
1617
state.sdk = action.payload;
1718
}
1819
}

react-demo-app/src/hooks/useSdk.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
SessionTypes,
66
ISessionIdAndConversationId,
77
SdkMediaStateWithType,
8-
ISdkGumRequest
8+
ISdkGumRequest,
9+
IExtendedMediaSession
910
} from 'genesys-cloud-webrtc-sdk';
1011
import { v4 } from 'uuid';
1112
import { useDispatch } from 'react-redux';
@@ -20,6 +21,7 @@ import { updateGumRequests, updateMediaState } from '../features/devicesSlice';
2021
import { useSelector } from 'react-redux';
2122
import { IPendingSession } from 'genesys-cloud-streaming-client';
2223
import { RootState } from '../types/store';
24+
import { MinimalSdk } from '../types/sdk';
2325

2426
interface IAuthData {
2527
token: string;
@@ -46,7 +48,7 @@ export default function useSdk() {
4648
};
4749

4850
webrtcSdk = new GenesysCloudWebrtcSdk(options);
49-
dispatch(setSdk(webrtcSdk));
51+
dispatch(setSdk(webrtcSdk as MinimalSdk));
5052

5153
connectEventHandlers();
5254

@@ -129,7 +131,7 @@ export default function useSdk() {
129131
dispatch(updateGumRequests());
130132
}
131133

132-
function updateDefaultDevices(options: any): void {
134+
function updateDefaultDevices(options: { audioDeviceId?: string; videoDeviceId?: string; outputDeviceId?: string }): void {
133135
if (!sdk) return;
134136
sdk.updateDefaultDevices({
135137
...options,
@@ -156,18 +158,19 @@ export default function useSdk() {
156158

157159
/* Misc Functions */
158160
async function updateOnQueueStatus(onQueue: boolean): Promise<void> {
159-
if (!sdk) return;
161+
if (!sdk || !sdk._http || !sdk._config || !sdk._personDetails) return;
160162
const systemPresences = await sdk._http.requestApi(`systempresences`, {
161163
method: 'get' as const,
162164
host: sdk._config.environment || '',
163165
authToken: sdk._config.accessToken
164166
});
165167

166168
let presenceDefinition;
169+
const presences = systemPresences.data as Array<{ name: string }>;
167170
if (onQueue) {
168-
presenceDefinition = systemPresences.data.find((p: { name: string; }) => p.name === 'ON_QUEUE')
171+
presenceDefinition = presences.find((p: { name: string; }) => p.name === 'ON_QUEUE')
169172
} else {
170-
presenceDefinition = systemPresences.data.find((p: { name: string; }) => p.name === 'AVAILABLE')
173+
presenceDefinition = presences.find((p: { name: string; }) => p.name === 'AVAILABLE')
171174
}
172175
const requestOptions = {
173176
method: 'patch' as const,
@@ -181,8 +184,8 @@ export default function useSdk() {
181184

182185
function disconnectPersistentConnection(): void {
183186
if (!sdk) return;
184-
const sessions = sdk.sessionManager.getAllActiveSessions().filter((session: any) => session.sessionType === SessionTypes.softphone);
185-
sessions.forEach((session: any) => sdk.forceTerminateSession(session.id));
187+
const sessions = sdk.sessionManager.getAllActiveSessions().filter((session: IExtendedMediaSession) => session.sessionType === SessionTypes.softphone);
188+
sessions.forEach((session: IExtendedMediaSession) => sdk.forceTerminateSession(session.id));
186189
}
187190

188191
return {

react-demo-app/src/types/sdk.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Minimal SDK interface for type safety
2+
import { IExtendedMediaSession } from 'genesys-cloud-webrtc-sdk';
3+
export interface MinimalSdk {
4+
startSoftphoneSession: (params: { phoneNumber: string }) => void;
5+
endSession: (params: { conversationId: string }) => void;
6+
setAudioMute: (params: { mute: boolean; conversationId: string }) => Promise<void>;
7+
setConversationHeld: (params: { held: boolean; conversationId: string }) => Promise<void>;
8+
updateDefaultDevices: (options: { audioDeviceId?: string; videoDeviceId?: string; outputDeviceId?: string; updateActiveSessions?: boolean }) => void;
9+
updateAudioVolume: (volume: number) => void;
10+
destroy: () => Promise<void>;
11+
acceptPendingSession: (params: { conversationId: string }) => void;
12+
rejectPendingSession: (params: { conversationId: string }) => void;
13+
forceTerminateSession: (sessionId: string) => void;
14+
media: {
15+
enumerateDevices: (force?: boolean) => void;
16+
requestMediaPermissions: (type: 'audio' | 'video' | 'both') => void;
17+
};
18+
sessionManager: {
19+
getAllActiveSessions: () => IExtendedMediaSession[];
20+
};
21+
station?: {
22+
webRtcPersistentEnabled?: boolean;
23+
name?: string;
24+
id?: string;
25+
status?: string;
26+
type?: string;
27+
webRtcCallAppearances?: number;
28+
webRtcForceTurn?: boolean;
29+
[key: string]: unknown;
30+
} | null;
31+
_config?: {
32+
environment?: string;
33+
accessToken?: string;
34+
defaults?: {
35+
audioVolume?: number;
36+
};
37+
};
38+
_http?: {
39+
requestApi: (endpoint: string, options: { method: 'get' | 'post' | 'patch' | 'put' | 'delete'; host: string; authToken?: string; data?: string }) => Promise<{ data: unknown }>;
40+
};
41+
_personDetails?: {
42+
id: string;
43+
};
44+
}

0 commit comments

Comments
 (0)