react-native-tpstreams 0.1.7 → 0.1.9

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/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Bharath
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bharath
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md CHANGED
@@ -1,49 +1,427 @@
1
- # react-native-tpstreams
2
-
3
- Video Component for TPStreams
4
-
5
- ## Installation
6
-
7
- ```sh
8
- npm install react-native-tpstreams
9
- ```
10
-
11
- ## Usage
12
-
13
-
14
- ```js
15
- import React, { useState } from 'react';
16
- import { NativeModules } from 'react-native';
17
- import TpStreamsPlayerView from 'react-native-tpstreams';
18
-
19
- const { Tpstreams } = NativeModules;
20
-
21
- // Initialize the player with your organization UUID
22
- Tpstreams.initializeTPSPlayer("ORGANIZATION_ID");
23
-
24
- const App = () => {
25
- const [playerProps, setPlayerProps] = useState({
26
- videoId: 'ASSET_ID',
27
- accessToken: 'ACCESS_TOKEN',
28
- style: { width: '100%', height: 300 },
29
- });
30
-
31
- return <TpStreamsPlayerView {...playerProps} />;
32
- };
33
-
34
- export default App;
35
-
36
- ```
37
-
38
-
39
- ## Contributing
40
-
41
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
42
-
43
- ## License
44
-
45
- MIT
46
-
47
- ---
48
-
49
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
1
+ # react-native-tpstreams
2
+
3
+ Video Component for TPStreams
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-tpstreams
9
+ ```
10
+
11
+ ### Initializing TPStreams SDK
12
+
13
+ First, import the package:
14
+
15
+ ```javascript
16
+ import { NativeModules } from 'react-native';
17
+ const { Tpstreams } = NativeModules;
18
+ ```
19
+
20
+ Next, initialize the SDK with your organization ID:
21
+
22
+ ```javascript
23
+ Tpstreams.initializeTPSPlayer("YOUR_ORGANIZATION_ID");
24
+ ```
25
+
26
+ Make sure to replace `YOUR_ORGANIZATION_ID` with your actual organization ID. This should be called at the entry point of your application to ensure proper initialization.
27
+
28
+ ## Play a Video
29
+
30
+ To play a video using the TPStreams Player SDK, use the `TpStreamsPlayerView` component:
31
+
32
+ ```javascript
33
+ import React, { useState } from 'react';
34
+ import { View, StyleSheet } from 'react-native';
35
+ import TpStreamsPlayerView from 'react-native-tpstreams';
36
+
37
+ const App = () => {
38
+ const [playerProps] = useState({
39
+ videoId: 'ASSET_ID',
40
+ accessToken: 'ACCESS_TOKEN',
41
+ enableDownload: false,
42
+ autoPlay: true,
43
+ style: { width: '100%', height: 300 },
44
+ });
45
+
46
+ return (
47
+ <View style={styles.container}>
48
+ <TpStreamsPlayerView {...playerProps} />
49
+ </View>
50
+ );
51
+ };
52
+
53
+ const styles = StyleSheet.create({
54
+ container: {
55
+ flex: 1,
56
+ justifyContent: 'center',
57
+ alignItems: 'center',
58
+ },
59
+ });
60
+
61
+ export default App;
62
+ ```
63
+
64
+ Replace `ASSET_ID` and `ACCESS_TOKEN` with the actual assetId and accessToken of the video you wish to play.
65
+
66
+ ## Player Props
67
+ The player component accepts the following props:
68
+
69
+ | Prop | Type | Required | Default | Description |
70
+ |----------------|---------|----------|---------------------------------|------------------------------------------------|
71
+ | `videoId` | string | Yes | - | The unique identifier of the video asset. |
72
+ | `accessToken` | string | Yes | - | The authentication token required to access the video. |
73
+ | `enableDownload` | boolean | No | `true` | Enables or disables video download. |
74
+ | `autoPlay` | boolean | No | `true` | Controls whether the video should start playing automatically. |
75
+ | `style` | object | No | `{ width: '100%', height: 300 }` | Defines the player’s width and height. |
76
+
77
+ # Player Methods
78
+
79
+ To use the `Tpstreams` module, first import `NativeModules` from `react-native` and get the `Tpstreams` instance:
80
+
81
+ ```js
82
+ import { NativeModules } from 'react-native';
83
+ const { Tpstreams } = NativeModules;
84
+ ```
85
+
86
+ The `Tpstreams` module provides several methods to control video playback and manage player states. Below is a detailed explanation of each method:
87
+
88
+ ## Play
89
+
90
+ ```js
91
+ Tpstreams.play();
92
+ ```
93
+
94
+ Starts video playback. Call this method when you want the video to start playing or resume after being paused.
95
+
96
+ ## Pause
97
+
98
+ ```js
99
+ Tpstreams.pause();
100
+ ```
101
+
102
+ Pauses video playback, allowing it to be resumed later from the same position.
103
+
104
+ ## Seek To
105
+
106
+ ```js
107
+ Tpstreams.seekTo(position: number);
108
+ ```
109
+
110
+ Seeks to a specific position in the video (in milliseconds).
111
+
112
+ **Example Usage:**
113
+
114
+ ```js
115
+ Tpstreams.seekTo(10000); // Jump to the 10-second mark
116
+ ```
117
+
118
+ ## Get Current Time
119
+
120
+ ```js
121
+ Tpstreams.getCurrentTime().then(console.log);
122
+ ```
123
+
124
+ Gets the current playback position of the video (in milliseconds). Returns a promise that resolves with the current time.
125
+
126
+ ## Get Duration
127
+
128
+ ```js
129
+ Tpstreams.getDuration().then(console.log);
130
+ ```
131
+
132
+ Retrieves the total duration of the currently loaded video (in milliseconds). Returns a promise that resolves with the total duration.
133
+
134
+ ## Get Buffered Time
135
+
136
+ ```js
137
+ Tpstreams.getBufferedTime().then(console.log);
138
+ ```
139
+
140
+ Gets the amount of video data that has been buffered (in milliseconds). Returns a promise that resolves with the buffered time.
141
+
142
+ ## Get Playback State
143
+
144
+ ```js
145
+ Tpstreams.getPlaybackState().then(console.log);
146
+ ```
147
+
148
+ Gets the current playback state of the player (e.g., `playing`, `paused`, `buffering`). Returns a promise that resolves with the state.
149
+
150
+ ## Get Play When Ready
151
+
152
+ ```js
153
+ Tpstreams.getPlayWhenReady().then(console.log);
154
+ ```
155
+
156
+ Checks if the player is set to start playback automatically. Returns a promise that resolves with a boolean value.
157
+
158
+ ## Set Play When Ready
159
+
160
+ ```js
161
+ Tpstreams.setPlayWhenReady(true); // Enable autoplay
162
+ ```
163
+
164
+ Controls whether the player should start playback automatically when loaded.
165
+
166
+ ## Get Playback Speed
167
+
168
+ ```js
169
+ Tpstreams.getPlaybackSpeed().then(console.log);
170
+ ```
171
+
172
+ Gets the current playback speed of the video. Returns a promise that resolves with the speed value.
173
+
174
+ ## Set Playback Speed
175
+
176
+ ```js
177
+ Tpstreams.setPlaybackSpeed(1.5); // Play at 1.5x speed
178
+ ```
179
+
180
+ Changes the playback speed of the video.
181
+
182
+ ## Release
183
+
184
+ ```js
185
+ Tpstreams.release();
186
+ ```
187
+
188
+ Releases the player resources, stopping playback and hiding the player UI. Once called, the player cannot be used again unless reinitialized.
189
+
190
+
191
+ # Player Events
192
+
193
+ `Tpstreams` provides event listeners to handle various player events. Below are the available events and how to use them:
194
+
195
+ ## Listening to Events
196
+
197
+ To subscribe to player events, use the `NativeEventEmitter` from `react-native` with `TpstreamsModule`:
198
+
199
+ ```js
200
+ import { NativeEventEmitter, NativeModules } from 'react-native';
201
+
202
+ const { Tpstreams } = NativeModules;
203
+ const eventEmitter = new NativeEventEmitter(Tpstreams);
204
+
205
+ const subscription = eventEmitter.addListener('onPlaybackStateChanged', (state) => {
206
+ console.log('Playback State Changed:', state);
207
+ });
208
+
209
+ // Remember to remove the listener when unmounting
210
+ subscription.remove();
211
+ ```
212
+
213
+ ## Available Events
214
+
215
+ ### onPlaybackStateChanged
216
+ Triggered when the playback state changes.
217
+
218
+ ```js
219
+ eventEmitter.addListener('onPlaybackStateChanged', (state) => {
220
+ console.log('Playback State:', state);
221
+ });
222
+ ```
223
+
224
+ ### onAccessTokenExpired
225
+ Triggered when the access token expires (requires refresh).
226
+
227
+ ```js
228
+ eventEmitter.addListener('onAccessTokenExpired', () => {
229
+ console.log('Access token expired, please refresh.');
230
+ });
231
+ ```
232
+
233
+ ### onMarkerCallback
234
+ Triggered when a marker (timestamp) is reached during playback.
235
+
236
+ ```js
237
+ eventEmitter.addListener('onMarkerCallback', (marker) => {
238
+ console.log('Marker reached:', marker);
239
+ });
240
+ ```
241
+
242
+ ### onDeviceInfoChanged
243
+ Triggered when the device information changes.
244
+
245
+ ```js
246
+ eventEmitter.addListener('onDeviceInfoChanged', (info) => {
247
+ console.log('Device info changed:', info);
248
+ });
249
+ ```
250
+
251
+ ### onFullScreenChanged
252
+ Triggered when the fullscreen mode changes.
253
+
254
+ ```js
255
+ eventEmitter.addListener('onFullScreenChanged', (isFullscreen) => {
256
+ console.log('Fullscreen mode:', isFullscreen);
257
+ });
258
+ ```
259
+
260
+ ### onIsLoadingChanged
261
+ Triggered when the player’s loading state changes.
262
+
263
+ ```js
264
+ eventEmitter.addListener('onIsLoadingChanged', (isLoading) => {
265
+ console.log('Loading state changed:', isLoading);
266
+ });
267
+ ```
268
+
269
+ ### onIsPlayingChanged
270
+ Triggered when the player’s playing state changes.
271
+
272
+ ```js
273
+ eventEmitter.addListener('onIsPlayingChanged', (isPlaying) => {
274
+ console.log('Playing state:', isPlaying);
275
+ });
276
+ ```
277
+
278
+ ### onPlayerError
279
+ Triggered when the player encounters an error.
280
+
281
+ ```js
282
+ eventEmitter.addListener('onPlayerError', (error) => {
283
+ console.log('Player Error:', error);
284
+ });
285
+ ```
286
+
287
+ ### onSeekBackIncrementChanged
288
+ Triggered when the seek-back increment value changes.
289
+
290
+ ```js
291
+ eventEmitter.addListener('onSeekBackIncrementChanged', (value) => {
292
+ console.log('Seek back increment changed:', value);
293
+ });
294
+ ```
295
+
296
+ ### onSeekForwardIncrementChanged
297
+ Triggered when the seek-forward increment value changes.
298
+
299
+ ```js
300
+ eventEmitter.addListener('onSeekForwardIncrementChanged', (value) => {
301
+ console.log('Seek forward increment changed:', value);
302
+ });
303
+ ```
304
+
305
+ ### onTimelineChanged
306
+ Triggered when the timeline of the player changes.
307
+
308
+ ```js
309
+ eventEmitter.addListener('onTimelineChanged', (timeline) => {
310
+ console.log('Timeline changed:', timeline);
311
+ });
312
+ ```
313
+
314
+ ### onTracksChanged
315
+ Triggered when the available tracks change (e.g., audio/video/subtitles).
316
+
317
+ ```js
318
+ eventEmitter.addListener('onTracksChanged', (tracks) => {
319
+ console.log('Tracks changed:', tracks);
320
+ });
321
+ ```
322
+
323
+ # Download Module
324
+
325
+ The `Download Module` in `Tpstreams` allows users to manage offline video downloads efficiently. This includes observing download progress, pausing, resuming, canceling, and deleting downloads.
326
+
327
+ ## Observing Download Data
328
+
329
+ To start observing the download data, call the `observeDownloadData` method from `FragmentModule`.
330
+
331
+ ```js
332
+ import { NativeModules, DeviceEventEmitter } from 'react-native';
333
+
334
+ const { FragmentModule } = NativeModules;
335
+ FragmentModule.observeDownloadData();
336
+ ```
337
+
338
+ Once initialized, the module will emit events whenever the download data changes.
339
+
340
+ ## Listening to Download Events
341
+
342
+ To listen for download state changes, use `DeviceEventEmitter`:
343
+
344
+ ```js
345
+ const subscription = DeviceEventEmitter.addListener(
346
+ 'onDownloadDataChanged',
347
+ (event) => {
348
+ console.log('Download data updated:', event.assets);
349
+ }
350
+ );
351
+
352
+ // Remember to remove the listener when unmounting
353
+ subscription.remove();
354
+ ```
355
+
356
+ ## Managing Downloads
357
+
358
+ ### Pause Download
359
+ Pauses an active download.
360
+
361
+ ```js
362
+ FragmentModule.pauseDownload(videoId);
363
+ ```
364
+
365
+ ### Resume Download
366
+ Resumes a paused download.
367
+
368
+ ```js
369
+ FragmentModule.resumeDownload(videoId);
370
+ ```
371
+
372
+ ### Cancel Download
373
+ Cancels an ongoing download.
374
+
375
+ ```js
376
+ FragmentModule.cancelDownload(videoId);
377
+ ```
378
+
379
+ ### Delete Download
380
+ Deletes a completed download from storage.
381
+
382
+ ```js
383
+ FragmentModule.deleteDownload(videoId);
384
+ ```
385
+
386
+ ## Rendering a Download List
387
+
388
+ Below is a sample implementation of a download list UI using `FlatList` in React Native:
389
+
390
+ ```js
391
+ import React, { useState, useEffect } from 'react';
392
+ import { SafeAreaView, Text, FlatList, View, Button, DeviceEventEmitter } from 'react-native';
393
+ import { NativeModules } from 'react-native';
394
+
395
+ const { FragmentModule } = NativeModules;
396
+
397
+ const DownloadListScreen = () => {
398
+ const [downloads, setDownloads] = useState([]);
399
+
400
+ useEffect(() => {
401
+ FragmentModule.observeDownloadData();
402
+ const subscription = DeviceEventEmitter.addListener('onDownloadDataChanged', (event) => {
403
+ setDownloads(event.assets);
404
+ });
405
+ return () => subscription.remove();
406
+ }, []);
407
+
408
+ const renderItem = ({ item }) => (
409
+ <View>
410
+ <Text>{item.title} - {item.percentage}%</Text>
411
+ {item.status === 'DOWNLOADING' && <Button title="Pause" onPress={() => FragmentModule.pauseDownload(item.videoId)} />}
412
+ {item.status === 'COMPLETE' && <Button title="Delete" onPress={() => FragmentModule.deleteDownload(item.videoId)} />}
413
+ {item.status === 'PAUSED' && <Button title="Resume" onPress={() => FragmentModule.resumeDownload(item.videoId)} />}
414
+ </View>
415
+ );
416
+
417
+ return (
418
+ <SafeAreaView>
419
+ <FlatList data={downloads} keyExtractor={(item) => item.videoId} renderItem={renderItem} />
420
+ </SafeAreaView>
421
+ );
422
+ };
423
+
424
+ export default DownloadListScreen;
425
+ ```
426
+
427
+ This component observes download events and dynamically updates the list with buttons for user interactions.
package/Tpstreams.podspec CHANGED
@@ -1,42 +1,42 @@
1
- require "json"
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
-
6
- Pod::Spec.new do |s|
7
- s.name = "Tpstreams"
8
- s.version = package["version"]
9
- s.summary = package["description"]
10
- s.homepage = package["homepage"]
11
- s.license = package["license"]
12
- s.authors = package["author"]
13
-
14
- s.platforms = { :ios => min_ios_version_supported }
15
- s.source = { :git => "https://github.com/testpress/react-native-player-sdk.git", :tag => "#{s.version}" }
16
-
17
- s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
- s.private_header_files = "ios/generated/**/*.h"
19
-
20
- # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
- # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
- if respond_to?(:install_modules_dependencies, true)
23
- install_modules_dependencies(s)
24
- else
25
- s.dependency "React-Core"
26
-
27
- # Don't install the dependencies when we run `pod install` in the old architecture.
28
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
29
- s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
30
- s.pod_target_xcconfig = {
31
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
32
- "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
33
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
34
- }
35
- s.dependency "React-Codegen"
36
- s.dependency "RCT-Folly"
37
- s.dependency "RCTRequired"
38
- s.dependency "RCTTypeSafety"
39
- s.dependency "ReactCommon/turbomodule/core"
40
- end
41
- end
42
- end
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "Tpstreams"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => min_ios_version_supported }
15
+ s.source = { :git => "https://github.com/testpress/react-native-player-sdk.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
+ s.private_header_files = "ios/generated/**/*.h"
19
+
20
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
+ if respond_to?(:install_modules_dependencies, true)
23
+ install_modules_dependencies(s)
24
+ else
25
+ s.dependency "React-Core"
26
+
27
+ # Don't install the dependencies when we run `pod install` in the old architecture.
28
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
29
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
30
+ s.pod_target_xcconfig = {
31
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
32
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
33
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
34
+ }
35
+ s.dependency "React-Codegen"
36
+ s.dependency "RCT-Folly"
37
+ s.dependency "RCTRequired"
38
+ s.dependency "RCTTypeSafety"
39
+ s.dependency "ReactCommon/turbomodule/core"
40
+ end
41
+ end
42
+ end