UNPKG

@nativescript/firebase-performance

Version:

NativeScript Firebase - Performancee

141 lines 3.84 kB
import { deserialize, firebase, FirebaseApp } from '@nativescript/firebase-core'; let defaultPerformance; const fb = firebase(); Object.defineProperty(fb, 'performance', { value: () => { if (!defaultPerformance) { defaultPerformance = new Performance(); } return defaultPerformance; }, writable: false, }); export class HttpMetric { static fromNative(metric) { if (metric instanceof com.google.firebase.perf.metrics.HttpMetric) { const result = new HttpMetric(); result._native = metric; return result; } return null; } get native() { return this._native; } get android() { return this.native; } getAttribute(attribute) { return this.native.getAttribute(attribute); } getAttributes() { return deserialize(this.native.getAttributes()); } putAttribute(attribute, value) { this.native.putAttribute(attribute, value); } removeAttribute(attribute) { this.native.removeAttribute(attribute); } setHttpResponseCode(code) { this.native.setHttpResponseCode(code); } setRequestPayloadSize(bytes) { this.native.setRequestPayloadSize(bytes); } setResponseContentType(contentType) { this.native.setResponseContentType(contentType); } setResponsePayloadSize(bytes) { this.native.setResponsePayloadSize(bytes); } start() { this.native.start(); } stop() { this.native.stop(); } } export class Trace { static fromNative(trace) { if (trace instanceof com.google.firebase.perf.metrics.Trace) { const result = new Trace(); result._native = trace; return result; } return null; } get native() { return this._native; } get android() { return this.native; } getAttribute(attribute) { return this.native.getAttribute(attribute); } getMetric(metricName) { return this.native.getLongMetric(metricName); } getMetrics() { return deserialize(this.native.getAttributes()); } incrementMetric(metricName, incrementBy) { this.native.incrementMetric(metricName, incrementBy); } putAttribute(attribute, value) { this.native.putAttribute(attribute, value); } putMetric(metricName, value) { this.native.putMetric(metricName, value); } removeMetric(metricName) { this.native.removeAttribute(metricName); } start() { this.native.start(); } stop() { this.native.stop(); } } export class Performance { constructor() { if (defaultPerformance) { return defaultPerformance; } defaultPerformance = this; this._native = com.google.firebase.perf.FirebasePerformance.getInstance(); } get isPerformanceCollectionEnabled() { return this.native.isPerformanceCollectionEnabled(); } set isPerformanceCollectionEnabled(value) { this.native.setPerformanceCollectionEnabled(value); } newHttpMetric(url, httpMethod) { return HttpMetric.fromNative(this.native.newHttpMetric(url, httpMethod)); } newTrace(identifier) { return Trace.fromNative(this.native.newTrace(identifier)); } startTrace(identifier) { const trace = this.newTrace(identifier); trace.start(); return trace; } get native() { return this._native; } get android() { return this.native; } get app() { if (!this._app) { // @ts-ignore this._app = FirebaseApp.fromNative(this.native.app); } return this._app; } } //# sourceMappingURL=index.android.js.map