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

Sessions #19

Merged
merged 11 commits into from
Jan 11, 2025
Merged

Sessions #19

merged 11 commits into from
Jan 11, 2025

Conversation

rockwellll
Copy link
Collaborator

@rockwellll rockwellll commented Jan 11, 2025

This PR improves session generation and offloads the work from a client-server approach into a client-only approach.

Todos

  • Publish a new version to npm.

Session generation

Previously, generating a session would have to go to Hellotext's servers to create a new one. This induced latency to the package's initialization time because it would have to wait until Hellotext replied with the session's token. Now, a session is generated on the client when is not present, this

  1. Reduces the wait-time for booting the lib by shaving the request to Hellotext when no session was found.
  2. Simplifies session generation across all devices.

The new session generation algorithm reuses crypto.randomUUID() which has now full support across all major browsers and can safely be assumed available everywhere.

Refactors

Moves session initialization code from Hellotext into a dedicated Session model that is responsible for setting the session, as well as dispatching events to subscribers. This solves a race-condition if a user had accessed Hellotext.session in a on-session callback because the subscriber would have been notified before Hellotext.session being set.

@rockwellll rockwellll merged commit f77c6c8 into main Jan 11, 2025
2 checks passed
@rockwellll rockwellll deleted the sessions branch January 11, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant