Skip to content

Commit

Permalink
fix: addressed comments to use enums
Browse files Browse the repository at this point in the history
  • Loading branch information
rsarika committed Nov 11, 2024
1 parent bc4b930 commit 010d4d9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
8 changes: 4 additions & 4 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
StationLogoutResponse,
StationReLoginResponse,
} from './types';
import {READY, CC_FILE} from './constants';
import {READY, CC_FILE, EMPTY_STRING} from './constants';
import HttpRequest from './services/core/HttpRequest';
import WebCallingService from './services/WebCallingService';
import {AGENT, WEB_RTC_PREFIX} from './services/constants';
Expand Down Expand Up @@ -123,10 +123,10 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
deviceId: this.getDeviceId(data.loginOption, data.dialNumber),
roles: [AGENT],
// TODO: The public API should not have the following properties so filling them with empty values for now. If needed, we can add them in the future.
teamName: '',
siteId: '',
teamName: EMPTY_STRING,
siteId: EMPTY_STRING,
usesOtherDN: false,
auxCodeId: '',
auxCodeId: EMPTY_STRING,
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/@webex/plugin-cc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const EVENT = 'event';
export const READY = 'ready';
export const CC_FILE = 'cc';
export const TIMEOUT_DURATION = 20000; // 20 seconds timeout duration for webrtc registration
export const EMPTY_STRING = '';
33 changes: 17 additions & 16 deletions packages/@webex/plugin-cc/src/services/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Agent from './types';
import AqmReqs from '../core/aqm-reqs';
import {HTTP_METHODS} from '../../types';
import {WCC_API_GATEWAY} from '../constants';
import {CC_EVENTS} from '../config/types';

/*
* routingAgent
Expand All @@ -20,15 +21,15 @@ export default function routingAgent(routing: AqmReqs) {
err,
notifSuccess: {
bind: {
type: 'AgentReloginSuccess',
data: {type: 'AgentReloginSuccess'},
type: CC_EVENTS.AGENT_RELOGIN_SUCCESS,
data: {type: CC_EVENTS.AGENT_RELOGIN_SUCCESS},
},
msg: {} as Agent.ReloginSuccess,
},
notifFail: {
bind: {
type: 'AgentReloginFailed',
data: {type: 'AgentReloginFailed'},
type: CC_EVENTS.AGENT_RELOGIN_FAILED,
data: {type: CC_EVENTS.AGENT_RELOGIN_FAILED},
},
errId: 'Service.aqm.agent.reload',
},
Expand All @@ -40,15 +41,15 @@ export default function routingAgent(routing: AqmReqs) {
err,
notifSuccess: {
bind: {
type: 'Logout',
data: {type: 'AgentLogoutSuccess'},
type: CC_EVENTS.AGENT_LOGOUT,
data: {type: CC_EVENTS.AGENT_LOGOUT_SUCCESS},
},
msg: {} as Agent.LogoutSuccess,
},
notifFail: {
bind: {
type: 'Logout',
data: {type: 'AgentLogoutFailed'},
type: CC_EVENTS.AGENT_LOGOUT,
data: {type: CC_EVENTS.AGENT_LOGOUT_FAILED},
},
errId: 'Service.aqm.agent.logout',
},
Expand All @@ -65,15 +66,15 @@ export default function routingAgent(routing: AqmReqs) {
}),
notifSuccess: {
bind: {
type: 'StationLogin',
data: {type: 'AgentStationLoginSuccess'},
type: CC_EVENTS.AGENT_STATION_LOGIN,
data: {type: CC_EVENTS.AGENT_STATION_LOGIN_SUCCESS},
},
msg: {} as Agent.StationLoginSuccess,
},
notifFail: {
bind: {
type: 'StationLogin',
data: {type: 'AgentStationLoginFailed'},
type: CC_EVENTS.AGENT_STATION_LOGIN,
data: {type: CC_EVENTS.AGENT_STATION_LOGIN_FAILED},
},
errId: 'Service.aqm.agent.stationLoginFailed',
},
Expand All @@ -86,15 +87,15 @@ export default function routingAgent(routing: AqmReqs) {
method: HTTP_METHODS.PUT,
notifSuccess: {
bind: {
type: 'AgentStateChange',
data: {type: 'AgentStateChangeSuccess'},
type: CC_EVENTS.AGENT_STATE_CHANGE,
data: {type: CC_EVENTS.AGENT_STATE_CHANGE_SUCCESS},
},
msg: {} as Agent.StateChangeSuccess,
},
notifFail: {
bind: {
type: 'AgentStateChange',
data: {type: 'AgentStateChangeFailed'},
type: CC_EVENTS.AGENT_STATE_CHANGE,
data: {type: CC_EVENTS.AGENT_STATE_CHANGE_FAILED},
},
errId: 'Service.aqm.agent.stateChange',
},
Expand Down
23 changes: 19 additions & 4 deletions packages/@webex/plugin-cc/src/services/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import {AuxCode} from '../../types';
import {AuxCode, WelcomeEvent} from '../../types';
import * as Agent from '../agent/types';

type Enum<T extends Record<string, unknown>> = T[keyof T];

// Define the CC_EVENTS object
export const CC_EVENTS = {
WELCOME: 'Welcome',
AGENT_RELOGIN_SUCCESS: 'AgentReloginSuccess',
AGENT_RELOGIN_FAILED: 'AgentReloginFailed',
AGENT_LOGOUT: 'Logout',
AGENT_LOGOUT_SUCCESS: 'AgentLogoutSuccess',
AGENT_LOGOUT_FAILED: 'AgentLogoutFailed',
AGENT_STATION_LOGIN: 'StationLogin',
AGENT_STATION_LOGIN_SUCCESS: 'AgentStationLoginSuccess',
AGENT_STATION_LOGIN_FAILED: 'AgentStationLoginFailed',
AGENT_STATE_CHANGE: 'AgentStateChange',
AGENT_STATE_CHANGE_SUCCESS: 'AgentStateChangeSuccess',
AGENT_STATE_CHANGE_FAILED: 'AgentStateChangeFailed',
} as const;

// Derive the type using the utility type
export type CC_EVENTS = Enum<typeof CC_EVENTS>;

export type WebSocketEvent = {
type: CC_EVENTS;
data: {
agentId: string;
};
data:
| WelcomeEvent
| Agent.StationLoginSuccess
| Agent.LogoutSuccess
| Agent.ReloginSuccess
| Agent.StateChangeSuccess;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/@webex/plugin-cc/src/services/core/HttpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IHttpResponse,
WelcomeResponse,
WelcomeEvent,
RequestBody,
} from '../../types';
import IWebSocket from '../WebSocket/types';
import WebSocket from '../WebSocket';
Expand Down Expand Up @@ -89,7 +90,7 @@ class HttpRequest {
service: string;
resource: string;
method: HTTP_METHODS;
body?: object;
body?: RequestBody;
}): Promise<IHttpResponse> {
const {service, resource, method, body} = options;

Expand Down
4 changes: 2 additions & 2 deletions packages/@webex/plugin-cc/src/services/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HTTP_METHODS, WebexRequestPayload} from '../../types';
import {HTTP_METHODS, RequestBody, WebexRequestPayload} from '../../types';
import * as Err from './Err';
import {Msg} from './GlobalTypes';

Expand Down Expand Up @@ -35,7 +35,7 @@ export type Req<TRes, TErr> = {
bind: Bind;
errId: Err.IdsDetails;
};
data?: any;
data?: RequestBody;
headers?: Record<string, string>;
timeout?: Timeout;
notifCancel?: {bind: Bind; msg: TRes};
Expand Down
5 changes: 5 additions & 0 deletions packages/@webex/plugin-cc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ export type AgentLogin = {

loginOption: LoginOption;
};
export type RequestBody =
| SubscribeRequest
| Agent.Logout
| Agent.UserStationLogin
| Agent.StateChange;

export type StationLoginResponse = Agent.StationLoginSuccess | Error;
export type StationLogoutResponse = Agent.LogoutSuccess | Error;
Expand Down

0 comments on commit 010d4d9

Please sign in to comment.