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

Web worker #4103

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open

Web worker #4103

wants to merge 6 commits into from

Conversation

Kesari3008
Copy link
Contributor

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

This pull request addresses

Adding web workers for sending keepalives

by making the following changes

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 >

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.

@Kesari3008 Kesari3008 added the validated If the pull request is validated for automation. label Feb 18, 2025
@Kesari3008 Kesari3008 requested review from a team as code owners February 18, 2025 07:05
Copy link

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

The changes encompass updates to the deployment workflow, core functionality, testing, and registration processes. The deployment configuration now includes an additional branch (web-workers-keepalive) to trigger deployment on pushes. In the core module, a new interceptors object has been introduced to centralize the creation of interceptor instances, and the initialization procedure of the WebexCore class has been updated to use this object. Several test files for the CallingClient and registration features have been modified—imports have been commented out and test suites have been skipped—indicating temporary deactivation for fixes or refactoring. In the registration module, modifications have shifted the keepalive mechanism to use a web worker instead of a setInterval approach, including changes to start and clear the keepalive timer. A new web worker script has been added to manage keepalive messages, and a new enumeration (WorkerMessageType) has been declared to standardize related message types.

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning glob@7.2.3: Glob versions prior to v9 are no longer supported
warning intern > glob@7.1.7: Glob versions prior to v9 are no longer supported
warning intern > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > jest-cli > jest-config > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > jest-cli > jest-config > babel-jest > babel-plugin-istanbul > test-exclude > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning mocha > glob@7.2.0: Glob versions prior to v9 are no longer supported
warning mocha > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning sinon@9.2.4: 16.1.1
warning sinon > @sinonjs/samsam > lodash.get@4.4.2: This package is deprecated. Use the optional chaining (?.) operator instead.
warning wd > request@2.88.0: request has been deprecated, see request/request#3142
warning wd > request > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning wd > archiver > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning wd > q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > request > har-validator@5.1.5: this library is no longer supported
warning wd > archiver > archiver-utils > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @babel/cli > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/plugin-proposal-export-namespace-from@7.18.9: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > sinon@9.2.4: 16.1.1
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-export-namespace-from@7.18.9: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-c0d10b92-1b1f-4a53-bf48-22d7cdbb6b3a > @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
[2/4] Fetching packages...
error eslint-plugin-jsdoc@40.3.0: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
packages/calling/src/CallingClient/line/line.test.ts (1)

80-123: 🛠️ Refactor suggestion

Update keepalive test for web worker implementation.

This test verifies the keepalive functionality using jest.advanceTimersByTime. Since the PR implements web workers for keepalive signals, this test should be updated to:

  1. Verify web worker initialization
  2. Test message passing between the main thread and worker
  3. Ensure keepalive signals are sent from the worker

Would you like me to help update this test to verify the web worker implementation?

🧹 Nitpick comments (2)
packages/calling/src/CallingClient/registration/register.ts (2)

683-755: Consider adding an onerror handler for the worker and verifying concurrency.

  1. Adding this.webWorker.onerror could help handle unexpected failures in the worker context more gracefully.
  2. Verify that multiple consecutive calls to startKeepaliveTimer won’t produce extra or leftover workers if called concurrently.

760-766: Minor redundancy in the termination flow.
Since .terminate() kills the worker, posting CLEAR_KEEPALIVE might be unnecessary. Consider removing the extra post or leaving a comment clarifying the intention.

  public clearKeepaliveTimer() {
    if (this.webWorker) {
-     this.webWorker.postMessage({type: WorkerMessageType.CLEAR_KEEPALIVE});
      this.webWorker.terminate();
      this.webWorker = undefined;
    }
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51a0f4a and 7c09037.

📒 Files selected for processing (8)
  • .github/workflows/deploy.yml (1 hunks)
  • packages/@webex/webex-core/src/webex-core.js (1 hunks)
  • packages/calling/src/CallingClient/CallingClient.test.ts (2 hunks)
  • packages/calling/src/CallingClient/line/line.test.ts (4 hunks)
  • packages/calling/src/CallingClient/registration/register.test.ts (2 hunks)
  • packages/calling/src/CallingClient/registration/register.ts (3 hunks)
  • packages/calling/src/CallingClient/registration/webWorker.ts (1 hunks)
  • packages/calling/src/common/types.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/calling/src/CallingClient/registration/webWorker.ts (1)
Learnt from: Kesari3008
PR: webex/webex-js-sdk#4101
File: packages/calling/src/CallingClient/registration/webWorker.ts:4-8
Timestamp: 2025-02-17T22:31:35.639Z
Learning: In web worker context, using `onmessage` directly is equivalent to `self.onmessage` and is a valid practice. Both approaches are acceptable for handling web worker messages.
🪛 Biome (1.9.4)
packages/calling/src/CallingClient/registration/webWorker.ts

[error] 3-4: A global variable should not be reassigned.

Assigning to a global variable can override essential functionality.

(lint/suspicious/noGlobalAssign)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Initialize Project
  • GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (7)
packages/calling/src/CallingClient/registration/register.ts (2)

22-22: Looks good.
The addition of WorkerMessageType import is consistent with the rest of the file.


80-80: Browser environment check.
Ensure that the environment can support web workers before instantiating them at runtime.

packages/calling/src/common/types.ts (1)

262-268: Enum addition looks great.
The new WorkerMessageType values provide clear and extensible message types for keepalive operations.

packages/@webex/webex-core/src/webex-core.js (1)

45-77: LGTM! Well-structured interceptors configuration.

The new interceptors object effectively centralizes the creation of interceptor instances, making the code more maintainable. The conditional handling of logging interceptors based on environment variables is a good practice.

packages/calling/src/CallingClient/CallingClient.test.ts (1)

13-13: Create a plan to re-enable the skipped tests.

Multiple test files have been disabled:

  1. Commented out imports: createClient and Line
  2. Skipped test suite: "CallingClient Tests"

This significantly reduces test coverage. While temporarily skipping tests during refactoring is understandable, we need a plan to re-enable them.

Please provide:

  1. Timeline for fixing and re-enabling these tests
  2. Confirmation that these tests will be updated to work with the new web worker implementation
  3. Any dependencies or blockers that need to be resolved first

Also applies to: 26-26, 52-52

packages/calling/src/CallingClient/registration/register.test.ts (1)

3-3: Re-enable registration tests after web worker implementation.

The registration tests have been disabled:

  1. Commented out import: createRegistration
  2. Skipped test suite: "Registration Tests"

These tests are crucial for validating the registration functionality, especially with the new web worker implementation for keepalive signals.

Please provide:

  1. Plan for updating these tests to work with the web worker implementation
  2. Timeline for re-enabling the test suite
  3. Confirmation that the tests will cover both the old and new keepalive mechanisms

Also applies to: 43-43

.github/workflows/deploy.yml (1)

7-8: New Deployable Branch Added: "web-workers-keepalive"

The addition of the web-workers-keepalive branch in the deployment trigger is correctly integrated. This aligns well with the PR objective to implement web workers for keepalive signals. Please ensure that any accompanying documentation or branch naming conventions across the project reflect this new branch.

Comment on lines +4 to +8
onmessage = (event: MessageEvent) => {
const {type} = event.data;
let keepaliveTimer: NodeJS.Timer | undefined;

const postKeepAlive = async (accessToken: string, deviceUrl: string, url: string) => {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Move “keepaliveTimer” to a higher scope for stronger consistency.
Currently, each message event redeclares keepaliveTimer. Move it outside the onmessage function to persist the reference across repeated starts/stops:

-let keepaliveTimer: NodeJS.Timer | undefined;
-onmessage = (event: MessageEvent) => {
-  const {type} = event.data;
-  let keepaliveTimer: NodeJS.Timer | undefined;
+let keepaliveTimer: NodeJS.Timer | undefined;
+onmessage = (event: MessageEvent) => {
   const {type} = event.data;
   ...
};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onmessage = (event: MessageEvent) => {
const {type} = event.data;
let keepaliveTimer: NodeJS.Timer | undefined;
const postKeepAlive = async (accessToken: string, deviceUrl: string, url: string) => {
let keepaliveTimer: NodeJS.Timer | undefined;
onmessage = (event: MessageEvent) => {
const {type} = event.data;
const postKeepAlive = async (accessToken: string, deviceUrl: string, url: string) => {
// function implementation goes here
};
// Other message handling logic...
};

@@ -16,20 +16,20 @@ import {
WebexRequestPayload,
} from '../../common/types';
import {LINE_EVENTS} from './types';
import Line from '.';
// import Line from '.';
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Tests should not be skipped without tracking.

The entire test suite has been skipped and imports have been commented out with a TODO comment. While this might be temporary during the web worker implementation, we should:

  1. Create a tracking issue for fixing these tests
  2. Add a comment explaining why the tests are skipped
  3. Set a timeline for re-enabling them

This helps prevent the tests from being forgotten and ensures test coverage is restored.

Would you like me to help create a tracking issue for fixing these tests?

Also applies to: 24-24, 26-26

const mutex = new Mutex();
const webex = getTestUtilsWebex();
SDKConnector.setWebex(webex);

const defaultServiceData = {indicator: ServiceIndicator.CALLING, domain: ''};
const createRegistrationSpy = jest.spyOn(regUtils, 'createRegistration');
// const createRegistrationSpy = jest.spyOn(regUtils, 'createRegistration');
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Registration spy assertions need to be updated for web worker changes.

The registration spy and its assertions have been commented out. Since this PR implements web workers for keepalive signals, these tests should be updated to verify the new behavior rather than being removed.

Let's check if there are any existing tests for the web worker implementation:

Also applies to: 84-91, 140-147


🏁 Script executed:

#!/bin/bash
# Description: Search for web worker related test files
# Test: Look for test files that might contain web worker tests
rg -t ts -t js "worker" . -l | grep "test"

# Description: Search for keepalive related tests
# Test: Look for test files that might contain keepalive tests
rg -t ts -t js "keepalive" . -l | grep "test"

Length of output: 661


Action Required: Update Registration Spy Assertions for Web Worker Behavior

  • In file packages/calling/src/CallingClient/line/line.test.ts around line 32 (and similarly at lines 84–91 and 140–147), the registration spy code is still commented out.
  • With the new web worker implementation for keepalive signals, update these tests to assert the new behavior rather than removing the assertions.
  • Additionally, review and ensure consistency with related tests in files such as packages/calling/src/CallingClient/registration/register.test.ts.

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4103.d3m3l2kee0btzx.amplifyapp.com

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.

2 participants