Skip to content

Commit

Permalink
[FFM-10442] - Disable streaming if Reactive Native + Android is detec…
Browse files Browse the repository at this point in the history
…ted (#115)

* [FFM-10442] - Disable streaming if Reactive Native + Android is detected

What
Make the JS SDK fall back to polling when it detects that it is running inside Android on React native

Why
XMLHttpRequest does not work correctly on React Native when Android is used.
For more context: facebook/react-native#28835
We will use this work around until a better fix is identified.

Testing
Manual
  • Loading branch information
andybharness authored Feb 21, 2024
1 parent fc679ab commit 54a99eb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/preact/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react-redux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harnessio/ff-javascript-client-sdk",
"version": "1.23.0",
"version": "1.24.0",
"author": "Harness",
"license": "Apache-2.0",
"main": "dist/sdk.cjs.js",
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Streamer } from './stream'
import { getVariation } from './variation'
import Poller from './poller'

const SDK_VERSION = '1.23.0'
const SDK_VERSION = '1.24.0'
const SDK_INFO = `Javascript ${SDK_VERSION} Client`
const METRICS_VALID_COUNT_INTERVAL = 500
const fetch = globalThis.fetch
Expand Down Expand Up @@ -85,6 +85,19 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
configurations.pollingInterval = MIN_POLLING_INTERVAL
}

if (configurations.streamEnabled) {
try {
const { Platform } = require("react-native");
if (Platform.OS === 'android') {
console.info("SDKCODE:1007 Android React Native detected - streaming will be disabled and polling enabled")
configurations.pollingEnabled = true
configurations.streamEnabled = false
}
} catch (e) {
// ignore
}
}

const logDebug = (message: string, ...args: any[]) => {
if (configurations.debug) {
// tslint:disable-next-line:no-console
Expand Down

0 comments on commit 54a99eb

Please sign in to comment.