-
Notifications
You must be signed in to change notification settings - Fork 18
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: adds ping stream support #624
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
824e1c7
feat: adds ping stream support
tanderson-ld 46c972e
Merge remote-tracking branch 'origin' into ta/sdk-198/ping-stream-sup…
tanderson-ld d1e962a
fixing issues discovered during bench testing
tanderson-ld d463667
fixing test that broke due to fixing missing logger parameter.
tanderson-ld a16aa37
added additional comment for Ping for Polling Unsupported case
tanderson-ld c22fd0e
fixing comments
tanderson-ld 9126060
Merge branch 'main' into ta/sdk-198/ping-stream-support
tanderson-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,12 @@ import { | |
DataSourcePaths, | ||
DataSourceState, | ||
FlagManager, | ||
getPollingUri, | ||
internal, | ||
LDEmitter, | ||
LDHeaders, | ||
LDIdentifyOptions, | ||
makeRequestor, | ||
Platform, | ||
Requestor, | ||
} from '@launchdarkly/js-client-sdk-common'; | ||
|
||
import { readFlagsFromBootstrap } from './bootstrap'; | ||
|
@@ -92,23 +91,35 @@ export default class BrowserDataManager extends BaseDataManager { | |
if (await this.flagManager.loadCached(context)) { | ||
this._debugLog('Identify - Flags loaded from cache. Continuing to initialize via a poll.'); | ||
} | ||
const plainContextString = JSON.stringify(Context.toLDContext(context)); | ||
const requestor = this._getRequestor(plainContextString); | ||
await this._finishIdentifyFromPoll(requestor, context, identifyResolve, identifyReject); | ||
} | ||
|
||
await this._finishIdentifyFromPoll(context, identifyResolve, identifyReject); | ||
} | ||
this._updateStreamingState(); | ||
} | ||
|
||
private async _finishIdentifyFromPoll( | ||
requestor: Requestor, | ||
context: Context, | ||
identifyResolve: () => void, | ||
identifyReject: (err: Error) => void, | ||
) { | ||
try { | ||
this.dataSourceStatusManager.requestStateUpdate(DataSourceState.Initializing); | ||
const payload = await requestor.requestPayload(); | ||
|
||
const plainContextString = JSON.stringify(Context.toLDContext(context)); | ||
const pollingRequestor = makeRequestor( | ||
plainContextString, | ||
this.config.serviceEndpoints, | ||
this.getPollingPaths(), | ||
this.platform.requests, | ||
this.platform.encoding!, | ||
this.baseHeaders, | ||
[], | ||
this.config.withReasons, | ||
this.config.useReport, | ||
this._secureModeHash, | ||
); | ||
|
||
const payload = await pollingRequestor.requestPayload(); | ||
try { | ||
const listeners = this.createStreamListeners(context, identifyResolve); | ||
const putListener = listeners.get('put'); | ||
|
@@ -196,35 +207,29 @@ export default class BrowserDataManager extends BaseDataManager { | |
const rawContext = Context.toLDContext(context)!; | ||
|
||
this.updateProcessor?.close(); | ||
this.createStreamingProcessor(rawContext, context, identifyResolve, identifyReject); | ||
|
||
this.updateProcessor!.start(); | ||
} | ||
|
||
private _getRequestor(plainContextString: string): Requestor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reviewers: _getRequestor got commonized to be a helper method in the Requestor file, the generated diff is confusing. |
||
const paths = this.getPollingPaths(); | ||
const path = this.config.useReport | ||
? paths.pathReport(this.platform.encoding!, plainContextString) | ||
: paths.pathGet(this.platform.encoding!, plainContextString); | ||
|
||
const parameters: { key: string; value: string }[] = []; | ||
if (this.config.withReasons) { | ||
parameters.push({ key: 'withReasons', value: 'true' }); | ||
} | ||
if (this._secureModeHash) { | ||
parameters.push({ key: 'h', value: this._secureModeHash }); | ||
} | ||
const plainContextString = JSON.stringify(Context.toLDContext(context)); | ||
const pollingRequestor = makeRequestor( | ||
plainContextString, | ||
this.config.serviceEndpoints, | ||
this.getPollingPaths(), // note: this is the polling path because the requestor is only used to make polling requests. | ||
tanderson-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.platform.requests, | ||
this.platform.encoding!, | ||
this.baseHeaders, | ||
[], | ||
this.config.withReasons, | ||
this.config.useReport, | ||
this._secureModeHash, | ||
); | ||
|
||
const headers: { [key: string]: string } = { ...this.baseHeaders }; | ||
let body; | ||
let method = 'GET'; | ||
if (this.config.useReport) { | ||
method = 'REPORT'; | ||
headers['content-type'] = 'application/json'; | ||
body = plainContextString; // context is in body for REPORT | ||
} | ||
this.createStreamingProcessor( | ||
rawContext, | ||
context, | ||
pollingRequestor, | ||
identifyResolve, | ||
identifyReject, | ||
); | ||
|
||
const uri = getPollingUri(this.config.serviceEndpoints, path, parameters); | ||
return new Requestor(this.platform.requests, uri, headers, method, body); | ||
this.updateProcessor!.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For reviewers: Updating paths to avoid confusing future developers about usage of /msdk