@splitsoftware/splitio-react-native
Version:
Split SDK for React Native
34 lines (30 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getEventSource = getEventSource;
var _reactNative = _interopRequireDefault(require("react-native"));
var _EventSourceXHR = require("./EventSourceXHR/EventSourceXHR");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// @ts-expect-error no declaration file provided
let _RNEventSource;
// Try-catch to avoid Jest error `Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules`
try {
if (_reactNative.default.NativeModules && _reactNative.default.NativeModules.RNEventSource) _RNEventSource = require('./EventSource/EventSource');
} catch (e) {}
/**
* Returns native implementation of EventSource.
* If not available (e.g., incomplete linking, Expo projects or other runtimes than Android and iOS), checks if global EventSource is available and returns it.
* If not available, returns an EventSource polyfill based on XMLHttpRequest.
*
* The EventSource polyfill is the last option because it doesn't work on Android in debug mode in RN below v0.74,
* due to Flipper network interceptor (https://github.com/NepeinAV/rn-eventsource-reborn#eventsource-dont-works-on-android-in-debug-mode).
* In RN 0.74 (https://reactnative.dev/blog/2024/04/22/release-0.74#removal-of-flipper-react-native-plugin) and Expo 51 (https://github.com/expo/expo/issues/27526#issuecomment-2113893318),
* Flipper was removed from new app templates and replaced by the new React Native DevTools, so the Android-debug interception that broke SSE disappears.
*
* @TODO breaking change: drop support for RN < 0.74 and remove native EventSource modules
*/
function getEventSource() {
return _RNEventSource || (typeof EventSource === 'function' ? EventSource : _EventSourceXHR.EventSourceXHR);
}
//# sourceMappingURL=getEventSource.js.map