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: WxCC SDK Subscribe Notifications and establish Mercury Connection #3909

Merged
merged 28 commits into from
Oct 23, 2024

Conversation

rsarika
Copy link
Contributor

@rsarika rsarika commented Oct 11, 2024

COMPLETES #https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-558547

This pull request addresses

The changes in this PR addresses the code to subscribe notifications and establish mercury connection with CC websocket.

by making the following changes

< DESCRIBE YOUR CHANGES >
Made changes in mercury plugin to accept additional config to skip authentication and ackowledgement.
Added code to call subscribe api and call mercury connection with websocket url.

Created new file MercuryCC.ts to extend Mercury and provide additional config and subscribe notifications.

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 were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

Updated samples page with register method.

If we click on register method it call subscribe notification API and gets Welcome Message as part of WebSocket.
We can see Welcome Message and CI-USerId in console logs.

This can be used to fetch agent profile in further PR's

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.

@rsarika rsarika requested review from a team as code owners October 11, 2024 09:38
@rsarika rsarika marked this pull request as draft October 11, 2024 09:39
@rsarika rsarika marked this pull request as ready for review October 14, 2024 07:22
Copy link
Contributor

@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.

Did we test the code? I don;t see the test details in the PR description

packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/constants.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/CCMercury.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
const handlers = [];
if (!eventType) {
return handlers;
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add comments on what is a handler and how it looks like

Copy link
Contributor Author

Choose a reason for hiding this comment

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

example of handlers w.r.t existing mercury
[
{
"name": "processKmsMessageEvent",
"namespace": "encryption"
}
]

Copy link
Contributor Author

@rsarika rsarika Oct 17, 2024

Choose a reason for hiding this comment

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

_getEventHandlers(eventType) {
    const handlers = [];
    if (!eventType) {
      return handlers;
    }
    const [namespace, name] = eventType.split('.');

    if (!this.webex[namespace] && !this.webex.internal[namespace]) {
      return handlers;
    }

    const handlerName = camelCase(`process_${name}_event`);

    if ((this.webex[namespace] || this.webex.internal[namespace])[handlerName]) {
      handlers.push({
        name: handlerName,
        namespace,
      });
    }

    return handlers;
  },

Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the above comment.. looks like half of it is in code while the other half is text.

* @param {object} body
* @returns {Promise<void>}
*/
register(datachannelUrl, body: object): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this funciton be called connect , connectDataChannel , connectSocket or something !?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

deviceRegistrationRequired: false,
};

const CCMercury = Mercury.extend({
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you try if something like this can be used

import AmpState from 'ampstate';

// Define the interface for your extended Mercury class
interface ExtendedMercury extends AmpState {
  // Add any custom properties or methods you need
  customProperty: string;
  customMethod(): void;
}

// Create the extended Mercury class
class CCMercury extends AmpState implements ExtendedMercury {
  customProperty = 'initial value';

  customMethod() {
    console.log('Custom method called');
  }
}

// Use the extended Mercury class
const mercuryInstance: ExtendedMercury = new CCMercury();
console.log(mercuryInstance.customProperty);
mercuryInstance.customMethod();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arun3528 Can you please elaborate more. because in the above mentioned code, existing Mercury is not extended.
We need to extend existing Mercury class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed added it as a modern TS class named 'WebSocket'

packages/@webex/plugin-cc/src/CCMercury.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/CCMercury.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@sreenara sreenara left a comment

Choose a reason for hiding this comment

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

Please fix the title. In the description's title, please add the jira link.
Please add a list of manual tests that have been done to test the feature.

packages/@webex/plugin-cc/src/constants.ts Outdated Show resolved Hide resolved
@rsarika rsarika changed the title feat: added code for cc mercury connection feat: WxCC SDK Subscribe Notifications and establish Mercury Connection Oct 16, 2024
@rsarika rsarika added the validated If the pull request is validated for automation. label Oct 16, 2024
@rsarika rsarika enabled auto-merge (squash) October 16, 2024 10:37
@@ -511,13 +516,15 @@ const Mercury = WebexPlugin.extend({
)
.then(() => {
this._emit('event', event.data);
const [namespace] = data.eventType.split('.');
if (data.eventType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a check for data.eventType to avoid undefined/null error

packages/@webex/plugin-cc/src/cc.ts Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/constants.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/constants.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/CCMercury.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/mercury.d.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/test/unit/spec/cc.ts Outdated Show resolved Hide resolved
@rsarika rsarika requested a review from sreenara October 21, 2024 16:45
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
import webSocketConfig from './config';
import IWebSocket from './IWebSocket';

class WebSocket extends (Mercury as any) implements IWebSocket {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we need to add as any here? I see mercury.d.ts file is deleted now so was this change done as an alternative for the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. this is the alternative to d.ts file and to impose type using interface IWebSocket

Copy link
Contributor

Choose a reason for hiding this comment

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

Did we try making it work with using as any here for Mercury? I removed it and it gives simple type error for request and connect function which should get resoolved if we add them in the interface I believe. Please try it out and address it before merge

Copy link
Contributor

Choose a reason for hiding this comment

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

Did we get chance to try this out ?

packages/@webex/plugin-cc/src/WebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket/WebSocket.ts Outdated Show resolved Hide resolved
*/
public unregister(): Promise<void> {
return this.webSocket.disconnectWebSocket().then(() => {
this.webSocket.off(EVENT, this.processEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to switch off the listener after the disconnect has already happened? This should happened in disconnectWebsocket function itself I believe

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a response on this also?

packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

2 previous comments are still not addressed

Copy link
Contributor

@sreenara sreenara left a comment

Choose a reason for hiding this comment

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

@rsarika it looks like we need more coverage in the UT

packages/@webex/plugin-cc/src/WebSocket/IWebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket/IWebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Show resolved Hide resolved
packages/@webex/plugin-cc/src/WebSocket/WebSocket.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Outdated Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Show resolved Hide resolved
packages/@webex/plugin-cc/src/cc.ts Show resolved Hide resolved
@rsarika rsarika requested a review from sreenara October 22, 2024 11:56
registered = false;
eventHandlers: Map<
string,
{resolve: (data: any) => void; reject: (error: any) => void; timeoutId: NodeJS.Timeout}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any should be avoided here also

});

const result = await promise;
expect(webSocketMock.subscribeAndConnect).toHaveBeenCalled();
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 expect statements can be combined into one and use toHaveBeenCalledOnceWith. Applies everywhere

import webSocketConfig from './config';
import IWebSocket from './IWebSocket';

class WebSocket extends (Mercury as any) implements IWebSocket {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we get chance to try this out ?

*/
public unregister(): Promise<void> {
return this.webSocket.disconnectWebSocket().then(() => {
this.webSocket.off(EVENT, this.processEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a response on this also?

Copy link
Contributor

@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 minor comments

Copy link
Contributor

@sreenara sreenara 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 a couple of questions.

  1. Why am I seeing this error constantly in the console

25 logger.js:396 wx-js-sdk socket,api.wxcc-us1.cisco.com: error while receiving WebSocket message TypeError: Cannot read properties of undefined (reading 'eventType')

  1. The text box under the webex.cc.register() still says "Not Subscribed" after the subscribe POST works fine. Is that expected?

@@ -0,0 +1,52 @@
import {WebSocketEvent} from '../types';

// ts doc
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this comment needed?

@rsarika rsarika merged commit 0887a00 into webex:feat/wxcc Oct 23, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants