react-native-tpstreams 0.2.15 → 0.2.16

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 CHANGED
@@ -117,15 +117,39 @@ import { TPStreamsPlayerView } from "react-native-tpstreams";
117
117
 
118
118
  - `getAllDownloads()`: Gets all downloaded videos. Returns `Promise<DownloadItem[]>`.
119
119
 
120
+ ### Real-time Download Progress
121
+
122
+ The library provides real-time download progress updates for optimal performance:
123
+
124
+ #### Progress Listener Methods
125
+
126
+ - `addDownloadProgressListener()`: Starts listening for download progress updates. Returns `Promise<void>`.
127
+
128
+ - `removeDownloadProgressListener()`: Stops listening for download progress updates. Returns `Promise<void>`.
129
+
130
+ - `onDownloadProgressChanged(listener: DownloadProgressListener)`: Adds a listener for progress changes. Returns `EmitterSubscription`.
131
+
132
+ #### Progress Listener Types
133
+
134
+ ```typescript
135
+ // Progress update event (uses existing DownloadItem interface)
136
+ type DownloadProgressChange = DownloadItem;
137
+
138
+ // Listener function type
139
+ type DownloadProgressListener = (downloads: DownloadProgressChange[]) => void;
140
+ ```
141
+
120
142
  ### Download Item
121
143
 
122
144
  The download item object (`DownloadItem`) contains information about a downloaded or downloading video, including:
123
145
 
124
- - `assetId`: The ID of the video.
125
- - `state`: The current state of the download as String (Queued, Downloading, Completed, Failed, Removing, Restarting, Paused ).
126
- - `progressPercentage`: Download progress from 0 to 100.
127
- - `title`: The title of the video Asset.
146
+ - `videoId`: The ID of the video.
147
+ - `title`: The title of the video.
128
148
  - `thumbnailUrl`: URL to the video thumbnail (if available).
149
+ - `totalBytes`: Total size of the video in bytes.
150
+ - `downloadedBytes`: Number of bytes downloaded so far.
151
+ - `progressPercentage`: Download progress from 0 to 100.
152
+ - `state`: The current state of the download as String (Queued, Downloading, Completed, Failed, Removing, Restarting, Paused).
129
153
  - `metadata`: Custom metadata attached to the download as a JSON string (if provided during download).
130
154
 
131
155
  ---
@@ -299,6 +323,285 @@ const removeVideoDownload = async (videoId: string) => {
299
323
  };
300
324
  ```
301
325
 
326
+ ## Real-time Download Progress Example
327
+
328
+ Here's a complete example showing how to implement real-time download progress in a React Native component:
329
+
330
+ ```jsx
331
+ import React, { useState, useEffect } from 'react';
332
+ import {
333
+ View,
334
+ Text,
335
+ StyleSheet,
336
+ TouchableOpacity,
337
+ ScrollView,
338
+ Alert,
339
+ } from 'react-native';
340
+ import {
341
+ addDownloadProgressListener,
342
+ removeDownloadProgressListener,
343
+ onDownloadProgressChanged,
344
+ pauseDownload,
345
+ resumeDownload,
346
+ removeDownload,
347
+ type DownloadItem,
348
+ type DownloadProgressChange,
349
+ } from 'react-native-tpstreams';
350
+
351
+ const DownloadProgressExample = () => {
352
+ const [downloads, setDownloads] = useState<DownloadItem[]>([]);
353
+ const [isInitializing, setIsInitializing] = useState(true);
354
+
355
+ useEffect(() => {
356
+ // Setup progress listener when component mounts
357
+ const setupProgressListener = async () => {
358
+ try {
359
+ // Start listening for progress updates
360
+ await addDownloadProgressListener();
361
+
362
+ // Add listener for progress updates
363
+ const subscription = onDownloadProgressChanged((downloads: DownloadProgressChange[]) => {
364
+ console.log('Progress changes received:', downloads.length, 'downloads');
365
+
366
+ // Simply replace the state with the complete list from native
367
+ setDownloads(downloads);
368
+ });
369
+
370
+ // Cleanup function
371
+ return () => {
372
+ subscription.remove(); // Remove the listener
373
+ removeDownloadProgressListener(); // Stop listening
374
+ };
375
+ } catch (error) {
376
+ console.error('Failed to setup progress listener:', error);
377
+ setIsInitializing(false);
378
+ }
379
+ };
380
+
381
+ setupProgressListener();
382
+ }, []);
383
+
384
+ const handlePauseDownload = async (videoId: string) => {
385
+ try {
386
+ await pauseDownload(videoId);
387
+ console.log('Download paused successfully');
388
+ } catch (error) {
389
+ console.error('Error pausing download:', error);
390
+ Alert.alert('Error', 'Failed to pause download');
391
+ }
392
+ };
393
+
394
+ const handleResumeDownload = async (videoId: string) => {
395
+ try {
396
+ await resumeDownload(videoId);
397
+ console.log('Download resumed successfully');
398
+ } catch (error) {
399
+ console.error('Error resuming download:', error);
400
+ Alert.alert('Error', 'Failed to resume download');
401
+ }
402
+ };
403
+
404
+ const handleRemoveDownload = async (videoId: string) => {
405
+ try {
406
+ await removeDownload(videoId);
407
+ console.log('Download removed successfully');
408
+ } catch (error) {
409
+ console.error('Error removing download:', error);
410
+ Alert.alert('Error', 'Failed to remove download');
411
+ }
412
+ };
413
+
414
+ const renderDownloadItem = (item: DownloadItem) => {
415
+ const isCompleted = item.state === 'Completed';
416
+ const isDownloading = item.state === 'Downloading';
417
+ const isPaused = item.state === 'Paused';
418
+
419
+ return (
420
+ <View key={item.videoId} style={styles.downloadItem}>
421
+ <Text style={styles.title}>{item.title}</Text>
422
+ <Text style={styles.status}>Status: {item.state}</Text>
423
+
424
+ {!isCompleted && (
425
+ <View style={styles.progressContainer}>
426
+ <View style={styles.progressBar}>
427
+ <View
428
+ style={[
429
+ styles.progressFill,
430
+ { width: `${item.progressPercentage}%` }
431
+ ]}
432
+ />
433
+ </View>
434
+ <Text style={styles.progressText}>
435
+ {item.progressPercentage.toFixed(1)}%
436
+ </Text>
437
+ </View>
438
+ )}
439
+
440
+ {item.totalBytes > 0 && (
441
+ <Text style={styles.bytesText}>
442
+ {(item.downloadedBytes / (1024 * 1024)).toFixed(1)} MB /
443
+ {(item.totalBytes / (1024 * 1024)).toFixed(1)} MB
444
+ </Text>
445
+ )}
446
+
447
+ <View style={styles.buttonContainer}>
448
+ {!isCompleted && (
449
+ <>
450
+ {isDownloading && (
451
+ <TouchableOpacity
452
+ style={styles.button}
453
+ onPress={() => handlePauseDownload(item.videoId)}
454
+ >
455
+ <Text style={styles.buttonText}>Pause</Text>
456
+ </TouchableOpacity>
457
+ )}
458
+
459
+ {isPaused && (
460
+ <TouchableOpacity
461
+ style={styles.button}
462
+ onPress={() => handleResumeDownload(item.videoId)}
463
+ >
464
+ <Text style={styles.buttonText}>Resume</Text>
465
+ </TouchableOpacity>
466
+ )}
467
+ </>
468
+ )}
469
+
470
+ <TouchableOpacity
471
+ style={[styles.button, styles.removeButton]}
472
+ onPress={() => handleRemoveDownload(item.videoId)}
473
+ >
474
+ <Text style={styles.buttonText}>Remove</Text>
475
+ </TouchableOpacity>
476
+ </View>
477
+ </View>
478
+ );
479
+ };
480
+
481
+ if (isInitializing) {
482
+ return (
483
+ <View style={styles.container}>
484
+ <Text>Loading downloads...</Text>
485
+ </View>
486
+ );
487
+ }
488
+
489
+ return (
490
+ <ScrollView style={styles.container}>
491
+ <Text style={styles.header}>Downloads ({downloads.length})</Text>
492
+
493
+ {downloads.length > 0 ? (
494
+ downloads.map(renderDownloadItem)
495
+ ) : (
496
+ <Text style={styles.emptyText}>No downloads available</Text>
497
+ )}
498
+ </ScrollView>
499
+ );
500
+ };
501
+
502
+ const styles = StyleSheet.create({
503
+ container: {
504
+ flex: 1,
505
+ padding: 16,
506
+ backgroundColor: '#f5f5f5',
507
+ },
508
+ header: {
509
+ fontSize: 20,
510
+ fontWeight: 'bold',
511
+ marginBottom: 16,
512
+ },
513
+ downloadItem: {
514
+ backgroundColor: '#fff',
515
+ padding: 16,
516
+ marginBottom: 12,
517
+ borderRadius: 8,
518
+ shadowColor: '#000',
519
+ shadowOffset: { width: 0, height: 2 },
520
+ shadowOpacity: 0.1,
521
+ shadowRadius: 4,
522
+ elevation: 3,
523
+ },
524
+ title: {
525
+ fontSize: 16,
526
+ fontWeight: 'bold',
527
+ marginBottom: 8,
528
+ },
529
+ status: {
530
+ fontSize: 14,
531
+ color: '#666',
532
+ marginBottom: 8,
533
+ },
534
+ progressContainer: {
535
+ flexDirection: 'row',
536
+ alignItems: 'center',
537
+ marginBottom: 8,
538
+ },
539
+ progressBar: {
540
+ flex: 1,
541
+ height: 8,
542
+ backgroundColor: '#eee',
543
+ borderRadius: 4,
544
+ marginRight: 12,
545
+ },
546
+ progressFill: {
547
+ height: '100%',
548
+ backgroundColor: '#007AFF',
549
+ borderRadius: 4,
550
+ },
551
+ progressText: {
552
+ fontSize: 12,
553
+ color: '#666',
554
+ width: 40,
555
+ },
556
+ bytesText: {
557
+ fontSize: 12,
558
+ color: '#666',
559
+ marginBottom: 12,
560
+ },
561
+ buttonContainer: {
562
+ flexDirection: 'row',
563
+ gap: 8,
564
+ },
565
+ button: {
566
+ paddingVertical: 8,
567
+ paddingHorizontal: 16,
568
+ backgroundColor: '#007AFF',
569
+ borderRadius: 6,
570
+ },
571
+ removeButton: {
572
+ backgroundColor: '#FF3B30',
573
+ },
574
+ buttonText: {
575
+ color: '#fff',
576
+ fontSize: 14,
577
+ fontWeight: '600',
578
+ },
579
+ emptyText: {
580
+ textAlign: 'center',
581
+ color: '#666',
582
+ fontSize: 16,
583
+ },
584
+ });
585
+
586
+ export default DownloadProgressExample;
587
+ ```
588
+
589
+ ### Key Features of the Real-time Progress System:
590
+
591
+ 1. **Real-time Updates**: Progress bars and status update in real-time
592
+ 2. **Automatic UI Updates**: UI automatically reflects current download states
593
+ 3. **Efficient State Management**: Uses functional state updates to avoid race conditions
594
+ 4. **Proper Cleanup**: Removes listeners when component unmounts
595
+ 5. **Error Handling**: Graceful error handling with user feedback
596
+ 6. **Type Safety**: Full TypeScript support with proper types
597
+
598
+ ### Best Practices:
599
+
600
+ 1. **Start listening when needed**: Only start the progress listener when your screen is active
601
+ 2. **Stop listening when not needed**: Always stop listening to save resources
602
+ 3. **Use functional state updates**: Prevents race conditions with concurrent updates
603
+ 4. **Debounce if needed**: Consider debouncing updates for better UI performance
604
+
302
605
  ---
303
606
 
304
607
  ## Contributing
@@ -3,4 +3,4 @@ Tpstreams_minSdkVersion=24
3
3
  Tpstreams_targetSdkVersion=34
4
4
  Tpstreams_compileSdkVersion=35
5
5
  Tpstreams_ndkVersion=27.1.12297006
6
- Tpstreams_tpstreamsAndroidPlayerVersion=1.0.11
6
+ Tpstreams_tpstreamsAndroidPlayerVersion=1.0.13
@@ -6,19 +6,89 @@ import com.facebook.react.bridge.Arguments
6
6
  import com.facebook.react.bridge.ReactMethod
7
7
  import com.facebook.react.bridge.ReactApplicationContext
8
8
  import com.facebook.react.bridge.ReactContextBaseJavaModule
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule
9
10
  import com.tpstreams.player.download.DownloadClient
10
11
  import com.tpstreams.player.download.DownloadItem
11
12
 
12
- class TPStreamsDownloadModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
13
+ class TPStreamsDownloadModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), DownloadClient.Listener {
13
14
 
14
15
  private val downloadClient: DownloadClient by lazy {
15
16
  DownloadClient.getInstance(reactContext)
16
17
  }
17
18
 
19
+ private var isListening = false
20
+
18
21
  override fun getName(): String {
19
22
  return "TPStreamsDownload"
20
23
  }
21
24
 
25
+ @ReactMethod
26
+ fun addDownloadProgressListener(promise: Promise) {
27
+ try {
28
+ if (!isListening) {
29
+ downloadClient.addListener(this)
30
+ isListening = true
31
+ Log.d(TAG, "Started listening for download progress")
32
+ }
33
+ promise.resolve(null)
34
+ } catch (e: Exception) {
35
+ Log.e(TAG, "Error starting progress listener: ${e.message}", e)
36
+ promise.reject("PROGRESS_LISTENER_START_ERROR", e.message, e)
37
+ }
38
+ }
39
+
40
+ @ReactMethod
41
+ fun removeDownloadProgressListener(promise: Promise) {
42
+ try {
43
+ if (isListening) {
44
+ downloadClient.removeListener(this)
45
+ isListening = false
46
+ Log.d(TAG, "Stopped listening for download progress")
47
+ }
48
+ promise.resolve(null)
49
+ } catch (e: Exception) {
50
+ Log.e(TAG, "Error stopping progress listener: ${e.message}", e)
51
+ promise.reject("PROGRESS_LISTENER_STOP_ERROR", e.message, e)
52
+ }
53
+ }
54
+
55
+ override fun onDownloadsChanged() {
56
+ try {
57
+ val currentDownloads = downloadClient.getAllDownloadItems()
58
+
59
+ val result = Arguments.createArray()
60
+ for (item in currentDownloads) {
61
+ val map = Arguments.createMap()
62
+ map.putString("videoId", item.assetId)
63
+ map.putString("title", item.title)
64
+ item.thumbnailUrl?.let { map.putString("thumbnailUrl", it) }
65
+ map.putDouble("totalBytes", item.totalBytes.toDouble())
66
+ map.putDouble("downloadedBytes", item.downloadedBytes.toDouble())
67
+ map.putDouble("progressPercentage", item.progressPercentage.toDouble())
68
+ map.putString("state", downloadClient.getDownloadStatus(item.assetId))
69
+
70
+ val metadataJson = org.json.JSONObject()
71
+ item.metadata.forEach { (key, value) ->
72
+ metadataJson.put(key, value)
73
+ }
74
+ map.putString("metadata", metadataJson.toString())
75
+
76
+ result.pushMap(map)
77
+ }
78
+
79
+ emitEvent("onDownloadProgressChanged", result)
80
+
81
+ } catch (e: Exception) {
82
+ Log.e(TAG, "Error in onDownloadsChanged: ${e.message}", e)
83
+ }
84
+ }
85
+
86
+ private fun emitEvent(eventName: String, data: Any) {
87
+ reactContext
88
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
89
+ .emit(eventName, data)
90
+ }
91
+
22
92
  @ReactMethod
23
93
  fun pauseDownload(videoId: String, promise: Promise) {
24
94
  try {
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
2
 
3
- import { NativeModules } from 'react-native';
3
+ import { NativeModules, NativeEventEmitter } from 'react-native';
4
4
  const {
5
5
  TPStreamsDownload
6
6
  } = NativeModules;
7
+ const downloadEventEmitter = new NativeEventEmitter(TPStreamsDownload);
8
+ export function addDownloadProgressListener() {
9
+ return TPStreamsDownload.addDownloadProgressListener();
10
+ }
11
+ export function removeDownloadProgressListener() {
12
+ return TPStreamsDownload.removeDownloadProgressListener();
13
+ }
14
+ export function onDownloadProgressChanged(listener) {
15
+ return downloadEventEmitter.addListener('onDownloadProgressChanged', listener);
16
+ }
7
17
  export function pauseDownload(videoId) {
8
18
  return TPStreamsDownload.pauseDownload(videoId);
9
19
  }
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","TPStreamsDownload","pauseDownload","videoId","resumeDownload","removeDownload","isDownloaded","isDownloading","isPaused","getDownloadStatus","getAllDownloads"],"sourceRoot":"../../src","sources":["TPStreamsDownload.tsx"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,MAAM;EAAEC;AAAkB,CAAC,GAAGD,aAAa;AAa3C,OAAO,SAASE,aAAaA,CAACC,OAAe,EAAiB;EAC5D,OAAOF,iBAAiB,CAACC,aAAa,CAACC,OAAO,CAAC;AACjD;AAEA,OAAO,SAASC,cAAcA,CAACD,OAAe,EAAiB;EAC7D,OAAOF,iBAAiB,CAACG,cAAc,CAACD,OAAO,CAAC;AAClD;AAEA,OAAO,SAASE,cAAcA,CAACF,OAAe,EAAiB;EAC7D,OAAOF,iBAAiB,CAACI,cAAc,CAACF,OAAO,CAAC;AAClD;AAEA,OAAO,SAASG,YAAYA,CAACH,OAAe,EAAoB;EAC9D,OAAOF,iBAAiB,CAACK,YAAY,CAACH,OAAO,CAAC;AAChD;AAEA,OAAO,SAASI,aAAaA,CAACJ,OAAe,EAAoB;EAC/D,OAAOF,iBAAiB,CAACM,aAAa,CAACJ,OAAO,CAAC;AACjD;AAEA,OAAO,SAASK,QAAQA,CAACL,OAAe,EAAoB;EAC1D,OAAOF,iBAAiB,CAACO,QAAQ,CAACL,OAAO,CAAC;AAC5C;AAEA,OAAO,SAASM,iBAAiBA,CAACN,OAAe,EAAmB;EAClE,OAAOF,iBAAiB,CAACQ,iBAAiB,CAACN,OAAO,CAAC;AACrD;AAEA,OAAO,SAASO,eAAeA,CAAA,EAA4B;EACzD,OAAOT,iBAAiB,CAACS,eAAe,CAAC,CAAC;AAC5C","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","TPStreamsDownload","downloadEventEmitter","addDownloadProgressListener","removeDownloadProgressListener","onDownloadProgressChanged","listener","addListener","pauseDownload","videoId","resumeDownload","removeDownload","isDownloaded","isDownloading","isPaused","getDownloadStatus","getAllDownloads"],"sourceRoot":"../../src","sources":["TPStreamsDownload.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAGhE,MAAM;EAAEC;AAAkB,CAAC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@@ -7,7 +7,7 @@ export * from './TPStreamsPlayerViewNativeComponent';
7
7
 
8
8
  // Export the wrapper component as TPStreamsPlayerView
9
9
  export { default as TPStreamsPlayerView } from "./TPStreamsPlayer.js";
10
- export { pauseDownload, resumeDownload, removeDownload, isDownloaded, isDownloading, isPaused, getDownloadStatus, getAllDownloads } from "./TPStreamsDownload.js";
10
+ export { pauseDownload, resumeDownload, removeDownload, isDownloaded, isDownloading, isPaused, getDownloadStatus, getAllDownloads, addDownloadProgressListener, removeDownloadProgressListener, onDownloadProgressChanged } from "./TPStreamsDownload.js";
11
11
  const TPStreamsModule = NativeModules.TPStreams;
12
12
  export const TPStreams = {
13
13
  initialize: organizationId => {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","default","TPStreamsPlayerNative","TPStreamsPlayerView","pauseDownload","resumeDownload","removeDownload","isDownloaded","isDownloading","isPaused","getDownloadStatus","getAllDownloads","TPStreamsModule","TPStreams","initialize","organizationId"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C;AACA,SAASC,OAAO,IAAIC,qBAAqB,QAAQ,sCAAsC;AACvF,cAAc,sCAAsC;;AAEpD;AACA,SAASD,OAAO,IAAIE,mBAAmB,QAAQ,sBAAmB;AAGlE,SACEC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACRC,iBAAiB,EACjBC,eAAe,QAEV,wBAAqB;AAE5B,MAAMC,eAAe,GAAGZ,aAAa,CAACa,SAAS;AAE/C,OAAO,MAAMA,SAAS,GAAG;EACvBC,UAAU,EAAGC,cAAsB,IAAW;IAC5CH,eAAe,CAACE,UAAU,CAACC,cAAc,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","default","TPStreamsPlayerNative","TPStreamsPlayerView","pauseDownload","resumeDownload","removeDownload","isDownloaded","isDownloading","isPaused","getDownloadStatus","getAllDownloads","addDownloadProgressListener","removeDownloadProgressListener","onDownloadProgressChanged","TPStreamsModule","TPStreams","initialize","organizationId"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C;AACA,SAASC,OAAO,IAAIC,qBAAqB,QAAQ,sCAAsC;AACvF,cAAc,sCAAsC;;AAEpD;AACA,SAASD,OAAO,IAAIE,mBAAmB,QAAQ,sBAAmB;AAGlE,SACEC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACRC,iBAAiB,EACjBC,eAAe,EACfC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,yBAAyB,QAIpB,wBAAqB;AAE5B,MAAMC,eAAe,GAAGf,aAAa,CAACgB,SAAS;AAE/C,OAAO,MAAMA,SAAS,GAAG;EACvBC,UAAU,EAAGC,cAAsB,IAAW;IAC5CH,eAAe,CAACE,UAAU,CAACC,cAAc,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import type { EmitterSubscription } from 'react-native';
1
2
  export interface DownloadItem {
2
3
  videoId: string;
3
4
  title: string;
@@ -8,6 +9,11 @@ export interface DownloadItem {
8
9
  state: string;
9
10
  metadata: string;
10
11
  }
12
+ export type DownloadProgressChange = DownloadItem;
13
+ export type DownloadProgressListener = (downloads: DownloadProgressChange[]) => void;
14
+ export declare function addDownloadProgressListener(): Promise<void>;
15
+ export declare function removeDownloadProgressListener(): Promise<void>;
16
+ export declare function onDownloadProgressChanged(listener: DownloadProgressListener): EmitterSubscription;
11
17
  export declare function pauseDownload(videoId: string): Promise<void>;
12
18
  export declare function resumeDownload(videoId: string): Promise<void>;
13
19
  export declare function removeDownload(videoId: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"TPStreamsDownload.d.ts","sourceRoot":"","sources":["../../../src/TPStreamsDownload.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,OAAO,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IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAClD,MAAM,MAAM,wBAAwB,GAAG,CACrC,SAAS,EAAE,sBAAsB,EAAE,KAChC,IAAI,CAAC;AAIV,wBAAgB,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3D;AAED,wBAAgB,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,wBAAwB,GACjC,mBAAmB,CAKrB;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE9D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/D;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE1D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAElE;AAED,wBAAgB,eAAe,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAEzD"}
@@ -2,7 +2,7 @@ export { default as TPStreamsPlayerNative } from './TPStreamsPlayerViewNativeCom
2
2
  export * from './TPStreamsPlayerViewNativeComponent';
3
3
  export { default as TPStreamsPlayerView } from './TPStreamsPlayer';
4
4
  export type { TPStreamsPlayerRef } from './TPStreamsPlayer';
5
- export { pauseDownload, resumeDownload, removeDownload, isDownloaded, isDownloading, isPaused, getDownloadStatus, getAllDownloads, type DownloadItem, } from './TPStreamsDownload';
5
+ export { pauseDownload, resumeDownload, removeDownload, isDownloaded, isDownloading, isPaused, getDownloadStatus, getAllDownloads, addDownloadProgressListener, removeDownloadProgressListener, onDownloadProgressChanged, type DownloadItem, type DownloadProgressChange, type DownloadProgressListener, } from './TPStreamsDownload';
6
6
  export declare const TPStreams: {
7
7
  initialize: (organizationId: string) => void;
8
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACxF,cAAc,sCAAsC,CAAC;AAGrD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,SAAS;iCACS,MAAM,KAAG,IAAI;CAG3C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACxF,cAAc,sCAAsC,CAAC;AAGrD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,2BAA2B,EAC3B,8BAA8B,EAC9B,yBAAyB,EACzB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,GAC9B,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,SAAS;iCACS,MAAM,KAAG,IAAI;CAG3C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Video component for TPStreams",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -1,4 +1,5 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeModules, NativeEventEmitter } from 'react-native';
2
+ import type { EmitterSubscription } from 'react-native';
2
3
 
3
4
  const { TPStreamsDownload } = NativeModules;
4
5
 
@@ -13,6 +14,30 @@ export interface DownloadItem {
13
14
  metadata: string;
14
15
  }
15
16
 
17
+ export type DownloadProgressChange = DownloadItem;
18
+ export type DownloadProgressListener = (
19
+ downloads: DownloadProgressChange[]
20
+ ) => void;
21
+
22
+ const downloadEventEmitter = new NativeEventEmitter(TPStreamsDownload);
23
+
24
+ export function addDownloadProgressListener(): Promise<void> {
25
+ return TPStreamsDownload.addDownloadProgressListener();
26
+ }
27
+
28
+ export function removeDownloadProgressListener(): Promise<void> {
29
+ return TPStreamsDownload.removeDownloadProgressListener();
30
+ }
31
+
32
+ export function onDownloadProgressChanged(
33
+ listener: DownloadProgressListener
34
+ ): EmitterSubscription {
35
+ return downloadEventEmitter.addListener(
36
+ 'onDownloadProgressChanged',
37
+ listener
38
+ );
39
+ }
40
+
16
41
  export function pauseDownload(videoId: string): Promise<void> {
17
42
  return TPStreamsDownload.pauseDownload(videoId);
18
43
  }
package/src/index.tsx CHANGED
@@ -16,7 +16,12 @@ export {
16
16
  isPaused,
17
17
  getDownloadStatus,
18
18
  getAllDownloads,
19
+ addDownloadProgressListener,
20
+ removeDownloadProgressListener,
21
+ onDownloadProgressChanged,
19
22
  type DownloadItem,
23
+ type DownloadProgressChange,
24
+ type DownloadProgressListener,
20
25
  } from './TPStreamsDownload';
21
26
 
22
27
  const TPStreamsModule = NativeModules.TPStreams;