react-native-bugbattle-sdk
Version:
In-App Bug Reporting and Testing for Apps. Learn more at https://www.bugbattle.io
121 lines (95 loc) • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _networklogger = _interopRequireDefault(require("./networklogger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const {
BugbattleSdk
} = _reactNative.NativeModules;
const networkLogger = new _networklogger.default();
if (BugbattleSdk) {
BugbattleSdk.NONE = 'NONE';
BugbattleSdk.SHAKE = 'SHAKE';
BugbattleSdk.SCREENSHOT = 'SCREENSHOT';
BugbattleSdk.startNetworkLogging = () => {
networkLogger.start();
};
BugbattleSdk.stopNetworkLogging = () => {
networkLogger.setStopped(true);
};
BugbattleSdk.autoConfigure = token => {
fetch("https://widget.bugbattle.io/appwidget/".concat(token, "/config?s=reactnative")).then(response => response.json()).then(config => {
if (typeof config.color !== 'undefined' && config.color.length > 0) {
BugbattleSdk.setColor(config.color);
}
if (typeof config.hideBugBattleLogo !== 'undefined') {
BugbattleSdk.enablePoweredByBugbattle(config.hideBugBattleLogo);
}
if (typeof config.logo !== 'undefined' && config.logo.length > 0) {
BugbattleSdk.setLogoUrl(config.logo);
}
if (typeof config.enableNetworkLogs !== 'undefined' && config.enableNetworkLogs === true) {
BugbattleSdk.startNetworkLogging();
}
if (typeof config.enableReplays !== 'undefined') {
BugbattleSdk.enableReplays(config.enableReplays);
}
var activationMethods = [];
if (typeof config.activationMethodShake !== 'undefined' && config.activationMethodShake === true) {
activationMethods.push(BugbattleSdk.SHAKE);
}
if (typeof config.activationMethodScreenshotGesture !== 'undefined' && config.activationMethodScreenshotGesture === true) {
activationMethods.push(BugbattleSdk.SCREENSHOT);
}
BugbattleSdk.initializeMany(token, activationMethods);
}).catch(err => {
console.log(err);
console.warn('Bugbattle: Your SDK key is invalid.');
});
};
var callbacks = [];
BugbattleSdk.registerCustomAction = customActionCallback => {
callbacks.push(customActionCallback);
};
const bugBattleEmitter = new _reactNative.NativeEventEmitter(BugbattleSdk);
bugBattleEmitter.addListener('bugWillBeSent', () => {
// Push the network log to the native SDK.
const requests = networkLogger.getRequests();
if (_reactNative.Platform.OS === 'android') {
BugbattleSdk.attachNetworkLog(JSON.stringify(requests));
} else {
BugbattleSdk.attachNetworkLog(requests);
}
});
bugBattleEmitter.addListener('customActionTriggered', data => {
if (isJsonString(data)) {
data = JSON.parse(data);
}
const {
name
} = data;
if (name && callbacks.length > 0) {
for (var i = 0; i < callbacks.length; i++) {
if (callbacks[i]) {
callbacks[i]({
name
});
}
}
}
});
}
function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
var _default = BugbattleSdk;
exports.default = _default;
//# sourceMappingURL=index.js.map