UNPKG

@datadog/mobile-react-native

Version:

A client-side React Native module to interact with Datadog

42 lines (39 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTimings = createTimings; var _reactNative = require("react-native"); /* * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. * This product includes software developed at Datadog (https://www.datadoghq.com/). * Copyright 2016-Present Datadog, Inc. */ function createTimings(startTime, responseStartTime, responseEndTime) { const firstByte = formatTiming(startTime, startTime, responseStartTime); const download = formatTiming(startTime, responseStartTime, responseEndTime); // needed for iOS, simply total duration from start to end const fetch = formatTiming(startTime, startTime, responseEndTime); return { firstByte, download, fetch }; } /** * @param origin Start time (absolute) of the request * @param start Start time (absolute) of the timing * @param end End time (absolute) of the timing */ function formatTiming(origin, start, end) { return { duration: timeToNanos(end - start), // if it is Android, startTime should be relative to the origin, // if it is iOS - absolute (unix timestamp) startTime: _reactNative.Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin) }; } function timeToNanos(durationMs) { return +(durationMs * 1e6).toFixed(0); } //# sourceMappingURL=resourceTiming.js.map