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

Implement countly-sdk-web-LITE for webworker context #103

Open
whizzzkid opened this issue Mar 8, 2023 · 2 comments
Open

Implement countly-sdk-web-LITE for webworker context #103

whizzzkid opened this issue Mar 8, 2023 · 2 comments
Labels
enhancement New feature or request P0

Comments

@whizzzkid
Copy link
Collaborator

whizzzkid commented Mar 8, 2023

Blocks: ipfs/ipfs-companion#1127
Related: Countly/countly-sdk-web#382

The issue:

  • countly-web-sdk ships as an iife which bundles everything, including dependence on window object and implements XMLHttpRequest. Both of these are blockers for implement countly in webworkers (companion background worker and service workers)

Proposed Fix:

  • Since not all APIs are used by ignite-metrics, it's possible to write a minimal set of function calls that can call countly endpoints from within the webworker.
  • APIs Needed:
    • Authentication Flow
    • Session Create Flow
    • Push Event Flow
  • Other considerations:
    • We already implement an eventAccumulator
    • We will need a batching mechanism to not overwhelm the endpoint.
  • Limitations:
    • webworkers don't have access to DOM, window, XMLHttpRequest and localStorage, so:
      • use fetch to open connections to countly endpoints
      • use indexedDB for storage needs. The browser API is awful to use, but projects like Dexie provide a decent API to work with indexedDB.
  • Shipping:
    • Since webpack supports webworker build target as of v5. We can simply provide an export target without changing a lot of things.

Other Thoughts

  • If countly can implement a modular SDK, we might be able to treeshake most of unreachable code and shim window if still needed.
  • In the short term this can help unblock and have light and sane way of communicating with countly.

CC: @SgtPooki

@BigLep
Copy link
Contributor

BigLep commented Mar 10, 2023

@SgtPooki @whizzzkid : how big of an effort this is? I'm asking so can trade off between getting ipfs/ipfs-companion#1127 or doing other work.

@SgtPooki
Copy link
Member

@BigLep It's about a week worth of effort. I talked with @whizzzkid about this and I believe I could get this done before EOW in a way that works for us, though it would be somewhat hacky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P0
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants