From 7fbf5c66edb674ced5070e4456bab3dbba94a524 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Sekhar Sarika Date: Wed, 13 Nov 2024 15:10:28 +0530 Subject: [PATCH] revert: mercury plugin changes of cc websocket --- .../internal-plugin-mercury/src/mercury.js | 21 ++--- .../src/socket/socket-base.js | 44 +++-------- .../test/unit/spec/mercury.js | 15 ---- .../test/unit/spec/socket.js | 76 ------------------- 4 files changed, 18 insertions(+), 138 deletions(-) diff --git a/packages/@webex/internal-plugin-mercury/src/mercury.js b/packages/@webex/internal-plugin-mercury/src/mercury.js index 40fae0bdaa5..ed7b706130c 100644 --- a/packages/@webex/internal-plugin-mercury/src/mercury.js +++ b/packages/@webex/internal-plugin-mercury/src/mercury.js @@ -217,8 +217,6 @@ const Mercury = WebexPlugin.extend({ token: token.toString(), trackingId: `${this.webex.sessionId}_${Date.now()}`, logger: this.logger, - authorizationRequired: this.config.authorizationRequired ?? true, - acknowledgementRequired: this.config.acknowledgementRequired ?? true, }; // if the consumer has supplied request options use them @@ -401,11 +399,8 @@ const Mercury = WebexPlugin.extend({ }, _getEventHandlers(eventType) { - const handlers = []; - if (!eventType) { - return handlers; - } const [namespace, name] = eventType.split('.'); + const handlers = []; if (!this.webex[namespace] && !this.webex.internal[namespace]) { return handlers; @@ -516,15 +511,13 @@ const Mercury = WebexPlugin.extend({ ) .then(() => { this._emit('event', event.data); - if (data.eventType) { - const [namespace] = data.eventType.split('.'); + const [namespace] = data.eventType.split('.'); - if (namespace === data.eventType) { - this._emit(`event:${namespace}`, envelope); - } else { - this._emit(`event:${namespace}`, envelope); - this._emit(`event:${data.eventType}`, envelope); - } + if (namespace === data.eventType) { + this._emit(`event:${namespace}`, envelope); + } else { + this._emit(`event:${namespace}`, envelope); + this._emit(`event:${data.eventType}`, envelope); } }) .catch((reason) => { diff --git a/packages/@webex/internal-plugin-mercury/src/socket/socket-base.js b/packages/@webex/internal-plugin-mercury/src/socket/socket-base.js index ae6eca611f4..02bbe25d5a1 100644 --- a/packages/@webex/internal-plugin-mercury/src/socket/socket-base.js +++ b/packages/@webex/internal-plugin-mercury/src/socket/socket-base.js @@ -179,8 +179,6 @@ export default class Socket extends EventEmitter { * @param {string} options.token (required) * @param {string} options.trackingId (required) * @param {Logger} options.logger (required) - * @param {boolean} options.authorizationRequired - * @param {boolean} options.acknowledgementRequired * @param {string} options.logLevelToken * @returns {Promise} */ @@ -212,18 +210,7 @@ export default class Socket extends EventEmitter { options ); - // Destructure and set default values for authorizationRequired and acknowledgementRequired - const { - authorizationRequired = true, - acknowledgementRequired = true, - ...remainingOptions - } = options; - - this.authorizationRequired = authorizationRequired; - this.acknowledgementRequired = acknowledgementRequired; - - // Assign the remaining options to the instance - Object.keys(remainingOptions).forEach((key) => { + Object.keys(options).forEach((key) => { Reflect.defineProperty(this, key, { enumerable: false, value: options[key], @@ -263,18 +250,13 @@ export default class Socket extends EventEmitter { socket.onopen = () => { this.logger.info(`socket,${this._domain}: connected`); - // Added the "authorizationRequired" condition to bypass the "_authorize" in case of the contact center context, in which case it is configured as false. - if (this.authorizationRequired) { - this._authorize() - .then(() => { - this.logger.info(`socket,${this._domain}: authorized`); - socket.onclose = this.onclose; - resolve(); - }) - .catch(reject); - } else { - this._ping(); - } + this._authorize() + .then(() => { + this.logger.info(`socket,${this._domain}: authorized`); + socket.onclose = this.onclose; + resolve(); + }) + .catch(reject); }; socket.onerror = (event) => { @@ -328,13 +310,9 @@ export default class Socket extends EventEmitter { // modified and we don't actually care about anything but the data property const processedEvent = {data}; - // Added the "acknowledgementRequired" condition to bypass the "_acknowledge" in case of the contact center context, in which case it is configured as false. - if (this.acknowledgementRequired) { - this._acknowledge(processedEvent); - } - if (data.type === 'pong' || data.type === 'ping') { - // added above ping condition to handle pong messages of contact center where type is 'ping' instead of 'pong' - this.emit('pong', {...processedEvent, type: 'pong'}); + this._acknowledge(processedEvent); + if (data.type === 'pong') { + this.emit('pong', processedEvent); } else { this.emit('message', processedEvent); } diff --git a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js index bb1bc4f40c6..6e772c301b9 100644 --- a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js +++ b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js @@ -713,21 +713,6 @@ describe('plugin-mercury', () => { return res; }); }); - - it('_onmessage without eventType', () => { - sinon.spy(mercury, '_getEventHandlers'); - sinon.spy(mercury, '_emit'); - const event = {data: {data: {eventType: undefined, mydata: 'some data'}}}; - mercury.logger.error.restore(); - sinon.stub(mercury.logger, 'error'); - return Promise.resolve(mercury._onmessage(event)).then(() => { - assert.calledWith(mercury._getEventHandlers, undefined); - assert.calledWith(mercury._emit, 'event', event.data); - assert.notCalled(mercury.logger.error); - mercury._emit.restore(); - mercury._getEventHandlers.restore(); - }); - }); }); describe('#_applyOverrides()', () => { diff --git a/packages/@webex/internal-plugin-mercury/test/unit/spec/socket.js b/packages/@webex/internal-plugin-mercury/test/unit/spec/socket.js index ce28a3542c6..39b4f9f3da1 100644 --- a/packages/@webex/internal-plugin-mercury/test/unit/spec/socket.js +++ b/packages/@webex/internal-plugin-mercury/test/unit/spec/socket.js @@ -139,7 +139,6 @@ describe('plugin-mercury', () => { )); it('accepts a logLevelToken option', () => { - const acknowledgeSpy = sinon.spy(socket, '_acknowledge'); const promise = socket.open('ws://example.com', { forceCloseDelay: mockoptions.forceCloseDelay, pingInterval: mockoptions.pingInterval, @@ -148,7 +147,6 @@ describe('plugin-mercury', () => { token: 'mocktoken', trackingId: 'mocktrackingid', logLevelToken: 'mocklogleveltoken', - acknowledgementRequired: true, }); mockWebSocket.readyState = 1; @@ -164,83 +162,9 @@ describe('plugin-mercury', () => { }); return promise.then(() => { - assert.called(acknowledgeSpy); assert.equal(socket.logLevelToken, 'mocklogleveltoken'); }); }); - - it('accepts acknowledgementRequired option as false and skip acknowledge', () => { - const acknowledgeSpy = sinon.spy(socket, '_acknowledge'); - const promise = socket.open('ws://example.com', { - forceCloseDelay: mockoptions.forceCloseDelay, - pingInterval: mockoptions.pingInterval, - pongTimeout: mockoptions.pongTimeout, - logger: console, - token: 'mocktoken', - trackingId: 'mocktrackingid', - logLevelToken: 'mocklogleveltoken', - acknowledgementRequired: false, - }); - - mockWebSocket.readyState = 1; - mockWebSocket.emit('open'); - - mockWebSocket.emit('message', { - data: JSON.stringify({ - id: uuid.v4(), - data: { - eventType: 'mercury.buffer_state', - }, - }), - }); - - return promise.then(() => { - assert.notCalled(acknowledgeSpy); - assert.equal(socket.logLevelToken, 'mocklogleveltoken'); - }); - }); - - it('accepts authorizationRequired option as false and skip authorize', () => { - const s = new Socket(); - const authorizeSpy = sinon.spy(socket, '_authorize'); - socket.open('ws://example.com', { - forceCloseDelay: mockoptions.forceCloseDelay, - pingInterval: mockoptions.pingInterval, - pongTimeout: mockoptions.pongTimeout, - logger: console, - token: 'mocktoken', - trackingId: 'mocktrackingid', - logLevelToken: 'mocklogleveltoken', - authorizationRequired: false, - }); - - mockWebSocket.readyState = 1; - mockWebSocket.emit('open'); - - assert.notCalled(authorizeSpy); - assert.called(socket._ping); - }); - - it('accepts authorizationRequired option as true and calles authorize', () => { - const s = new Socket(); - const authorizeSpy = sinon.spy(socket, '_authorize'); - socket.open('ws://example.com', { - forceCloseDelay: mockoptions.forceCloseDelay, - pingInterval: mockoptions.pingInterval, - pongTimeout: mockoptions.pongTimeout, - logger: console, - token: 'mocktoken', - trackingId: 'mocktrackingid', - logLevelToken: 'mocklogleveltoken', - authorizationRequired: true, - }); - - mockWebSocket.readyState = 1; - mockWebSocket.emit('open'); - - assert.called(authorizeSpy); - assert.called(socket._ping); - }); }); describe('#binaryType', () => {