Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-cc): add agent logout #2

Closed
wants to merge 2 commits into from

Conversation

rarajes2
Copy link
Collaborator

@rarajes2 rarajes2 commented Oct 29, 2024

COMPLETES #< SPARK-558556 >

This pull request addresses

Adds the Agent Station Logout feature

by making the following changes

Agent is able to Logout from station.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios where tested

Tested the station logout on the samples page after logging in with Browser.

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

@@ -112,6 +112,7 @@ <h2 class="collapsible">
<input id="dialNumber" name="dialNumber" placeholder="Dial Number" value="" type="text">
<button id="loginAgent" disabled class="btn btn-primary my-3" onclick="doAgentLogin()">Login With
Selected Team</button>
<button id="logoutAgent" style="display: none;" class="btn btn-primary my-3 ml-2" onclick="logoutAgent()">Logout Agent</button>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using the already present 'hidden' class instead of display: none

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.webRTCCalling.deregisterWebCallingLine();
}

return response;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a log for the success case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.agent.stationLogout is already adding the success log. Adding here will add it twice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rarajes2 , In that case, let's remove the logs from catch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


try {
const response = await this.agentService.stationLogout({
logoutReason,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options param can be passed as is to agentService without the need for destructuring

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 71 to 73
eventType: 'Logout',
success: ['AgentLogoutSuccess'],
failure: ['AgentLogoutFailed'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings can be constants

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -236,3 +236,16 @@ export type SubscribeResponse = {
};
message: string | null;
};

export interface LogoutSuccess {
eventType: 'AgentDesktopMessage';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a constant for this string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

subStatus: string;
loggedOutBy?: string;
roles?: string[];
type: 'AgentLogoutSuccess';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a constant for this string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rarajes2 rarajes2 force-pushed the station-logout-cc branch 2 times, most recently from d09dc17 to e8da707 Compare October 30, 2024 08:39

return response;
} catch (error) {
return Promise.reject(error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add log for failures

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@arun3528 arun3528 force-pushed the AgentLogin branch 2 times, most recently from 2ece117 to ac5285e Compare October 31, 2024 13:30
export const AgentDesktopMessage = 'AgentDesktopMessage';

export const LOGOUT_EVENT = 'Logout';
export const AgentLogoutSuccessEvent = 'AgentLogoutSuccess';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant names should be in caps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -56,4 +65,28 @@ export default class AgentService {
return Promise.reject(error);
}
}

public async stationLogout(options: {logoutReason: string}): Promise<LogoutSuccess> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value should be generic right, either the promise resolves or rejects indicating success or failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


public async stationLogout(options: {logoutReason: string}): Promise<LogoutSuccess> {
try {
const response = await this.agentService.stationLogout(options);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 4xx or 5xx failure occurs, don't we need to handle that and reject promise

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, now all the logic is in the service, this function simply calls it and returns. It's just one liner now

public async stationLogout(options: {logoutReason: string}): Promise<LogoutSuccess> {
try {
const response = await this.agentService.stationLogout(options);
this.webex.logger.log('Logout API SUCCESS');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to say Logout Success and Logout Failure. We don't need to add API in the log messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -34,4 +34,15 @@ export default class Agent {
return Promise.reject(new Error('Error while performing agent login', error));
}
}

public async stationLogout(options: {logoutReason: string}): Promise<LogoutSuccess> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it data instead of options

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


describe('#stationLogout', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have tests added for changes in the cc.ts file as well and the same goes for AgentService.ts. And we should cover the failure response test case also

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for cc and AgentService. Removed tests from Agent as it's one liner now.

@Kesari3008
Copy link

Kesari3008 commented Nov 4, 2024

Build seems to be failing with below error:
[@webex/plugin-cc]: src/WebRTCCalling.ts(8,8): error TS2307: Cannot find module '@webex/calling' or its corresponding type declarations.

Is this being taken care in any of the PRs?

Please add manual testing details in the PR description

Copy link

@Kesari3008 Kesari3008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with few comments. Please ensure to address these comments before merge
Screenshot 2024-11-07 at 8 37 14 PM
Even when logout was successful, timeout error is printing. Please fix this in sample app

export const AgentDesktopMessage = 'AgentDesktopMessage';

export const LOGOUT_EVENT = 'Logout';
export const AGENT_LOGOUT_SUCCESS_EVENT = 'AgentLogoutSuccess';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be moved within CC_EVENTS itself but check with Ravi if we would even need CC_EVENTS enum since we are moving the aqm code


return response;
} catch (error) {
this.webex.logger.error(`Station logout failed: ${error}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need to have a try-catch block here? I believe we can just return response as it is that we get from httpRequest.sendRequestWithEvent()

* @returns Promise<LogoutSuccess>
* @throws Error
*/
public async stationLogout(data: {logoutReason: string}): Promise<StationLogoutResponse> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a type for {logoutReason: string} as Logout similar and use that eveyrwhere

}

return response;
} catch (error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need this catch block? I believe return response should suffice

@rarajes2
Copy link
Collaborator Author

Closing as this PR changes has been taken in Ravi's PR.

@rarajes2 rarajes2 closed this Nov 12, 2024
rarajes2 pushed a commit that referenced this pull request Nov 13, 2024
* feat(cc-sdk): ported-code-for-health-check

* feat(cc-sdk): fixed-broken-tests

* feat(cc-sdk): fixed-blob-issue

* feat(cc-sdk): merged-with-ravi-pr

* feat(cc-sdk): re-added-cc-code

* feat(cc-sdk): added-logger-proxy

* feat(cc-sdk): added-config-values

* feat(cc-sdk): added-connection-instance

* feat(cc-sdk): added-event-listeners-instead-of-signals

* feat(cc-sdk): fixed-broken-tests

* feat(cc-sdk): fixed-test-coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants