@jaak.ai/stamps 2.2.0-dev.6 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -8
- package/dist/cjs/jaak-stamps.cjs.entry.js +657 -3118
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/collection/components/my-component/my-component.css +23 -2
- package/dist/collection/components/my-component/my-component.js +42 -16
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/collection/services/CameraService.js +41 -9
- package/dist/collection/services/CameraService.js.map +1 -1
- package/dist/collection/services/LicenseValidationService.js +2 -2
- package/dist/collection/services/LicenseValidationService.js.map +1 -1
- package/dist/collection/services/TracingService.js +130 -78
- package/dist/collection/services/TracingService.js.map +1 -1
- package/dist/collection/services/interfaces/ITracingService.js.map +1 -1
- package/dist/components/jaak-stamps.js +657 -3118
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/jaak-stamps.entry.js +657 -3118
- package/dist/esm/jaak-stamps.entry.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/p-34bcebb1.entry.js +7 -0
- package/dist/jaak-stamps-webcomponent/p-34bcebb1.entry.js.map +1 -0
- package/dist/types/components/my-component/my-component.d.ts +2 -1
- package/dist/types/components.d.ts +2 -2
- package/dist/types/services/LicenseValidationService.d.ts +1 -1
- package/dist/types/services/TracingService.d.ts +6 -1
- package/dist/types/services/interfaces/ITracingService.d.ts +5 -0
- package/package.json +1 -1
- package/dist/jaak-stamps-webcomponent/p-8c49893d.entry.js +0 -7
- package/dist/jaak-stamps-webcomponent/p-8c49893d.entry.js.map +0 -1
|
@@ -377,17 +377,30 @@ export class CameraService {
|
|
|
377
377
|
}
|
|
378
378
|
const constraints = { ...videoConstraints };
|
|
379
379
|
if (capabilities.width && capabilities.height) {
|
|
380
|
-
const maxWidth = Math.min(capabilities.width.max, 1920);
|
|
381
|
-
const maxHeight = Math.min(capabilities.height.max, 1080);
|
|
382
380
|
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
381
|
+
const isMobileDevice = this.deviceType === 'mobile' ||
|
|
382
|
+
/Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
383
|
+
// Optimize resolution based on device type to prevent "slow motion" effect
|
|
384
|
+
// on devices with high-resolution cameras
|
|
385
|
+
let targetWidth;
|
|
386
|
+
let targetHeight;
|
|
387
|
+
if (isMobileDevice && !isTablet) {
|
|
388
|
+
// Mobile phones: Use 720p max to ensure smooth detection performance
|
|
389
|
+
targetWidth = Math.min(capabilities.width.max, 1280);
|
|
390
|
+
targetHeight = Math.min(capabilities.height.max, 720);
|
|
391
|
+
}
|
|
392
|
+
else if (isTablet) {
|
|
393
|
+
// Tablets: Can handle slightly higher resolution
|
|
394
|
+
targetWidth = Math.min(capabilities.width.max, 1280);
|
|
395
|
+
targetHeight = Math.min(capabilities.height.max, 720);
|
|
386
396
|
}
|
|
387
397
|
else {
|
|
388
|
-
|
|
389
|
-
|
|
398
|
+
// Desktop: Can handle full HD
|
|
399
|
+
targetWidth = Math.min(capabilities.width.max, 1920);
|
|
400
|
+
targetHeight = Math.min(capabilities.height.max, 1080);
|
|
390
401
|
}
|
|
402
|
+
constraints.width = { ideal: targetWidth };
|
|
403
|
+
constraints.height = { ideal: targetHeight };
|
|
391
404
|
}
|
|
392
405
|
// Configure autofocus if camera has the capability
|
|
393
406
|
const capabilitiesAny = capabilities;
|
|
@@ -407,9 +420,28 @@ export class CameraService {
|
|
|
407
420
|
await this.detectDeviceType();
|
|
408
421
|
}
|
|
409
422
|
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
|
|
423
|
+
const isMobileDevice = this.deviceType === 'mobile' ||
|
|
424
|
+
/Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
425
|
+
// Optimized fallback constraints for device type
|
|
426
|
+
let fallbackWidth;
|
|
427
|
+
let fallbackHeight;
|
|
428
|
+
if (isMobileDevice && !isTablet) {
|
|
429
|
+
// Mobile phones: Use 720p for smooth performance
|
|
430
|
+
fallbackWidth = 1280;
|
|
431
|
+
fallbackHeight = 720;
|
|
432
|
+
}
|
|
433
|
+
else if (isTablet) {
|
|
434
|
+
fallbackWidth = 1280;
|
|
435
|
+
fallbackHeight = 720;
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
// Desktop
|
|
439
|
+
fallbackWidth = 1920;
|
|
440
|
+
fallbackHeight = 1080;
|
|
441
|
+
}
|
|
410
442
|
const fallbackConstraints = {
|
|
411
|
-
width: { ideal:
|
|
412
|
-
height: { ideal:
|
|
443
|
+
width: { ideal: fallbackWidth },
|
|
444
|
+
height: { ideal: fallbackHeight }
|
|
413
445
|
};
|
|
414
446
|
if (this.selectedCameraId) {
|
|
415
447
|
fallbackConstraints.deviceId = { exact: this.selectedCameraId };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CameraService.js","sourceRoot":"","sources":["../../src/services/CameraService.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAoBd;IAnBF,gBAAgB,GAAsB,EAAE,CAAC;IACzC,gBAAgB,GAAkB,IAAI,CAAC;IACvC,UAAU,GAAoC,SAAS,CAAC;IACxD,qBAAqB,GAAkC,IAAI,CAAC;IAC5D,eAAe,GAA8B,MAAM,CAAC;IAE5D,8CAA8C;IACtC,MAAM,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAA4B,CAAC;IACrE,MAAM,CAAC,sBAAsB,GAG1B,IAAI,CAAC;IACR,MAAM,CAAU,cAAc,GAAG,KAAK,CAAC,CAAC,aAAa;IAE7D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AAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC3H,CAAC;YACH,CAAC;YAED,OAAO,mBAAmB,CAAC;QAC7B,CAAC;IACH,CAAC;IAGD,8BAA8B;IACtB,gBAAgB,CAAC,CAAyB,EAAE,CAAyB;QAC3E,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,kCAAkC;IAC3B,MAAM,CAAC,WAAW;QACvB,aAAa,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;QAC9C,aAAa,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAC9C,CAAC;IAED,gDAAgD;IACzC,qBAAqB;QAC1B,aAAa,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAC9C,CAAC;IAEO,eAAe,CAAC,MAAuB;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,uBAAuB,GAAG;YAC9B,KAAK;YACL,SAAS;YACT,aAAa;YACb,SAAS;YACT,QAAQ;YACR,UAAU;YACV,OAAO;YACP,kBAAkB;YAClB,UAAU;YACV,OAAO;YACP,QAAQ;YACR,YAAY;YACZ,UAAU;YACV,cAAc;YACd,eAAe;YACf,OAAO;YACP,MAAM;YACN,iBAAiB;YACjB,WAAW;YACX,UAAU;YACV,QAAQ;YACR,UAAU;YACV,QAAQ;YACR,UAAU;YACV,WAAW;SACZ,CAAC;QAEF,OAAO,uBAAuB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9E,CAAC","sourcesContent":["import { ICameraService, CameraInfo } from './interfaces/ICameraService';\nimport { IEventBus } from './interfaces/IEventBus';\n\nexport class CameraService implements ICameraService {\n private availableCameras: MediaDeviceInfo[] = [];\n private selectedCameraId: string | null = null;\n private deviceType: 'mobile' | 'desktop' | 'tablet' = 'desktop';\n private preferredCameraFacing: 'environment' | 'user' | null = null;\n private preferredCamera: 'auto' | 'front' | 'back' = 'auto';\n\n // Optimization: Static caches for performance\n private static cameraCapabilitiesCache = new Map<string, boolean | string>();\n private static deviceEnumerationCache: {\n devices: MediaDeviceInfo[];\n timestamp: number;\n } | null = null;\n private static readonly CACHE_DURATION = 30000; // 30 seconds\n \n // Stream management for optimization\n private currentStreamPromise?: Promise<MediaStream>;\n private lastStreamConstraints?: MediaTrackConstraints;\n\n constructor(\n private eventBus: IEventBus,\n preferredCamera: 'auto' | 'front' | 'back' = 'auto'\n ) {\n this.preferredCamera = preferredCamera;\n }\n\n async detectDeviceType(): Promise<'mobile' | 'desktop' | 'tablet'> {\n const userAgent = navigator.userAgent;\n const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);\n const isTablet = /iPad|Android/i.test(userAgent) && window.innerWidth >= 768;\n \n if (isTablet) {\n this.deviceType = 'tablet';\n } else if (isMobile) {\n this.deviceType = 'mobile';\n } else {\n this.deviceType = 'desktop';\n }\n \n \n return this.deviceType;\n }\n\n async enumerateDevices(): Promise<MediaDeviceInfo[]> {\n try {\n // Check cache first for optimization\n const now = Date.now();\n if (CameraService.deviceEnumerationCache &&\n (now - CameraService.deviceEnumerationCache.timestamp) < CameraService.CACHE_DURATION) {\n this.availableCameras = CameraService.deviceEnumerationCache.devices;\n await this.setInitialCameraPreference();\n this.eventBus.emit('camera-changed', this.selectedCameraId);\n return this.availableCameras;\n }\n\n const permissionStatus = await this.checkCameraPermission();\n\n if (permissionStatus === 'denied') {\n return [];\n }\n\n if (permissionStatus === 'prompt') {\n const tempStream = await navigator.mediaDevices.getUserMedia({ video: true });\n tempStream.getTracks().forEach(track => track.stop());\n }\n\n const devices = await navigator.mediaDevices.enumerateDevices();\n const allCameras = devices.filter(device => device.kind === 'videoinput');\n\n // Filter out virtual cameras\n this.availableCameras = allCameras.filter(camera => {\n const isVirtual = this.isVirtualCamera(camera);\n if (isVirtual) {\n console.log(`Virtual camera detected and filtered: ${camera.label}`);\n }\n return !isVirtual;\n });\n\n // Check if there are physical cameras available\n if (this.availableCameras.length === 0) {\n console.log('No physical cameras available');\n this.eventBus.emit('error', new Error('Cámaras virtuales no están permitidas. Use una cámara física.'));\n return [];\n }\n\n // Cache the results for optimization\n CameraService.deviceEnumerationCache = {\n devices: this.availableCameras,\n timestamp: now\n };\n\n await this.setInitialCameraPreference();\n\n this.eventBus.emit('camera-changed', this.selectedCameraId);\n\n return this.availableCameras;\n } catch (error) {\n this.handleCameraPermissionError(error);\n return [];\n }\n }\n\n getAvailableCameras(): MediaDeviceInfo[] {\n return [...this.availableCameras];\n }\n\n isMultipleCamerasAvailable(): boolean {\n return this.availableCameras.length > 1;\n }\n\n getSelectedCameraId(): string | null {\n return this.selectedCameraId;\n }\n\n async setSelectedCamera(cameraId: string): Promise<void> {\n const camera = this.availableCameras.find(cam => cam.deviceId === cameraId);\n if (!camera) {\n throw new Error(`Camera with ID ${cameraId} not found`);\n }\n \n this.selectedCameraId = cameraId;\n this.updatePreferredFacing(camera);\n this.eventBus.emit('camera-changed', cameraId);\n }\n\n getPreferredFacing(): 'environment' | 'user' | null {\n return this.preferredCameraFacing;\n }\n\n async setupCamera(constraints?: MediaTrackConstraints): Promise<MediaStream> {\n try {\n const finalConstraints = constraints || await this.getMaxResolution();\n\n // Optimization: Check if we can reuse existing stream with same constraints\n if (this.currentStreamPromise && this.constraintsEqual(finalConstraints, this.lastStreamConstraints)) {\n return await this.currentStreamPromise;\n }\n\n // Create new stream promise for lazy loading\n this.currentStreamPromise = navigator.mediaDevices.getUserMedia({\n video: finalConstraints,\n audio: false\n });\n\n this.lastStreamConstraints = finalConstraints;\n\n const stream = await this.currentStreamPromise;\n\n // Validate that active stream is not from a virtual camera\n const videoTrack = stream.getVideoTracks()[0];\n if (videoTrack) {\n const settings = videoTrack.getSettings();\n const deviceId = settings.deviceId;\n if (deviceId) {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const currentDevice = devices.find(device => device.deviceId === deviceId);\n if (currentDevice && this.isVirtualCamera(currentDevice)) {\n console.log(`Virtual camera detected in active stream: ${currentDevice.label}`);\n stream.getTracks().forEach(track => track.stop());\n throw new Error('Cámaras virtuales no están permitidas. Use una cámara física.');\n }\n }\n }\n\n return stream;\n } catch (error) {\n\n // Fallback to basic constraints if getMaxResolution fails\n const basicConstraints: MediaTrackConstraints = {\n width: { ideal: 1280 },\n height: { ideal: 720 }\n };\n\n // Only add facingMode if not on desktop to avoid OverconstrainedError\n if (this.deviceType !== 'desktop' && this.preferredCameraFacing) {\n basicConstraints.facingMode = this.preferredCameraFacing;\n }\n\n this.currentStreamPromise = navigator.mediaDevices.getUserMedia({\n video: basicConstraints,\n audio: false\n });\n\n this.lastStreamConstraints = basicConstraints;\n\n const stream = await this.currentStreamPromise;\n\n // Validate fallback stream as well\n const videoTrack = stream.getVideoTracks()[0];\n if (videoTrack) {\n const settings = videoTrack.getSettings();\n const deviceId = settings.deviceId;\n if (deviceId) {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const currentDevice = devices.find(device => device.deviceId === deviceId);\n if (currentDevice && this.isVirtualCamera(currentDevice)) {\n console.log(`Virtual camera detected in fallback stream: ${currentDevice.label}`);\n stream.getTracks().forEach(track => track.stop());\n throw new Error('Cámaras virtuales no están permitidas. Use una cámara física.');\n }\n }\n }\n\n return stream;\n }\n }\n\n async switchCamera(cameraId: string): Promise<void> {\n const selectedCamera = this.availableCameras.find(cam => cam.deviceId === cameraId);\n if (!selectedCamera) {\n await this.enumerateDevices();\n return;\n }\n\n // Validate that the target camera is not virtual\n if (this.isVirtualCamera(selectedCamera)) {\n console.log(`Attempted to switch to virtual camera: ${selectedCamera.label}`);\n this.eventBus.emit('error', new Error('No se puede cambiar a cámara virtual'));\n return;\n }\n\n await this.setSelectedCamera(cameraId);\n }\n\n\n\n\n isRearCamera(stream: MediaStream): boolean {\n const videoTrack = stream.getVideoTracks()[0];\n if (!videoTrack) return false;\n \n const settings = videoTrack.getSettings();\n return settings.facingMode === 'environment';\n }\n\n async getCameraInfo(): Promise<{\n availableCameras: CameraInfo[];\n selectedCameraId: string | null;\n deviceType: string;\n isMultipleCamerasAvailable: boolean;\n preferredFacing: 'environment' | 'user' | null;\n }> {\n const availableCamerasWithAutofocus = await Promise.all(\n this.availableCameras.map(async (camera) => {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n return {\n id: camera.deviceId,\n label: camera.label || 'Unknown Camera',\n selected: camera.deviceId === this.selectedCameraId,\n hasAutofocus\n };\n })\n );\n\n return {\n availableCameras: availableCamerasWithAutofocus,\n selectedCameraId: this.selectedCameraId,\n deviceType: this.deviceType,\n isMultipleCamerasAvailable: this.isMultipleCamerasAvailable(),\n preferredFacing: this.preferredCameraFacing\n };\n }\n\n private async checkCameraPermission(): Promise<'granted' | 'denied' | 'prompt'> {\n try {\n if (!navigator.permissions) {\n return 'prompt';\n }\n \n const permission = await navigator.permissions.query({ name: 'camera' as PermissionName });\n return permission.state;\n } catch (error) {\n return 'prompt';\n }\n }\n\n private handleCameraPermissionError(error: any): void {\n this.availableCameras = [];\n this.eventBus.emit('error', new Error(`Camera permission error: ${error.message}`));\n }\n\n private async setInitialCameraPreference(): Promise<void> {\n if (this.availableCameras.length === 0) return;\n \n \n if (this.preferredCamera === 'front') {\n await this.selectFrontCamera();\n } else if (this.preferredCamera === 'back') {\n await this.selectBackCamera();\n } else {\n await this.selectAutoCamera();\n }\n \n }\n\n private async checkCameraAutofocus(deviceId: string): Promise<boolean> {\n try {\n // Check cache first for optimization\n if (CameraService.cameraCapabilitiesCache.has(deviceId)) {\n const cached = CameraService.cameraCapabilitiesCache.get(deviceId)!;\n return typeof cached === 'boolean' ? cached : false;\n }\n\n const stream = await navigator.mediaDevices.getUserMedia({\n video: { deviceId: { exact: deviceId } }\n });\n \n const videoTrack = stream.getVideoTracks()[0];\n const capabilities = videoTrack.getCapabilities() as any;\n \n stream.getTracks().forEach(track => track.stop());\n \n const hasFocusMode = capabilities.focusMode && Array.isArray(capabilities.focusMode) && capabilities.focusMode.length > 0;\n const hasAutofocus = hasFocusMode && (\n capabilities.focusMode.includes('continuous') || \n capabilities.focusMode.includes('auto')\n );\n \n // Cache the result for future use\n CameraService.cameraCapabilitiesCache.set(deviceId, hasAutofocus);\n \n return hasAutofocus;\n } catch (error) {\n // Cache negative result to avoid repeated failures\n CameraService.cameraCapabilitiesCache.set(deviceId, false);\n return false;\n }\n }\n\n private async selectFrontCamera(): Promise<void> {\n this.preferredCameraFacing = 'user';\n \n const frontCameras = this.availableCameras.filter(camera => {\n const label = camera.label.toLowerCase();\n return label.includes('front') || \n label.includes('user') ||\n label.includes('selfie') ||\n label.includes('frontal') ||\n (!label.includes('back') && !label.includes('rear') && !label.includes('environment'));\n });\n \n let selectedCamera = null;\n \n if (frontCameras.length > 0) {\n for (const camera of frontCameras) {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n if (hasAutofocus) {\n selectedCamera = camera;\n break;\n }\n }\n \n if (!selectedCamera) {\n selectedCamera = frontCameras[0];\n }\n }\n \n this.selectedCameraId = selectedCamera ? selectedCamera.deviceId : this.availableCameras[0].deviceId;\n }\n\n private async selectBackCamera(): Promise<void> {\n this.preferredCameraFacing = 'environment';\n \n const backCameras = this.availableCameras.filter(camera => {\n const label = camera.label.toLowerCase();\n return label.includes('back') || \n label.includes('rear') ||\n label.includes('environment') ||\n label.includes('trasera') ||\n label.includes('posterior');\n });\n \n let selectedCamera = null;\n \n if (backCameras.length > 0) {\n for (const camera of backCameras) {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n if (hasAutofocus) {\n selectedCamera = camera;\n break;\n }\n }\n \n if (!selectedCamera) {\n selectedCamera = backCameras[0];\n }\n } else if (this.availableCameras.length > 1) {\n const lastCamera = this.availableCameras[this.availableCameras.length - 1];\n const hasAutofocus = await this.checkCameraAutofocus(lastCamera.deviceId);\n selectedCamera = hasAutofocus ? lastCamera : this.availableCameras[this.availableCameras.length - 1];\n }\n \n this.selectedCameraId = selectedCamera ? selectedCamera.deviceId : this.availableCameras[0].deviceId;\n }\n\n private async selectAutoCamera(): Promise<void> {\n if (this.deviceType === 'mobile' || this.deviceType === 'tablet') {\n await this.selectBackCamera();\n } else {\n // For desktop, prefer front camera (usually built-in webcam)\n await this.selectFrontCamera();\n }\n }\n\n private updatePreferredFacing(camera: MediaDeviceInfo): void {\n const isRearCamera = camera.label.toLowerCase().includes('back') || \n camera.label.toLowerCase().includes('rear') ||\n camera.label.toLowerCase().includes('environment');\n this.preferredCameraFacing = isRearCamera ? 'environment' : 'user';\n }\n\n private async getMaxResolution(): Promise<MediaTrackConstraints> {\n try {\n // Ensure device type is detected before determining constraints\n if (!this.deviceType || this.deviceType === 'desktop') {\n await this.detectDeviceType();\n }\n \n const videoConstraints: MediaTrackConstraints = {};\n \n // Priority 1: Always use deviceId if available (ensures specific camera with autofocus)\n if (this.selectedCameraId) {\n videoConstraints.deviceId = { exact: this.selectedCameraId };\n } \n // Priority 2: Use facingMode as fallback when no specific camera is selected\n else if (this.preferredCameraFacing) {\n const facingConstraint = this.deviceType === 'desktop' \n ? { ideal: this.preferredCameraFacing }\n : { exact: this.preferredCameraFacing };\n videoConstraints.facingMode = facingConstraint;\n } \n // Priority 3: Fallback to preferredCamera setting\n else {\n if (this.preferredCamera === 'front') {\n videoConstraints.facingMode = \"user\";\n } else if (this.preferredCamera === 'back') {\n videoConstraints.facingMode = \"environment\"; \n } else {\n videoConstraints.facingMode = (this.deviceType === 'mobile' || this.deviceType === 'tablet') ? \"environment\" : \"user\";\n }\n }\n \n // Optimization: Use cached capabilities if available\n let capabilities: MediaTrackCapabilities;\n \n if (this.selectedCameraId && CameraService.cameraCapabilitiesCache.has(this.selectedCameraId + '_caps')) {\n capabilities = JSON.parse(CameraService.cameraCapabilitiesCache.get(this.selectedCameraId + '_caps') as string);\n } else {\n const tempStream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints });\n const videoTrack = tempStream.getVideoTracks()[0];\n capabilities = videoTrack.getCapabilities();\n tempStream.getTracks().forEach(track => track.stop());\n \n // Cache capabilities for future use\n if (this.selectedCameraId) {\n CameraService.cameraCapabilitiesCache.set(this.selectedCameraId + '_caps', JSON.stringify(capabilities));\n }\n }\n \n const constraints: MediaTrackConstraints = { ...videoConstraints };\n \n if (capabilities.width && capabilities.height) {\n const maxWidth = Math.min(capabilities.width.max, 1920);\n const maxHeight = Math.min(capabilities.height.max, 1080);\n \n const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;\n \n if (isTablet) {\n constraints.width = { ideal: Math.min(maxWidth, 1280) };\n constraints.height = { ideal: Math.min(maxHeight, 720) };\n } else {\n constraints.width = { ideal: maxWidth };\n constraints.height = { ideal: maxHeight };\n }\n }\n \n // Configure autofocus if camera has the capability\n const capabilitiesAny = capabilities as any;\n if (capabilitiesAny.focusMode && Array.isArray(capabilitiesAny.focusMode)) {\n if (capabilitiesAny.focusMode.includes('continuous')) {\n (constraints as any).focusMode = 'continuous';\n } else if (capabilitiesAny.focusMode.includes('auto')) {\n (constraints as any).focusMode = 'auto';\n }\n }\n \n return constraints;\n } catch (err) {\n // Fallback logic with minimal temporary streams\n if (!this.deviceType || this.deviceType === 'desktop') {\n await this.detectDeviceType();\n }\n \n const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;\n const fallbackConstraints: MediaTrackConstraints = {\n width: { ideal: isTablet ? 1280 : 1920 },\n height: { ideal: isTablet ? 720 : 1080 }\n };\n \n if (this.selectedCameraId) {\n fallbackConstraints.deviceId = { exact: this.selectedCameraId };\n } else if (this.preferredCameraFacing) {\n const facingConstraint = this.deviceType === 'desktop' \n ? { ideal: this.preferredCameraFacing }\n : { exact: this.preferredCameraFacing };\n fallbackConstraints.facingMode = facingConstraint;\n } else {\n if (this.preferredCamera === 'front') {\n fallbackConstraints.facingMode = \"user\";\n } else if (this.preferredCamera === 'back') {\n fallbackConstraints.facingMode = \"environment\"; \n } else {\n fallbackConstraints.facingMode = (this.deviceType === 'mobile' || this.deviceType === 'tablet') ? \"environment\" : \"user\";\n }\n }\n \n return fallbackConstraints;\n }\n }\n\n\n // Optimization helper methods\n private constraintsEqual(a?: MediaTrackConstraints, b?: MediaTrackConstraints): boolean {\n if (!a || !b) return false;\n return JSON.stringify(a) === JSON.stringify(b);\n }\n\n // Cleanup method for optimization\n public static clearCaches(): void {\n CameraService.cameraCapabilitiesCache.clear();\n CameraService.deviceEnumerationCache = null;\n }\n\n // Method to invalidate device cache when needed\n public invalidateDeviceCache(): void {\n CameraService.deviceEnumerationCache = null;\n }\n\n private isVirtualCamera(device: MediaDeviceInfo): boolean {\n const label = device.label.toLowerCase();\n const virtualCameraIndicators = [\n 'obs',\n 'virtual',\n 'snap camera',\n 'manycam',\n 'xsplit',\n 'camtwist',\n 'ecamm',\n 'nvidia broadcast',\n 'droidcam',\n 'iriun',\n 'elgato',\n 'streamlabs',\n 'wirecast',\n 'zoom virtual',\n 'teams virtual',\n 'mmhmm',\n 'camo',\n 'reincubate camo',\n 'webcamoid',\n 'splitcam',\n 'cheese',\n 'guvcview',\n 'yawcam',\n 'webcam 7',\n 'altserver'\n ];\n\n return virtualCameraIndicators.some(indicator => label.includes(indicator));\n }\n\n}"]}
|
|
1
|
+
{"version":3,"file":"CameraService.js","sourceRoot":"","sources":["../../src/services/CameraService.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAoBd;IAnBF,gBAAgB,GAAsB,EAAE,CAAC;IACzC,gBAAgB,GAAkB,IAAI,CAAC;IACvC,UAAU,GAAoC,SAAS,CAAC;IACxD,qBAAqB,GAAkC,IAAI,CAAC;IAC5D,eAAe,GAA8B,MAAM,CAAC;IAE5D,8CAA8C;IACtC,MAAM,CAAC,uBAAuB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AgB,CAAC,CAAyB,EAAE,CAAyB;QAC3E,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,kCAAkC;IAC3B,MAAM,CAAC,WAAW;QACvB,aAAa,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;QAC9C,aAAa,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAC9C,CAAC;IAED,gDAAgD;IACzC,qBAAqB;QAC1B,aAAa,CAAC,sBAAsB,GAAG,IAAI,CAAC;IAC9C,CAAC;IAEO,eAAe,CAAC,MAAuB;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,uBAAuB,GAAG;YAC9B,KAAK;YACL,SAAS;YACT,aAAa;YACb,SAAS;YACT,QAAQ;YACR,UAAU;YACV,OAAO;YACP,kBAAkB;YAClB,UAAU;YACV,OAAO;YACP,QAAQ;YACR,YAAY;YACZ,UAAU;YACV,cAAc;YACd,eAAe;YACf,OAAO;YACP,MAAM;YACN,iBAAiB;YACjB,WAAW;YACX,UAAU;YACV,QAAQ;YACR,UAAU;YACV,QAAQ;YACR,UAAU;YACV,WAAW;SACZ,CAAC;QAEF,OAAO,uBAAuB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9E,CAAC","sourcesContent":["import { ICameraService, CameraInfo } from './interfaces/ICameraService';\nimport { IEventBus } from './interfaces/IEventBus';\n\nexport class CameraService implements ICameraService {\n private availableCameras: MediaDeviceInfo[] = [];\n private selectedCameraId: string | null = null;\n private deviceType: 'mobile' | 'desktop' | 'tablet' = 'desktop';\n private preferredCameraFacing: 'environment' | 'user' | null = null;\n private preferredCamera: 'auto' | 'front' | 'back' = 'auto';\n\n // Optimization: Static caches for performance\n private static cameraCapabilitiesCache = new Map<string, boolean | string>();\n private static deviceEnumerationCache: {\n devices: MediaDeviceInfo[];\n timestamp: number;\n } | null = null;\n private static readonly CACHE_DURATION = 30000; // 30 seconds\n \n // Stream management for optimization\n private currentStreamPromise?: Promise<MediaStream>;\n private lastStreamConstraints?: MediaTrackConstraints;\n\n constructor(\n private eventBus: IEventBus,\n preferredCamera: 'auto' | 'front' | 'back' = 'auto'\n ) {\n this.preferredCamera = preferredCamera;\n }\n\n async detectDeviceType(): Promise<'mobile' | 'desktop' | 'tablet'> {\n const userAgent = navigator.userAgent;\n const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);\n const isTablet = /iPad|Android/i.test(userAgent) && window.innerWidth >= 768;\n \n if (isTablet) {\n this.deviceType = 'tablet';\n } else if (isMobile) {\n this.deviceType = 'mobile';\n } else {\n this.deviceType = 'desktop';\n }\n \n \n return this.deviceType;\n }\n\n async enumerateDevices(): Promise<MediaDeviceInfo[]> {\n try {\n // Check cache first for optimization\n const now = Date.now();\n if (CameraService.deviceEnumerationCache &&\n (now - CameraService.deviceEnumerationCache.timestamp) < CameraService.CACHE_DURATION) {\n this.availableCameras = CameraService.deviceEnumerationCache.devices;\n await this.setInitialCameraPreference();\n this.eventBus.emit('camera-changed', this.selectedCameraId);\n return this.availableCameras;\n }\n\n const permissionStatus = await this.checkCameraPermission();\n\n if (permissionStatus === 'denied') {\n return [];\n }\n\n if (permissionStatus === 'prompt') {\n const tempStream = await navigator.mediaDevices.getUserMedia({ video: true });\n tempStream.getTracks().forEach(track => track.stop());\n }\n\n const devices = await navigator.mediaDevices.enumerateDevices();\n const allCameras = devices.filter(device => device.kind === 'videoinput');\n\n // Filter out virtual cameras\n this.availableCameras = allCameras.filter(camera => {\n const isVirtual = this.isVirtualCamera(camera);\n if (isVirtual) {\n console.log(`Virtual camera detected and filtered: ${camera.label}`);\n }\n return !isVirtual;\n });\n\n // Check if there are physical cameras available\n if (this.availableCameras.length === 0) {\n console.log('No physical cameras available');\n this.eventBus.emit('error', new Error('Cámaras virtuales no están permitidas. Use una cámara física.'));\n return [];\n }\n\n // Cache the results for optimization\n CameraService.deviceEnumerationCache = {\n devices: this.availableCameras,\n timestamp: now\n };\n\n await this.setInitialCameraPreference();\n\n this.eventBus.emit('camera-changed', this.selectedCameraId);\n\n return this.availableCameras;\n } catch (error) {\n this.handleCameraPermissionError(error);\n return [];\n }\n }\n\n getAvailableCameras(): MediaDeviceInfo[] {\n return [...this.availableCameras];\n }\n\n isMultipleCamerasAvailable(): boolean {\n return this.availableCameras.length > 1;\n }\n\n getSelectedCameraId(): string | null {\n return this.selectedCameraId;\n }\n\n async setSelectedCamera(cameraId: string): Promise<void> {\n const camera = this.availableCameras.find(cam => cam.deviceId === cameraId);\n if (!camera) {\n throw new Error(`Camera with ID ${cameraId} not found`);\n }\n \n this.selectedCameraId = cameraId;\n this.updatePreferredFacing(camera);\n this.eventBus.emit('camera-changed', cameraId);\n }\n\n getPreferredFacing(): 'environment' | 'user' | null {\n return this.preferredCameraFacing;\n }\n\n async setupCamera(constraints?: MediaTrackConstraints): Promise<MediaStream> {\n try {\n const finalConstraints = constraints || await this.getMaxResolution();\n\n // Optimization: Check if we can reuse existing stream with same constraints\n if (this.currentStreamPromise && this.constraintsEqual(finalConstraints, this.lastStreamConstraints)) {\n return await this.currentStreamPromise;\n }\n\n // Create new stream promise for lazy loading\n this.currentStreamPromise = navigator.mediaDevices.getUserMedia({\n video: finalConstraints,\n audio: false\n });\n\n this.lastStreamConstraints = finalConstraints;\n\n const stream = await this.currentStreamPromise;\n\n // Validate that active stream is not from a virtual camera\n const videoTrack = stream.getVideoTracks()[0];\n if (videoTrack) {\n const settings = videoTrack.getSettings();\n const deviceId = settings.deviceId;\n if (deviceId) {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const currentDevice = devices.find(device => device.deviceId === deviceId);\n if (currentDevice && this.isVirtualCamera(currentDevice)) {\n console.log(`Virtual camera detected in active stream: ${currentDevice.label}`);\n stream.getTracks().forEach(track => track.stop());\n throw new Error('Cámaras virtuales no están permitidas. Use una cámara física.');\n }\n }\n }\n\n return stream;\n } catch (error) {\n\n // Fallback to basic constraints if getMaxResolution fails\n const basicConstraints: MediaTrackConstraints = {\n width: { ideal: 1280 },\n height: { ideal: 720 }\n };\n\n // Only add facingMode if not on desktop to avoid OverconstrainedError\n if (this.deviceType !== 'desktop' && this.preferredCameraFacing) {\n basicConstraints.facingMode = this.preferredCameraFacing;\n }\n\n this.currentStreamPromise = navigator.mediaDevices.getUserMedia({\n video: basicConstraints,\n audio: false\n });\n\n this.lastStreamConstraints = basicConstraints;\n\n const stream = await this.currentStreamPromise;\n\n // Validate fallback stream as well\n const videoTrack = stream.getVideoTracks()[0];\n if (videoTrack) {\n const settings = videoTrack.getSettings();\n const deviceId = settings.deviceId;\n if (deviceId) {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const currentDevice = devices.find(device => device.deviceId === deviceId);\n if (currentDevice && this.isVirtualCamera(currentDevice)) {\n console.log(`Virtual camera detected in fallback stream: ${currentDevice.label}`);\n stream.getTracks().forEach(track => track.stop());\n throw new Error('Cámaras virtuales no están permitidas. Use una cámara física.');\n }\n }\n }\n\n return stream;\n }\n }\n\n async switchCamera(cameraId: string): Promise<void> {\n const selectedCamera = this.availableCameras.find(cam => cam.deviceId === cameraId);\n if (!selectedCamera) {\n await this.enumerateDevices();\n return;\n }\n\n // Validate that the target camera is not virtual\n if (this.isVirtualCamera(selectedCamera)) {\n console.log(`Attempted to switch to virtual camera: ${selectedCamera.label}`);\n this.eventBus.emit('error', new Error('No se puede cambiar a cámara virtual'));\n return;\n }\n\n await this.setSelectedCamera(cameraId);\n }\n\n\n\n\n isRearCamera(stream: MediaStream): boolean {\n const videoTrack = stream.getVideoTracks()[0];\n if (!videoTrack) return false;\n \n const settings = videoTrack.getSettings();\n return settings.facingMode === 'environment';\n }\n\n async getCameraInfo(): Promise<{\n availableCameras: CameraInfo[];\n selectedCameraId: string | null;\n deviceType: string;\n isMultipleCamerasAvailable: boolean;\n preferredFacing: 'environment' | 'user' | null;\n }> {\n const availableCamerasWithAutofocus = await Promise.all(\n this.availableCameras.map(async (camera) => {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n return {\n id: camera.deviceId,\n label: camera.label || 'Unknown Camera',\n selected: camera.deviceId === this.selectedCameraId,\n hasAutofocus\n };\n })\n );\n\n return {\n availableCameras: availableCamerasWithAutofocus,\n selectedCameraId: this.selectedCameraId,\n deviceType: this.deviceType,\n isMultipleCamerasAvailable: this.isMultipleCamerasAvailable(),\n preferredFacing: this.preferredCameraFacing\n };\n }\n\n private async checkCameraPermission(): Promise<'granted' | 'denied' | 'prompt'> {\n try {\n if (!navigator.permissions) {\n return 'prompt';\n }\n \n const permission = await navigator.permissions.query({ name: 'camera' as PermissionName });\n return permission.state;\n } catch (error) {\n return 'prompt';\n }\n }\n\n private handleCameraPermissionError(error: any): void {\n this.availableCameras = [];\n this.eventBus.emit('error', new Error(`Camera permission error: ${error.message}`));\n }\n\n private async setInitialCameraPreference(): Promise<void> {\n if (this.availableCameras.length === 0) return;\n \n \n if (this.preferredCamera === 'front') {\n await this.selectFrontCamera();\n } else if (this.preferredCamera === 'back') {\n await this.selectBackCamera();\n } else {\n await this.selectAutoCamera();\n }\n \n }\n\n private async checkCameraAutofocus(deviceId: string): Promise<boolean> {\n try {\n // Check cache first for optimization\n if (CameraService.cameraCapabilitiesCache.has(deviceId)) {\n const cached = CameraService.cameraCapabilitiesCache.get(deviceId)!;\n return typeof cached === 'boolean' ? cached : false;\n }\n\n const stream = await navigator.mediaDevices.getUserMedia({\n video: { deviceId: { exact: deviceId } }\n });\n \n const videoTrack = stream.getVideoTracks()[0];\n const capabilities = videoTrack.getCapabilities() as any;\n \n stream.getTracks().forEach(track => track.stop());\n \n const hasFocusMode = capabilities.focusMode && Array.isArray(capabilities.focusMode) && capabilities.focusMode.length > 0;\n const hasAutofocus = hasFocusMode && (\n capabilities.focusMode.includes('continuous') || \n capabilities.focusMode.includes('auto')\n );\n \n // Cache the result for future use\n CameraService.cameraCapabilitiesCache.set(deviceId, hasAutofocus);\n \n return hasAutofocus;\n } catch (error) {\n // Cache negative result to avoid repeated failures\n CameraService.cameraCapabilitiesCache.set(deviceId, false);\n return false;\n }\n }\n\n private async selectFrontCamera(): Promise<void> {\n this.preferredCameraFacing = 'user';\n \n const frontCameras = this.availableCameras.filter(camera => {\n const label = camera.label.toLowerCase();\n return label.includes('front') || \n label.includes('user') ||\n label.includes('selfie') ||\n label.includes('frontal') ||\n (!label.includes('back') && !label.includes('rear') && !label.includes('environment'));\n });\n \n let selectedCamera = null;\n \n if (frontCameras.length > 0) {\n for (const camera of frontCameras) {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n if (hasAutofocus) {\n selectedCamera = camera;\n break;\n }\n }\n \n if (!selectedCamera) {\n selectedCamera = frontCameras[0];\n }\n }\n \n this.selectedCameraId = selectedCamera ? selectedCamera.deviceId : this.availableCameras[0].deviceId;\n }\n\n private async selectBackCamera(): Promise<void> {\n this.preferredCameraFacing = 'environment';\n \n const backCameras = this.availableCameras.filter(camera => {\n const label = camera.label.toLowerCase();\n return label.includes('back') || \n label.includes('rear') ||\n label.includes('environment') ||\n label.includes('trasera') ||\n label.includes('posterior');\n });\n \n let selectedCamera = null;\n \n if (backCameras.length > 0) {\n for (const camera of backCameras) {\n const hasAutofocus = await this.checkCameraAutofocus(camera.deviceId);\n if (hasAutofocus) {\n selectedCamera = camera;\n break;\n }\n }\n \n if (!selectedCamera) {\n selectedCamera = backCameras[0];\n }\n } else if (this.availableCameras.length > 1) {\n const lastCamera = this.availableCameras[this.availableCameras.length - 1];\n const hasAutofocus = await this.checkCameraAutofocus(lastCamera.deviceId);\n selectedCamera = hasAutofocus ? lastCamera : this.availableCameras[this.availableCameras.length - 1];\n }\n \n this.selectedCameraId = selectedCamera ? selectedCamera.deviceId : this.availableCameras[0].deviceId;\n }\n\n private async selectAutoCamera(): Promise<void> {\n if (this.deviceType === 'mobile' || this.deviceType === 'tablet') {\n await this.selectBackCamera();\n } else {\n // For desktop, prefer front camera (usually built-in webcam)\n await this.selectFrontCamera();\n }\n }\n\n private updatePreferredFacing(camera: MediaDeviceInfo): void {\n const isRearCamera = camera.label.toLowerCase().includes('back') || \n camera.label.toLowerCase().includes('rear') ||\n camera.label.toLowerCase().includes('environment');\n this.preferredCameraFacing = isRearCamera ? 'environment' : 'user';\n }\n\n private async getMaxResolution(): Promise<MediaTrackConstraints> {\n try {\n // Ensure device type is detected before determining constraints\n if (!this.deviceType || this.deviceType === 'desktop') {\n await this.detectDeviceType();\n }\n \n const videoConstraints: MediaTrackConstraints = {};\n \n // Priority 1: Always use deviceId if available (ensures specific camera with autofocus)\n if (this.selectedCameraId) {\n videoConstraints.deviceId = { exact: this.selectedCameraId };\n } \n // Priority 2: Use facingMode as fallback when no specific camera is selected\n else if (this.preferredCameraFacing) {\n const facingConstraint = this.deviceType === 'desktop' \n ? { ideal: this.preferredCameraFacing }\n : { exact: this.preferredCameraFacing };\n videoConstraints.facingMode = facingConstraint;\n } \n // Priority 3: Fallback to preferredCamera setting\n else {\n if (this.preferredCamera === 'front') {\n videoConstraints.facingMode = \"user\";\n } else if (this.preferredCamera === 'back') {\n videoConstraints.facingMode = \"environment\"; \n } else {\n videoConstraints.facingMode = (this.deviceType === 'mobile' || this.deviceType === 'tablet') ? \"environment\" : \"user\";\n }\n }\n \n // Optimization: Use cached capabilities if available\n let capabilities: MediaTrackCapabilities;\n \n if (this.selectedCameraId && CameraService.cameraCapabilitiesCache.has(this.selectedCameraId + '_caps')) {\n capabilities = JSON.parse(CameraService.cameraCapabilitiesCache.get(this.selectedCameraId + '_caps') as string);\n } else {\n const tempStream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints });\n const videoTrack = tempStream.getVideoTracks()[0];\n capabilities = videoTrack.getCapabilities();\n tempStream.getTracks().forEach(track => track.stop());\n \n // Cache capabilities for future use\n if (this.selectedCameraId) {\n CameraService.cameraCapabilitiesCache.set(this.selectedCameraId + '_caps', JSON.stringify(capabilities));\n }\n }\n \n const constraints: MediaTrackConstraints = { ...videoConstraints };\n \n if (capabilities.width && capabilities.height) {\n const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;\n const isMobileDevice = this.deviceType === 'mobile' ||\n /Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n\n // Optimize resolution based on device type to prevent \"slow motion\" effect\n // on devices with high-resolution cameras\n let targetWidth: number;\n let targetHeight: number;\n\n if (isMobileDevice && !isTablet) {\n // Mobile phones: Use 720p max to ensure smooth detection performance\n targetWidth = Math.min(capabilities.width.max, 1280);\n targetHeight = Math.min(capabilities.height.max, 720);\n } else if (isTablet) {\n // Tablets: Can handle slightly higher resolution\n targetWidth = Math.min(capabilities.width.max, 1280);\n targetHeight = Math.min(capabilities.height.max, 720);\n } else {\n // Desktop: Can handle full HD\n targetWidth = Math.min(capabilities.width.max, 1920);\n targetHeight = Math.min(capabilities.height.max, 1080);\n }\n\n constraints.width = { ideal: targetWidth };\n constraints.height = { ideal: targetHeight };\n }\n \n // Configure autofocus if camera has the capability\n const capabilitiesAny = capabilities as any;\n if (capabilitiesAny.focusMode && Array.isArray(capabilitiesAny.focusMode)) {\n if (capabilitiesAny.focusMode.includes('continuous')) {\n (constraints as any).focusMode = 'continuous';\n } else if (capabilitiesAny.focusMode.includes('auto')) {\n (constraints as any).focusMode = 'auto';\n }\n }\n \n return constraints;\n } catch (err) {\n // Fallback logic with minimal temporary streams\n if (!this.deviceType || this.deviceType === 'desktop') {\n await this.detectDeviceType();\n }\n \n const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;\n const isMobileDevice = this.deviceType === 'mobile' ||\n /Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n\n // Optimized fallback constraints for device type\n let fallbackWidth: number;\n let fallbackHeight: number;\n\n if (isMobileDevice && !isTablet) {\n // Mobile phones: Use 720p for smooth performance\n fallbackWidth = 1280;\n fallbackHeight = 720;\n } else if (isTablet) {\n fallbackWidth = 1280;\n fallbackHeight = 720;\n } else {\n // Desktop\n fallbackWidth = 1920;\n fallbackHeight = 1080;\n }\n\n const fallbackConstraints: MediaTrackConstraints = {\n width: { ideal: fallbackWidth },\n height: { ideal: fallbackHeight }\n };\n \n if (this.selectedCameraId) {\n fallbackConstraints.deviceId = { exact: this.selectedCameraId };\n } else if (this.preferredCameraFacing) {\n const facingConstraint = this.deviceType === 'desktop' \n ? { ideal: this.preferredCameraFacing }\n : { exact: this.preferredCameraFacing };\n fallbackConstraints.facingMode = facingConstraint;\n } else {\n if (this.preferredCamera === 'front') {\n fallbackConstraints.facingMode = \"user\";\n } else if (this.preferredCamera === 'back') {\n fallbackConstraints.facingMode = \"environment\"; \n } else {\n fallbackConstraints.facingMode = (this.deviceType === 'mobile' || this.deviceType === 'tablet') ? \"environment\" : \"user\";\n }\n }\n \n return fallbackConstraints;\n }\n }\n\n\n // Optimization helper methods\n private constraintsEqual(a?: MediaTrackConstraints, b?: MediaTrackConstraints): boolean {\n if (!a || !b) return false;\n return JSON.stringify(a) === JSON.stringify(b);\n }\n\n // Cleanup method for optimization\n public static clearCaches(): void {\n CameraService.cameraCapabilitiesCache.clear();\n CameraService.deviceEnumerationCache = null;\n }\n\n // Method to invalidate device cache when needed\n public invalidateDeviceCache(): void {\n CameraService.deviceEnumerationCache = null;\n }\n\n private isVirtualCamera(device: MediaDeviceInfo): boolean {\n const label = device.label.toLowerCase();\n const virtualCameraIndicators = [\n 'obs',\n 'virtual',\n 'snap camera',\n 'manycam',\n 'xsplit',\n 'camtwist',\n 'ecamm',\n 'nvidia broadcast',\n 'droidcam',\n 'iriun',\n 'elgato',\n 'streamlabs',\n 'wirecast',\n 'zoom virtual',\n 'teams virtual',\n 'mmhmm',\n 'camo',\n 'reincubate camo',\n 'webcamoid',\n 'splitcam',\n 'cheese',\n 'guvcview',\n 'yawcam',\n 'webcam 7',\n 'altserver'\n ];\n\n return virtualCameraIndicators.some(indicator => label.includes(indicator));\n }\n\n}"]}
|
|
@@ -9,8 +9,8 @@ export class LicenseValidationService {
|
|
|
9
9
|
static ENVIRONMENT_URLS = {
|
|
10
10
|
dev: 'https://api.dev.jaak.ai',
|
|
11
11
|
qa: 'https://api.qa.jaak.ai',
|
|
12
|
-
|
|
13
|
-
prod: 'https://api.jaak.ai',
|
|
12
|
+
sandbox: 'https://api.sandbox.jaak.ai',
|
|
13
|
+
prod: 'https://services.api.jaak.ai',
|
|
14
14
|
};
|
|
15
15
|
constructor(environment = 'prod') {
|
|
16
16
|
this.baseUrl = LicenseValidationService.ENVIRONMENT_URLS[environment];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicenseValidationService.js","sourceRoot":"","sources":["../../src/services/LicenseValidationService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgCH,MAAM,OAAO,wBAAwB;IAC3B,WAAW,GAAW,0BAA0B,CAAC;IACjD,OAAO,CAAS;IAExB,iCAAiC;IACzB,MAAM,CAAU,gBAAgB,GAAgC;QACtE,GAAG,EAAE,yBAAyB;QAC9B,EAAE,EAAE,wBAAwB;QAC5B,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"LicenseValidationService.js","sourceRoot":"","sources":["../../src/services/LicenseValidationService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgCH,MAAM,OAAO,wBAAwB;IAC3B,WAAW,GAAW,0BAA0B,CAAC;IACjD,OAAO,CAAS;IAExB,iCAAiC;IACzB,MAAM,CAAU,gBAAgB,GAAgC;QACtE,GAAG,EAAE,yBAAyB;QAC9B,EAAE,EAAE,wBAAwB;QAC5B,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,8BAA8B;KACrC,CAAC;IAEF,YAAY,cAA2B,MAAM;QAC3C,IA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O,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,+BAA+B;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAErE,sCAAsC;QACtC,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;QAC/B,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,iEAAiE,EAAE,OAAO,CAAC,CAAC;QACzF,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["/**\n * License Validation Service\n * Handles license validation for the jaak-stamps webcomponent\n */\n\nexport type Environment = 'dev' | 'qa' | 'sandbox' | 'prod';\n\nexport interface LicenseValidationRequest {\n license: string;\n origin: string;\n app_id?: string;\n product?: string;\n product_version?: string;\n metadata?: {\n [key: string]: any;\n };\n}\n\nexport interface LicenseValidationResponse {\n access_token: string;\n token_type: string;\n expires_at: string;\n session_id: string;\n jti: string;\n step: number;\n license: string;\n traceId?: string; // Generated or provided traceId\n}\n\nexport interface LicenseValidationError {\n error: string;\n error_description?: string;\n status_code?: number;\n}\n\nexport class LicenseValidationService {\n private apiEndpoint: string = '/api/v1/license/validate';\n private baseUrl: string;\n\n // Environment-specific base URLs\n private static readonly ENVIRONMENT_URLS: Record<Environment, string> = {\n dev: 'https://api.dev.jaak.ai',\n qa: 'https://api.qa.jaak.ai',\n sandbox: 'https://api.sandbox.jaak.ai',\n prod: 'https://services.api.jaak.ai',\n };\n\n constructor(environment: Environment = 'prod') {\n this.baseUrl = LicenseValidationService.ENVIRONMENT_URLS[environment];\n }\n\n /**\n * Validate license with the API\n * @param license License key to validate\n * @param traceId Optional trace ID from W3C Trace Context\n * @param appId Optional application ID\n * @param metadata Optional additional metadata\n * @returns Promise<LicenseValidationResponse>\n */\n async validateLicense(\n license: string,\n traceId?: string,\n appId: string = 'jaak-stamps-web',\n ): Promise<LicenseValidationResponse> {\n // Generate traceId if not provided\n const effectiveTraceId = traceId || this.generateTraceId();\n\n // Build request body\n const requestBody: LicenseValidationRequest = {\n license: traceId ? `L${effectiveTraceId}` : license,\n origin: 'web',\n app_id: appId,\n product: 'kyc',\n metadata: {\n sdk_version: '2.1.0',\n },\n };\n\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n };\n\n // Add traceparent header with the effective traceId\n headers['traceparent'] = `00-${effectiveTraceId}-${this.generateSpanId()}-01`;\n\n try {\n const response = await fetch(`${this.baseUrl}${this.apiEndpoint}`, {\n method: 'POST',\n headers,\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw {\n error: errorData.error || 'license_validation_failed',\n error_description: errorData.error_description || `HTTP ${response.status}: ${response.statusText}`,\n status_code: response.status,\n } as LicenseValidationError;\n }\n\n const responseData = await response.json();\n // Add the traceId to the response\n return {\n ...responseData,\n traceId: effectiveTraceId,\n };\n } catch (error) {\n if ((error as any).error) {\n throw error;\n }\n\n throw {\n error: 'network_error',\n error_description: 'Failed to connect to license validation service',\n status_code: 0,\n } as LicenseValidationError;\n }\n }\n\n /**\n * Generate a random trace ID for W3C Trace Context (32 hex characters)\n */\n private generateTraceId(): string {\n const array = new Uint8Array(16);\n crypto.getRandomValues(array);\n return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n }\n\n /**\n * Generate a random span ID for W3C Trace Context (16 hex characters)\n */\n private generateSpanId(): string {\n const array = new Uint8Array(8);\n crypto.getRandomValues(array);\n return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n }\n\n /**\n * Extract trace ID from license field\n * License format: \"L<32-hex-chars>\"\n * Example: \"Ld79223833a2fd91971e4c14a33298904\" -> \"d79223833a2fd91971e4c14a33298904\"\n */\n static extractTraceIdFromLicense(license: string): string | null {\n if (!license || typeof license !== 'string') {\n return null;\n }\n\n // Remove \"L\" prefix if present\n const traceId = license.startsWith('L') ? license.slice(1) : license;\n\n // Validate format (32 hex characters)\n if (traceId.length === 32 && /^[a-f0-9]{32}$/i.test(traceId)) {\n return traceId.toLowerCase();\n }\n\n console.warn('[LicenseValidationService] Invalid license format for trace ID:', license);\n return null;\n }\n}\n"]}
|
|
@@ -1,18 +1,74 @@
|
|
|
1
|
-
import { trace, SpanStatusCode, context } from "@opentelemetry/api";
|
|
1
|
+
import { trace, SpanStatusCode, context, TraceFlags } from "@opentelemetry/api";
|
|
2
2
|
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
|
|
3
3
|
import { BatchSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
5
|
import { ZoneContextManager } from "@opentelemetry/context-zone";
|
|
6
6
|
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
7
7
|
import { registerInstrumentations } from "@opentelemetry/instrumentation";
|
|
8
|
-
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
|
|
9
|
-
import { XMLHttpRequestInstrumentation } from "@opentelemetry/instrumentation-xml-http-request";
|
|
10
8
|
import { UserInteractionInstrumentation } from "@opentelemetry/instrumentation-user-interaction";
|
|
11
|
-
import { DocumentLoadInstrumentation } from "@opentelemetry/instrumentation-document-load";
|
|
12
9
|
import UAParser from "ua-parser-js";
|
|
13
10
|
// Semantic convention attribute names
|
|
14
11
|
const ATTR_SERVICE_NAME = 'service.name';
|
|
15
12
|
const ATTR_SERVICE_VERSION = 'service.version';
|
|
13
|
+
// Token de autenticación para OpenTelemetry Collector
|
|
14
|
+
const AUTH_TOKEN = 'eAzROSTiqNd3i+M9Jw6q5Tld0jarZc617sJB//pvb5c=';
|
|
15
|
+
// Instalar interceptores globalmente UNA SOLA VEZ antes de cualquier inicialización
|
|
16
|
+
let interceptorsInstalled = false;
|
|
17
|
+
function installAuthInterceptors() {
|
|
18
|
+
if (interceptorsInstalled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
interceptorsInstalled = true;
|
|
22
|
+
// Guardar referencia al XHR original ANTES de que OpenTelemetry lo toque
|
|
23
|
+
const RealXHR = window.XMLHttpRequest;
|
|
24
|
+
if (!RealXHR) {
|
|
25
|
+
console.error('[TracingService] XMLHttpRequest not available');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Crear wrapper que agrega el header
|
|
29
|
+
window.XMLHttpRequest = function () {
|
|
30
|
+
const xhr = new RealXHR();
|
|
31
|
+
const originalOpen = xhr.open;
|
|
32
|
+
const originalSend = xhr.send;
|
|
33
|
+
let isCollectorRequest = false;
|
|
34
|
+
xhr.open = function (method, url, ...args) {
|
|
35
|
+
const urlString = typeof url === 'string' ? url : url.toString();
|
|
36
|
+
isCollectorRequest = urlString.includes('collector.jaak.ai');
|
|
37
|
+
return originalOpen.apply(this, [method, url, ...args]);
|
|
38
|
+
};
|
|
39
|
+
xhr.send = function (...args) {
|
|
40
|
+
if (isCollectorRequest) {
|
|
41
|
+
this.setRequestHeader('Authorization', `Bearer ${AUTH_TOKEN}`);
|
|
42
|
+
}
|
|
43
|
+
return originalSend.apply(this, args);
|
|
44
|
+
};
|
|
45
|
+
return xhr;
|
|
46
|
+
};
|
|
47
|
+
// Copiar propiedades del constructor original
|
|
48
|
+
for (const prop in RealXHR) {
|
|
49
|
+
if (RealXHR.hasOwnProperty(prop)) {
|
|
50
|
+
window.XMLHttpRequest[prop] = RealXHR[prop];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// También interceptar fetch por si el SDK lo usa en lugar de XHR
|
|
54
|
+
const originalFetch = window.fetch;
|
|
55
|
+
window.fetch = function (input, init) {
|
|
56
|
+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
57
|
+
if (url.includes('collector.jaak.ai')) {
|
|
58
|
+
const headers = new Headers(init?.headers || {});
|
|
59
|
+
headers.set('Authorization', `Bearer ${AUTH_TOKEN}`);
|
|
60
|
+
init = {
|
|
61
|
+
...init,
|
|
62
|
+
headers: headers,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return originalFetch.call(this, input, init);
|
|
66
|
+
};
|
|
67
|
+
// Deshabilitar sendBeacon globalmente porque no soporta headers personalizados
|
|
68
|
+
navigator.sendBeacon = function () {
|
|
69
|
+
return false; // Retornar false fuerza al SDK a usar XHR/Fetch como fallback
|
|
70
|
+
};
|
|
71
|
+
}
|
|
16
72
|
export class TracingService {
|
|
17
73
|
provider = null;
|
|
18
74
|
tracer = null;
|
|
@@ -24,7 +80,6 @@ export class TracingService {
|
|
|
24
80
|
customerId;
|
|
25
81
|
tenantId;
|
|
26
82
|
environment;
|
|
27
|
-
propagateTraceHeaderCorsUrls;
|
|
28
83
|
enableAutoInstrumentation;
|
|
29
84
|
spanProcessor = null;
|
|
30
85
|
parser;
|
|
@@ -39,19 +94,43 @@ export class TracingService {
|
|
|
39
94
|
this.customerId = config.customerId;
|
|
40
95
|
this.tenantId = config.tenantId;
|
|
41
96
|
this.environment = config.environment || 'production';
|
|
42
|
-
this.propagateTraceHeaderCorsUrls = config.propagateTraceHeaderCorsUrls || [];
|
|
43
97
|
this.enableAutoInstrumentation = config.enableAutoInstrumentation ?? false; // Default to false
|
|
44
98
|
this.parser = new UAParser();
|
|
45
99
|
}
|
|
46
100
|
initialize() {
|
|
47
101
|
try {
|
|
102
|
+
// Instalar interceptores de autenticación ANTES de crear el exporter
|
|
103
|
+
installAuthInterceptors();
|
|
48
104
|
// Create OTLP exporter
|
|
49
|
-
const
|
|
105
|
+
const baseExporter = new OTLPTraceExporter({
|
|
50
106
|
url: this.collectorUrl,
|
|
51
107
|
headers: {
|
|
52
108
|
'Content-Type': 'application/json',
|
|
109
|
+
'Authorization': `Bearer ${AUTH_TOKEN}`,
|
|
53
110
|
},
|
|
111
|
+
// @ts-ignore - useSendBeacon no está en los tipos pero es soportada
|
|
112
|
+
useSendBeacon: false,
|
|
54
113
|
});
|
|
114
|
+
// Wrap exporter to log export attempts
|
|
115
|
+
const exporter = {
|
|
116
|
+
export: (spans, resultCallback) => {
|
|
117
|
+
if (this.debug) {
|
|
118
|
+
console.log('[TracingService] 📤 Exporting', spans.length, 'spans to collector');
|
|
119
|
+
}
|
|
120
|
+
baseExporter.export(spans, (result) => {
|
|
121
|
+
if (result.code !== 0) {
|
|
122
|
+
console.error('[TracingService] ❌ Export failed:', result);
|
|
123
|
+
}
|
|
124
|
+
resultCallback(result);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
shutdown: async () => {
|
|
128
|
+
return baseExporter.shutdown();
|
|
129
|
+
},
|
|
130
|
+
forceFlush: async () => {
|
|
131
|
+
return baseExporter.forceFlush();
|
|
132
|
+
},
|
|
133
|
+
};
|
|
55
134
|
// Create console exporter for debug mode
|
|
56
135
|
const exporters = [exporter];
|
|
57
136
|
if (this.debug) {
|
|
@@ -76,12 +155,10 @@ export class TracingService {
|
|
|
76
155
|
if (this.tenantId) {
|
|
77
156
|
resourceAttributes['tenant.id'] = this.tenantId;
|
|
78
157
|
}
|
|
79
|
-
// Create tracer provider with
|
|
158
|
+
// Create tracer provider with span processor in constructor
|
|
80
159
|
this.provider = new WebTracerProvider({
|
|
81
|
-
|
|
160
|
+
spanProcessors: [this.spanProcessor],
|
|
82
161
|
});
|
|
83
|
-
// Add span processor
|
|
84
|
-
this.provider.addSpanProcessor?.(this.spanProcessor);
|
|
85
162
|
// Configure context manager (Zone.js for async context propagation)
|
|
86
163
|
const contextManager = new ZoneContextManager();
|
|
87
164
|
// Configure propagators (W3C Trace Context + B3 for compatibility)
|
|
@@ -95,19 +172,7 @@ export class TracingService {
|
|
|
95
172
|
this.tracer = trace.getTracer(this.serviceName, this.serviceVersion);
|
|
96
173
|
// Initialize auto-instrumentation if enabled
|
|
97
174
|
if (this.enableAutoInstrumentation) {
|
|
98
|
-
this.initializeAutoInstrumentation(
|
|
99
|
-
}
|
|
100
|
-
if (this.debug) {
|
|
101
|
-
console.log('[TracingService] Initialized successfully', {
|
|
102
|
-
collectorUrl: this.collectorUrl,
|
|
103
|
-
serviceName: this.serviceName,
|
|
104
|
-
serviceVersion: this.serviceVersion,
|
|
105
|
-
environment: this.environment,
|
|
106
|
-
customerId: this.customerId,
|
|
107
|
-
tenantId: this.tenantId,
|
|
108
|
-
autoInstrumentation: this.enableAutoInstrumentation,
|
|
109
|
-
propagateUrls: this.propagateTraceHeaderCorsUrls,
|
|
110
|
-
});
|
|
175
|
+
this.initializeAutoInstrumentation();
|
|
111
176
|
}
|
|
112
177
|
}
|
|
113
178
|
catch (error) {
|
|
@@ -115,37 +180,15 @@ export class TracingService {
|
|
|
115
180
|
// Don't throw - telemetry should fail silently in production
|
|
116
181
|
}
|
|
117
182
|
}
|
|
118
|
-
initializeAutoInstrumentation(
|
|
183
|
+
initializeAutoInstrumentation() {
|
|
119
184
|
try {
|
|
120
|
-
//
|
|
121
|
-
//
|
|
185
|
+
// NOTE: XHR and Fetch instrumentation are disabled because we manually intercept
|
|
186
|
+
// them to add authentication headers. Enabling them causes conflicts.
|
|
187
|
+
// NOTE: DocumentLoadInstrumentation is disabled because it captures events that
|
|
188
|
+
// occurred before the component initialized, and cannot use custom trace IDs.
|
|
189
|
+
// Only enable user interaction instrumentation
|
|
122
190
|
registerInstrumentations({
|
|
123
191
|
instrumentations: [
|
|
124
|
-
// Fetch API instrumentation
|
|
125
|
-
new FetchInstrumentation({
|
|
126
|
-
propagateTraceHeaderCorsUrls: this.propagateTraceHeaderCorsUrls,
|
|
127
|
-
clearTimingResources: true,
|
|
128
|
-
applyCustomAttributesOnSpan: (span, _request, response) => {
|
|
129
|
-
// Add resource attributes to each span
|
|
130
|
-
Object.entries(resourceAttributes).forEach(([key, value]) => {
|
|
131
|
-
span.setAttribute(key, value);
|
|
132
|
-
});
|
|
133
|
-
// Add custom attributes
|
|
134
|
-
if (response && 'status' in response) {
|
|
135
|
-
span.setAttribute('http.response.status_code', response.status);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
}),
|
|
139
|
-
// XMLHttpRequest instrumentation
|
|
140
|
-
new XMLHttpRequestInstrumentation({
|
|
141
|
-
propagateTraceHeaderCorsUrls: this.propagateTraceHeaderCorsUrls,
|
|
142
|
-
applyCustomAttributesOnSpan: (span) => {
|
|
143
|
-
// Add resource attributes to each span
|
|
144
|
-
Object.entries(resourceAttributes).forEach(([key, value]) => {
|
|
145
|
-
span.setAttribute(key, value);
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
}),
|
|
149
192
|
// User interaction instrumentation (clicks, etc.)
|
|
150
193
|
new UserInteractionInstrumentation({
|
|
151
194
|
eventNames: ['click', 'submit'],
|
|
@@ -154,13 +197,8 @@ export class TracingService {
|
|
|
154
197
|
return element.tagName === 'BUTTON' || element.tagName === 'A' || element.tagName === 'FORM';
|
|
155
198
|
},
|
|
156
199
|
}),
|
|
157
|
-
// Document load instrumentation
|
|
158
|
-
new DocumentLoadInstrumentation(),
|
|
159
200
|
],
|
|
160
201
|
});
|
|
161
|
-
if (this.debug) {
|
|
162
|
-
console.log('[TracingService] Auto-instrumentation enabled');
|
|
163
|
-
}
|
|
164
202
|
}
|
|
165
203
|
catch (error) {
|
|
166
204
|
console.error('[TracingService] Failed to initialize auto-instrumentation:', error);
|
|
@@ -251,19 +289,24 @@ export class TracingService {
|
|
|
251
289
|
}
|
|
252
290
|
startSpan(name, attributes) {
|
|
253
291
|
if (!this.tracer) {
|
|
254
|
-
|
|
292
|
+
console.warn('[TracingService] Tracer not initialized, returning no-op span');
|
|
255
293
|
return trace.getTracer('noop').startSpan('noop');
|
|
256
294
|
}
|
|
257
295
|
try {
|
|
258
296
|
let currentContext = context.active();
|
|
259
|
-
// If we have a session trace ID, create a span context
|
|
260
|
-
if (this.sessionTraceId) {
|
|
261
|
-
|
|
297
|
+
// If we have a session trace ID and there's no active span, create a root span context
|
|
298
|
+
if (this.sessionTraceId && !trace.getSpan(currentContext)) {
|
|
299
|
+
// Create a valid span context for the custom trace ID
|
|
300
|
+
const remoteSpanContext = {
|
|
262
301
|
traceId: this.sessionTraceId,
|
|
263
302
|
spanId: this.generateSpanId(),
|
|
264
|
-
traceFlags:
|
|
303
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
304
|
+
isRemote: true,
|
|
265
305
|
};
|
|
266
|
-
|
|
306
|
+
// Create a non-recording span with the custom trace context
|
|
307
|
+
const remoteSpan = trace.wrapSpanContext(remoteSpanContext);
|
|
308
|
+
// Set this span in the context so child spans inherit the trace ID
|
|
309
|
+
currentContext = trace.setSpan(currentContext, remoteSpan);
|
|
267
310
|
}
|
|
268
311
|
// Get device info
|
|
269
312
|
const deviceInfo = this.getDeviceInfo();
|
|
@@ -320,20 +363,15 @@ export class TracingService {
|
|
|
320
363
|
}
|
|
321
364
|
}
|
|
322
365
|
endSpan(span) {
|
|
323
|
-
if (!span)
|
|
366
|
+
if (!span) {
|
|
367
|
+
console.warn('[TracingService] endSpan called with null/undefined span');
|
|
324
368
|
return;
|
|
369
|
+
}
|
|
325
370
|
try {
|
|
326
371
|
span.end();
|
|
327
|
-
if (this.debug) {
|
|
328
|
-
const spanContext = span.spanContext();
|
|
329
|
-
console.log('[TracingService] Ended span', {
|
|
330
|
-
traceId: spanContext.traceId,
|
|
331
|
-
spanId: spanContext.spanId,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
372
|
}
|
|
335
373
|
catch (error) {
|
|
336
|
-
console.error('[TracingService] Failed to end span:', error);
|
|
374
|
+
console.error('[TracingService] ❌ Failed to end span:', error);
|
|
337
375
|
}
|
|
338
376
|
}
|
|
339
377
|
addSpanEvent(span, name, attributes) {
|
|
@@ -358,9 +396,6 @@ export class TracingService {
|
|
|
358
396
|
code: SpanStatusCode.ERROR,
|
|
359
397
|
message: error.message,
|
|
360
398
|
});
|
|
361
|
-
if (this.debug) {
|
|
362
|
-
console.log('[TracingService] Recorded exception:', error);
|
|
363
|
-
}
|
|
364
399
|
}
|
|
365
400
|
catch (err) {
|
|
366
401
|
console.error('[TracingService] Failed to record exception:', err);
|
|
@@ -397,6 +432,26 @@ export class TracingService {
|
|
|
397
432
|
this.endSpan(span);
|
|
398
433
|
}
|
|
399
434
|
}
|
|
435
|
+
async traceAsync(name, fn, attributes) {
|
|
436
|
+
return this.trace(name, fn, attributes);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Flush all pending spans to the collector
|
|
440
|
+
* Call this when capture/process is complete to send all traces
|
|
441
|
+
*/
|
|
442
|
+
async flush() {
|
|
443
|
+
try {
|
|
444
|
+
if (!this.spanProcessor) {
|
|
445
|
+
console.warn('[TracingService] No span processor available to flush');
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
await this.spanProcessor.forceFlush();
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
console.error('[TracingService] ❌ Failed to flush spans:', error);
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
400
455
|
async cleanup() {
|
|
401
456
|
try {
|
|
402
457
|
if (this.spanProcessor) {
|
|
@@ -406,9 +461,6 @@ export class TracingService {
|
|
|
406
461
|
if (this.provider) {
|
|
407
462
|
await this.provider.shutdown();
|
|
408
463
|
}
|
|
409
|
-
if (this.debug) {
|
|
410
|
-
console.log('[TracingService] Cleaned up successfully');
|
|
411
|
-
}
|
|
412
464
|
}
|
|
413
465
|
catch (error) {
|
|
414
466
|
console.error('[TracingService] Failed to cleanup:', error);
|