@angular-helpers/browser-web-apis 21.1.0 → 21.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.es.md +418 -2
- package/README.md +389 -2
- package/fesm2022/angular-helpers-browser-web-apis.mjs +1104 -3
- package/package.json +1 -1
- package/types/angular-helpers-browser-web-apis.d.ts +400 -6
package/README.es.md
CHANGED
|
@@ -23,14 +23,40 @@ Paquete de servicios Angular para acceder de forma estructurada y segura a Brows
|
|
|
23
23
|
- `MediaDevicesService` - Enumeracion y gestion de dispositivos multimedia
|
|
24
24
|
- `GeolocationService` - Acceso a la API de geolocalizacion
|
|
25
25
|
- `NotificationService` - API de notificaciones del navegador
|
|
26
|
+
- `MediaRecorderService` - Grabar audio/video desde MediaStream
|
|
26
27
|
|
|
27
|
-
###
|
|
28
|
+
### APIs de observadores
|
|
29
|
+
|
|
30
|
+
- `IntersectionObserverService` - Detectar cuando elementos entran/salen del viewport
|
|
31
|
+
- `ResizeObserverService` - Observar cambios de tamano de elementos
|
|
32
|
+
|
|
33
|
+
### APIs de sistema
|
|
34
|
+
|
|
35
|
+
- `BatteryService` - Monitorear estado de bateria y carga
|
|
36
|
+
- `PageVisibilityService` - Rastrear cambios de visibilidad del documento
|
|
37
|
+
- `ScreenWakeLockService` - Evitar que la pantalla se atenue o bloquee
|
|
38
|
+
- `ScreenOrientationService` - Leer y bloquear orientacion de pantalla
|
|
39
|
+
- `FullscreenService` - Alternar modo pantalla completa para elementos
|
|
40
|
+
- `VibrationService` - Activar patrones de retroalimentacion tactil
|
|
41
|
+
- `SpeechSynthesisService` - Texto a voz con seleccion de voz
|
|
42
|
+
|
|
43
|
+
### APIs de red
|
|
28
44
|
|
|
29
|
-
- `WebWorkerService` - Gestion de Web Workers
|
|
30
45
|
- `WebSocketService` - Gestion de conexiones WebSocket
|
|
46
|
+
- `ServerSentEventsService` - Cliente de Server-Sent Events
|
|
47
|
+
- `BroadcastChannelService` - Comunicacion entre pestanas
|
|
48
|
+
- `NetworkInformationService` - Informacion de conexion y estado online
|
|
49
|
+
|
|
50
|
+
### APIs de almacenamiento y E/S
|
|
51
|
+
|
|
31
52
|
- `WebStorageService` - Helpers para LocalStorage y SessionStorage
|
|
32
53
|
- `WebShareService` - Soporte para Web Share API nativa
|
|
33
54
|
- `ClipboardService` - Acceso al portapapeles del sistema
|
|
55
|
+
- `FileSystemAccessService` - Abrir/guardar archivos via selector nativo
|
|
56
|
+
|
|
57
|
+
### Web APIs
|
|
58
|
+
|
|
59
|
+
- `WebWorkerService` - Gestion de Web Workers
|
|
34
60
|
|
|
35
61
|
### Seguridad y capacidades
|
|
36
62
|
|
|
@@ -134,6 +160,396 @@ export class LocationComponent {
|
|
|
134
160
|
}
|
|
135
161
|
```
|
|
136
162
|
|
|
163
|
+
### IntersectionObserverService
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { IntersectionObserverService } from '@angular-helpers/browser-web-apis';
|
|
167
|
+
|
|
168
|
+
export class LazyImageComponent {
|
|
169
|
+
private intersectionService = inject(IntersectionObserverService);
|
|
170
|
+
private elementRef = inject(ElementRef);
|
|
171
|
+
|
|
172
|
+
isVisible = signal(false);
|
|
173
|
+
|
|
174
|
+
ngAfterViewInit() {
|
|
175
|
+
this.intersectionService
|
|
176
|
+
.observeVisibility(this.elementRef.nativeElement, { threshold: 0.5 })
|
|
177
|
+
.subscribe((visible) => this.isVisible.set(visible));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### ResizeObserverService
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { ResizeObserverService } from '@angular-helpers/browser-web-apis';
|
|
186
|
+
|
|
187
|
+
export class ResponsiveComponent {
|
|
188
|
+
private resizeService = inject(ResizeObserverService);
|
|
189
|
+
private elementRef = inject(ElementRef);
|
|
190
|
+
|
|
191
|
+
elementSize = signal<ElementSize | null>(null);
|
|
192
|
+
|
|
193
|
+
ngAfterViewInit() {
|
|
194
|
+
this.resizeService
|
|
195
|
+
.observeSize(this.elementRef.nativeElement)
|
|
196
|
+
.subscribe((size) => this.elementSize.set(size));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### PageVisibilityService
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { PageVisibilityService } from '@angular-helpers/browser-web-apis';
|
|
205
|
+
|
|
206
|
+
export class AnalyticsComponent {
|
|
207
|
+
private visibilityService = inject(PageVisibilityService);
|
|
208
|
+
|
|
209
|
+
ngOnInit() {
|
|
210
|
+
this.visibilityService.watch().subscribe((state) => {
|
|
211
|
+
console.log('La pagina ahora esta:', state);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### FullscreenService
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { FullscreenService } from '@angular-helpers/browser-web-apis';
|
|
221
|
+
|
|
222
|
+
export class VideoPlayerComponent {
|
|
223
|
+
private fullscreenService = inject(FullscreenService);
|
|
224
|
+
|
|
225
|
+
async toggleFullscreen() {
|
|
226
|
+
await this.fullscreenService.toggle();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### ScreenWakeLockService
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { ScreenWakeLockService } from '@angular-helpers/browser-web-apis';
|
|
235
|
+
|
|
236
|
+
export class PresentationComponent {
|
|
237
|
+
private wakeLockService = inject(ScreenWakeLockService);
|
|
238
|
+
|
|
239
|
+
async keepScreenOn() {
|
|
240
|
+
await this.wakeLockService.request();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async releaseScreen() {
|
|
244
|
+
await this.wakeLockService.release();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### BroadcastChannelService
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import { BroadcastChannelService } from '@angular-helpers/browser-web-apis';
|
|
253
|
+
|
|
254
|
+
export class SyncComponent {
|
|
255
|
+
private broadcastService = inject(BroadcastChannelService);
|
|
256
|
+
|
|
257
|
+
ngOnInit() {
|
|
258
|
+
// Escuchar mensajes de otras pestanas
|
|
259
|
+
this.broadcastService.open<string>('app-sync').subscribe((msg) => {
|
|
260
|
+
console.log('Recibido:', msg);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
sendMessage(data: string) {
|
|
265
|
+
this.broadcastService.post('app-sync', data);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### ServerSentEventsService
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { ServerSentEventsService } from '@angular-helpers/browser-web-apis';
|
|
274
|
+
|
|
275
|
+
export class LiveFeedComponent {
|
|
276
|
+
private sseService = inject(ServerSentEventsService);
|
|
277
|
+
|
|
278
|
+
connectToEvents() {
|
|
279
|
+
this.sseService.connect('https://api.example.com/events').subscribe({
|
|
280
|
+
next: (message) => console.log('Evento:', message),
|
|
281
|
+
error: (err) => console.error('Error SSE:', err),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### VibrationService
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { VibrationService } from '@angular-helpers/browser-web-apis';
|
|
291
|
+
|
|
292
|
+
export class FeedbackComponent {
|
|
293
|
+
private vibrationService = inject(VibrationService);
|
|
294
|
+
|
|
295
|
+
onSuccess() {
|
|
296
|
+
this.vibrationService.success();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
onError() {
|
|
300
|
+
this.vibrationService.error();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### SpeechSynthesisService
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { SpeechSynthesisService } from '@angular-helpers/browser-web-apis';
|
|
309
|
+
|
|
310
|
+
export class VoiceComponent {
|
|
311
|
+
private speechService = inject(SpeechSynthesisService);
|
|
312
|
+
|
|
313
|
+
speakText(text: string) {
|
|
314
|
+
this.speechService.speak(text).subscribe((state) => {
|
|
315
|
+
console.log('Estado de voz:', state);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### ScreenOrientationService
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { ScreenOrientationService } from '@angular-helpers/browser-web-apis';
|
|
325
|
+
|
|
326
|
+
export class MobileComponent {
|
|
327
|
+
private orientationService = inject(ScreenOrientationService);
|
|
328
|
+
|
|
329
|
+
ngOnInit() {
|
|
330
|
+
// Observar cambios de orientacion
|
|
331
|
+
this.orientationService.watch().subscribe((orientation) => {
|
|
332
|
+
console.log('Orientacion:', orientation.type, 'Angulo:', orientation.angle);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async lockPortrait() {
|
|
337
|
+
try {
|
|
338
|
+
await this.orientationService.lock('portrait');
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error('No se pudo bloquear la orientacion:', error);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
unlockOrientation() {
|
|
345
|
+
this.orientationService.unlock();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### BatteryService
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import { BatteryService } from '@angular-helpers/browser-web-apis';
|
|
354
|
+
|
|
355
|
+
export class PowerComponent {
|
|
356
|
+
private batteryService = inject(BatteryService);
|
|
357
|
+
|
|
358
|
+
async ngOnInit() {
|
|
359
|
+
try {
|
|
360
|
+
// Inicializar y obtener informacion inicial de la bateria
|
|
361
|
+
const batteryInfo = await this.batteryService.initialize();
|
|
362
|
+
console.log('Nivel de bateria:', batteryInfo.level);
|
|
363
|
+
console.log('Esta cargando:', batteryInfo.charging);
|
|
364
|
+
|
|
365
|
+
// Observar cambios de bateria
|
|
366
|
+
this.batteryService.watchBatteryInfo().subscribe((info) => {
|
|
367
|
+
console.log('Bateria actualizada:', info);
|
|
368
|
+
});
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.error('Battery API no soportada:', error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### ClipboardService
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { ClipboardService } from '@angular-helpers/browser-web-apis';
|
|
380
|
+
|
|
381
|
+
export class CopyComponent {
|
|
382
|
+
private clipboardService = inject(ClipboardService);
|
|
383
|
+
|
|
384
|
+
async copyToClipboard(text: string) {
|
|
385
|
+
try {
|
|
386
|
+
await this.clipboardService.writeText(text);
|
|
387
|
+
console.log('Copiado exitosamente');
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.error('Error al copiar:', error);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
async pasteFromClipboard(): Promise<string> {
|
|
394
|
+
try {
|
|
395
|
+
const text = await this.clipboardService.readText();
|
|
396
|
+
return text;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
console.error('Error al leer el portapapeles:', error);
|
|
399
|
+
return '';
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### FileSystemAccessService
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { FileSystemAccessService } from '@angular-helpers/browser-web-apis';
|
|
409
|
+
|
|
410
|
+
export class FileManagerComponent {
|
|
411
|
+
private fileService = inject(FileSystemAccessService);
|
|
412
|
+
|
|
413
|
+
async openFiles() {
|
|
414
|
+
try {
|
|
415
|
+
const files = await this.fileService.openFile({
|
|
416
|
+
multiple: true,
|
|
417
|
+
types: [
|
|
418
|
+
{
|
|
419
|
+
description: 'Archivos de texto',
|
|
420
|
+
accept: { 'text/plain': ['.txt'] },
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
});
|
|
424
|
+
console.log('Archivos seleccionados:', files);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
console.error('Error al abrir archivos:', error);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async saveContent(content: string) {
|
|
431
|
+
try {
|
|
432
|
+
await this.fileService.saveFile(content, {
|
|
433
|
+
suggestedName: 'documento.txt',
|
|
434
|
+
});
|
|
435
|
+
} catch (error) {
|
|
436
|
+
console.error('Error al guardar archivo:', error);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### MediaRecorderService
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
import { MediaRecorderService } from '@angular-helpers/browser-web-apis';
|
|
446
|
+
|
|
447
|
+
export class RecorderComponent {
|
|
448
|
+
private recorderService = inject(MediaRecorderService);
|
|
449
|
+
private stream: MediaStream | null = null;
|
|
450
|
+
|
|
451
|
+
async startRecording() {
|
|
452
|
+
try {
|
|
453
|
+
this.stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
|
|
454
|
+
await this.recorderService.start(this.stream, { mimeType: 'video/webm' });
|
|
455
|
+
} catch (error) {
|
|
456
|
+
console.error('Error al iniciar la grabacion:', error);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
stopRecording() {
|
|
461
|
+
const result = this.recorderService.stop();
|
|
462
|
+
if (result) {
|
|
463
|
+
console.log('Grabacion guardada, URL del blob:', result.url);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### WebSocketService
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
import { WebSocketService } from '@angular-helpers/browser-web-apis';
|
|
473
|
+
|
|
474
|
+
export class LiveComponent {
|
|
475
|
+
private wsService = inject(WebSocketService);
|
|
476
|
+
|
|
477
|
+
connect() {
|
|
478
|
+
this.wsService
|
|
479
|
+
.connect({
|
|
480
|
+
url: 'wss://example.com/socket',
|
|
481
|
+
reconnectInterval: 3000,
|
|
482
|
+
maxReconnectAttempts: 5,
|
|
483
|
+
})
|
|
484
|
+
.subscribe((status) => {
|
|
485
|
+
console.log('Estado de conexion:', status);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
this.wsService.getMessages().subscribe((message) => {
|
|
489
|
+
console.log('Recibido:', message);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
sendMessage(data: unknown) {
|
|
494
|
+
this.wsService.send({ type: 'message', data });
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### WebStorageService
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import { WebStorageService } from '@angular-helpers/browser-web-apis';
|
|
503
|
+
|
|
504
|
+
export class SettingsComponent {
|
|
505
|
+
private storageService = inject(WebStorageService);
|
|
506
|
+
|
|
507
|
+
saveSetting(key: string, value: unknown) {
|
|
508
|
+
this.storageService.setLocalStorage(key, value);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
getSetting<T>(key: string): T | null {
|
|
512
|
+
return this.storageService.getLocalStorage<T>(key);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
watchSetting<T>(key: string) {
|
|
516
|
+
return this.storageService.watchLocalStorage<T>(key).subscribe((value) => {
|
|
517
|
+
console.log('Configuracion cambiada:', value);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### WebWorkerService
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
import { WebWorkerService } from '@angular-helpers/browser-web-apis';
|
|
527
|
+
|
|
528
|
+
export class WorkerComponent {
|
|
529
|
+
private workerService = inject(WebWorkerService);
|
|
530
|
+
|
|
531
|
+
async createWorker() {
|
|
532
|
+
this.workerService
|
|
533
|
+
.createWorker('calc-worker', '/assets/workers/calc.worker.js')
|
|
534
|
+
.subscribe((status) => {
|
|
535
|
+
console.log('Estado del worker:', status);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
this.workerService.getMessages('calc-worker').subscribe((message) => {
|
|
539
|
+
console.log('Respuesta del worker:', message);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
sendTask(data: unknown) {
|
|
544
|
+
this.workerService.postMessage('calc-worker', {
|
|
545
|
+
id: 'task-1',
|
|
546
|
+
type: 'CALCULATE',
|
|
547
|
+
data,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
137
553
|
## Soporte de navegadores
|
|
138
554
|
|
|
139
555
|
Los servicios validan automaticamente el soporte del navegador y el manejo de rutas no soportadas:
|