-
Notifications
You must be signed in to change notification settings - Fork 20
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: Add connection mananger. #522
feat: Add connection mananger. #522
Conversation
@@ -9,6 +9,6 @@ | |||
* | |||
* streaming - The SDK will use a streaming connection to receive updates from LaunchDarkly. | |||
*/ | |||
type ConnectionMode = 'offline' | 'streaming'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding polling as a connection mode. An implementation of polling will be in a later PR.
@@ -0,0 +1,149 @@ | |||
import { ConnectionMode, LDLogger } from '@launchdarkly/js-client-sdk-common'; | |||
|
|||
export enum ApplicationState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These "state" enums are internal to the SDK, so I used enums for them. (Versus a union type.)
Available, | ||
} | ||
|
||
export interface ConnectionDestination { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually the common client will likely support this interface, but having the abstraction here is nice for testing.
The common interface for the client will likely not expose these as they are for internal control.
} | ||
|
||
export interface StateDetector { | ||
setApplicationStateListener(fn: (state: ApplicationState) => void): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used basic callback functions for "events" from the state detector.
export interface ConnectionDestination { | ||
setNetworkAvailability(available: boolean): void; | ||
setEventSendingEnabled(enabled: boolean, flush: boolean): void; | ||
setConnectionMode(mode: ConnectionMode): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version of setting the connection mode is asynchronous. I am not sure if that is ideal. The process itself is asynchronous, but having a promise that indicates it is "finished" seems risky. Especially lots of independent inputs and without a queue managing transitions.
In the LDClient interface is returns void, but the implementation actually returns a promise and we don't provide any specification of behavior.
readonly automaticBackgroundHandling: boolean; | ||
} | ||
|
||
export class ConnectionManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is largely a port of the flutter implementation.
2d2131a
into
feat/client-connection-handling-rework
This adds a connection manager which is used to handle application state and network state and determine the desired connection mode.
This adds a connection manager which is used to handle application state and network state and determine the desired connection mode.
🤖 I have created a release *beep* *boop* --- <details><summary>akamai-edgeworker-sdk-common: 1.1.12</summary> ## [1.1.12](akamai-edgeworker-sdk-common-v1.1.11...akamai-edgeworker-sdk-common-v1.1.12) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from ^2.4.4 to ^2.4.5 </details> <details><summary>akamai-server-base-sdk: 2.1.12</summary> ## [2.1.12](akamai-server-base-sdk-v2.1.11...akamai-server-base-sdk-v2.1.12) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.1.11 to ^1.1.12 * @launchdarkly/js-server-sdk-common bumped from ^2.4.4 to ^2.4.5 </details> <details><summary>akamai-server-edgekv-sdk: 1.1.12</summary> ## [1.1.12](akamai-server-edgekv-sdk-v1.1.11...akamai-server-edgekv-sdk-v1.1.12) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.1.11 to ^1.1.12 * @launchdarkly/js-server-sdk-common bumped from ^2.4.4 to ^2.4.5 </details> <details><summary>cloudflare-server-sdk: 2.5.10</summary> ## [2.5.10](cloudflare-server-sdk-v2.5.9...cloudflare-server-sdk-v2.5.10) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/js-server-sdk-common-edge bumped from 2.3.5 to 2.3.6 </details> <details><summary>js-client-sdk-common: 1.3.0</summary> ## [1.3.0](js-client-sdk-common-v1.2.0...js-client-sdk-common-v1.3.0) (2024-08-12) ### Features * Add connection mananger. ([#522](#522)) ([5bf8b16](5bf8b16)) * Implement polling support. ([#524](#524)) ([a99048e](a99048e)) * Refactor application state handling. ([#523](#523)) ([f5b81e6](f5b81e6)) * refactors the implementation of context caching. You can now s… ([#531](#531)) ([8ab2ee4](8ab2ee4)) ### Bug Fixes * Fix field visibility. ([#530](#530)) ([21fb18b](21fb18b)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-sdk-common bumped from 2.5.0 to 2.6.0 </details> <details><summary>js-sdk-common: 2.6.0</summary> ## [2.6.0](js-sdk-common-v2.5.0...js-sdk-common-v2.6.0) (2024-08-12) ### Features * refactors the implementation of context caching. You can now s… ([#531](#531)) ([8ab2ee4](8ab2ee4)) </details> <details><summary>js-server-sdk-common: 2.4.5</summary> ## [2.4.5](js-server-sdk-common-v2.4.4...js-server-sdk-common-v2.4.5) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-sdk-common bumped from 2.5.0 to 2.6.0 </details> <details><summary>js-server-sdk-common-edge: 2.3.6</summary> ## [2.3.6](js-server-sdk-common-edge-v2.3.5...js-server-sdk-common-edge-v2.3.6) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from 2.4.4 to 2.4.5 </details> <details><summary>node-server-sdk: 9.5.1</summary> ## [9.5.1](node-server-sdk-v9.5.0...node-server-sdk-v9.5.1) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from 2.4.4 to 2.4.5 </details> <details><summary>node-server-sdk-dynamodb: 6.1.18</summary> ## [6.1.18](node-server-sdk-dynamodb-v6.1.17...node-server-sdk-dynamodb-v6.1.18) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/node-server-sdk bumped from 9.5.0 to 9.5.1 * peerDependencies * @launchdarkly/node-server-sdk bumped from >=9.4.3 to >=9.5.1 </details> <details><summary>node-server-sdk-otel: 1.0.10</summary> ## [1.0.10](node-server-sdk-otel-v1.0.9...node-server-sdk-otel-v1.0.10) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/node-server-sdk bumped from 9.5.0 to 9.5.1 * peerDependencies * @launchdarkly/node-server-sdk bumped from >=9.4.3 to >=9.5.1 </details> <details><summary>node-server-sdk-redis: 4.1.18</summary> ## [4.1.18](node-server-sdk-redis-v4.1.17...node-server-sdk-redis-v4.1.18) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/node-server-sdk bumped from 9.5.0 to 9.5.1 * peerDependencies * @launchdarkly/node-server-sdk bumped from >=9.4.3 to >=9.5.1 </details> <details><summary>react-native-client-sdk: 10.4.0</summary> ## [10.4.0](react-native-client-sdk-v10.3.1...react-native-client-sdk-v10.4.0) (2024-08-12) ### Features * Add configuration validation for ReactNative specific configuration. ([#532](#532)) ([c1490e2](c1490e2)) * Add connection mananger. ([#522](#522)) ([5bf8b16](5bf8b16)) * Implement polling support. ([#524](#524)) ([a99048e](a99048e)) * Refactor application state handling. ([#523](#523)) ([f5b81e6](f5b81e6)) ### Bug Fixes * Fix field visibility. ([#530](#530)) ([21fb18b](21fb18b)) * Handle non-status code errors for streaming connection. ([#533](#533)) ([fc4645e](fc4645e)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 1.2.0 to 1.3.0 </details> <details><summary>vercel-server-sdk: 1.3.13</summary> ## [1.3.13](vercel-server-sdk-v1.3.12...vercel-server-sdk-v1.3.13) (2024-08-12) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common-edge bumped from 2.3.5 to 2.3.6 </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Todd Anderson <[email protected]>
This adds a connection manager which is used to handle application state and network state and determine the desired connection mode.