react-native-tpstreams 0.1.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/LICENSE +20 -0
- package/README.md +49 -0
- package/Tpstreams.podspec +42 -0
- package/android/build.gradle +122 -0
- package/android/generated/java/com/tpstreams/NativeTpstreamsSpec.java +37 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNTpstreamsSpec-generated.cpp +32 -0
- package/android/generated/jni/RNTpstreamsSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI-generated.cpp +28 -0
- package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI.h +71 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/tpstreams/FragmentModule.kt +183 -0
- package/android/src/main/java/com/tpstreams/PlayerFragment.kt +91 -0
- package/android/src/main/java/com/tpstreams/TpStreamsPlayerView.kt +45 -0
- package/android/src/main/java/com/tpstreams/TpStreamsPlayerViewManager.kt +29 -0
- package/android/src/main/java/com/tpstreams/TpstreamsModule.kt +25 -0
- package/android/src/main/java/com/tpstreams/TpstreamsPackage.kt +16 -0
- package/android/src/main/res/layout/fragment_player.xml +29 -0
- package/ios/Tpstreams.h +6 -0
- package/ios/Tpstreams.mm +18 -0
- package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec-generated.mm +39 -0
- package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec.h +63 -0
- package/ios/generated/RNTpstreamsSpecJSI-generated.cpp +28 -0
- package/ios/generated/RNTpstreamsSpecJSI.h +71 -0
- package/lib/commonjs/NativeTpstreams.js +9 -0
- package/lib/commonjs/NativeTpstreams.js.map +1 -0
- package/lib/commonjs/index.js +10 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/NativeTpstreams.js +5 -0
- package/lib/module/NativeTpstreams.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeTpstreams.d.ts +7 -0
- package/lib/typescript/commonjs/src/NativeTpstreams.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +5 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +6 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeTpstreams.d.ts +7 -0
- package/lib/typescript/module/src/NativeTpstreams.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +5 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +6 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +203 -0
- package/react-native.config.js +12 -0
- package/src/NativeTpstreams.ts +8 -0
- package/src/index.tsx +9 -0
- package/src/types.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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)
|
|
@@ -0,0 +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
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Tpstreams_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
rootProject.allprojects {
|
|
19
|
+
repositories {
|
|
20
|
+
mavenCentral() // Ensure this line is here
|
|
21
|
+
google()
|
|
22
|
+
maven {
|
|
23
|
+
url "https://github.com/testpress/maven/raw/main/repo"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def isNewArchitectureEnabled() {
|
|
30
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.android.library"
|
|
34
|
+
apply plugin: "kotlin-android"
|
|
35
|
+
|
|
36
|
+
if (isNewArchitectureEnabled()) {
|
|
37
|
+
apply plugin: "com.facebook.react"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def getExtOrIntegerDefault(name) {
|
|
41
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Tpstreams_" + name]).toInteger()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def supportsNamespace() {
|
|
45
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
46
|
+
def major = parsed[0].toInteger()
|
|
47
|
+
def minor = parsed[1].toInteger()
|
|
48
|
+
|
|
49
|
+
// Namespace support was added in 7.3.0
|
|
50
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
android {
|
|
54
|
+
if (supportsNamespace()) {
|
|
55
|
+
namespace "com.tpstreams"
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
65
|
+
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
68
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
69
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
buildFeatures {
|
|
73
|
+
buildConfig true
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
buildTypes {
|
|
77
|
+
release {
|
|
78
|
+
minifyEnabled false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
lintOptions {
|
|
83
|
+
disable "GradleCompatible"
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
compileOptions {
|
|
87
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
88
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sourceSets {
|
|
92
|
+
main {
|
|
93
|
+
if (isNewArchitectureEnabled()) {
|
|
94
|
+
java.srcDirs += [
|
|
95
|
+
"generated/java",
|
|
96
|
+
"generated/jni"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
repositories {
|
|
104
|
+
mavenCentral()
|
|
105
|
+
google()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
109
|
+
|
|
110
|
+
dependencies {
|
|
111
|
+
implementation "com.facebook.react:react-android"
|
|
112
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
113
|
+
implementation "com.tpstreams.player:player:3.1.4"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isNewArchitectureEnabled()) {
|
|
117
|
+
react {
|
|
118
|
+
jsRootDir = file("../src/")
|
|
119
|
+
libraryName = "Tpstreams"
|
|
120
|
+
codegenJavaPackageName = "com.tpstreams"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
+
*
|
|
10
|
+
* @nolint
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
package com.tpstreams;
|
|
14
|
+
|
|
15
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
19
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
20
|
+
import javax.annotation.Nonnull;
|
|
21
|
+
|
|
22
|
+
public abstract class NativeTpstreamsSpec extends ReactContextBaseJavaModule implements TurboModule {
|
|
23
|
+
public static final String NAME = "Tpstreams";
|
|
24
|
+
|
|
25
|
+
public NativeTpstreamsSpec(ReactApplicationContext reactContext) {
|
|
26
|
+
super(reactContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Override
|
|
30
|
+
public @Nonnull String getName() {
|
|
31
|
+
return NAME;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
35
|
+
@DoNotStrip
|
|
36
|
+
public abstract double multiply(double a, double b);
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
cmake_minimum_required(VERSION 3.13)
|
|
7
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
8
|
+
|
|
9
|
+
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNTpstreamsSpec/*.cpp)
|
|
10
|
+
|
|
11
|
+
add_library(
|
|
12
|
+
react_codegen_RNTpstreamsSpec
|
|
13
|
+
OBJECT
|
|
14
|
+
${react_codegen_SRCS}
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
target_include_directories(react_codegen_RNTpstreamsSpec PUBLIC . react/renderer/components/RNTpstreamsSpec)
|
|
18
|
+
|
|
19
|
+
target_link_libraries(
|
|
20
|
+
react_codegen_RNTpstreamsSpec
|
|
21
|
+
fbjni
|
|
22
|
+
jsi
|
|
23
|
+
# We need to link different libraries based on whether we are building rncore or not, that's necessary
|
|
24
|
+
# because we want to break a circular dependency between react_codegen_rncore and reactnative
|
|
25
|
+
reactnative
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
target_compile_options(
|
|
29
|
+
react_codegen_RNTpstreamsSpec
|
|
30
|
+
PRIVATE
|
|
31
|
+
-DLOG_TAG=\"ReactNative\"
|
|
32
|
+
-fexceptions
|
|
33
|
+
-frtti
|
|
34
|
+
-std=c++20
|
|
35
|
+
-Wall
|
|
36
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJniCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "RNTpstreamsSpec.h"
|
|
12
|
+
|
|
13
|
+
namespace facebook::react {
|
|
14
|
+
|
|
15
|
+
static facebook::jsi::Value __hostFunction_NativeTpstreamsSpecJSI_multiply(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
16
|
+
static jmethodID cachedMethodId = nullptr;
|
|
17
|
+
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, NumberKind, "multiply", "(DD)D", args, count, cachedMethodId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
NativeTpstreamsSpecJSI::NativeTpstreamsSpecJSI(const JavaTurboModule::InitParams ¶ms)
|
|
21
|
+
: JavaTurboModule(params) {
|
|
22
|
+
methodMap_["multiply"] = MethodMetadata {2, __hostFunction_NativeTpstreamsSpecJSI_multiply};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::shared_ptr<TurboModule> RNTpstreamsSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
26
|
+
if (moduleName == "Tpstreams") {
|
|
27
|
+
return std::make_shared<NativeTpstreamsSpecJSI>(params);
|
|
28
|
+
}
|
|
29
|
+
return nullptr;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJniH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
14
|
+
#include <ReactCommon/TurboModule.h>
|
|
15
|
+
#include <jsi/jsi.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook::react {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* JNI C++ class for module 'NativeTpstreams'
|
|
21
|
+
*/
|
|
22
|
+
class JSI_EXPORT NativeTpstreamsSpecJSI : public JavaTurboModule {
|
|
23
|
+
public:
|
|
24
|
+
NativeTpstreamsSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
JSI_EXPORT
|
|
29
|
+
std::shared_ptr<TurboModule> RNTpstreamsSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
30
|
+
|
|
31
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleCpp.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "RNTpstreamsSpecJSI.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
static jsi::Value __hostFunction_NativeTpstreamsCxxSpecJSI_multiply(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
15
|
+
return static_cast<NativeTpstreamsCxxSpecJSI *>(&turboModule)->multiply(
|
|
16
|
+
rt,
|
|
17
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber(),
|
|
18
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asNumber()
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
NativeTpstreamsCxxSpecJSI::NativeTpstreamsCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
23
|
+
: TurboModule("Tpstreams", jsInvoker) {
|
|
24
|
+
methodMap_["multiply"] = MethodMetadata {2, __hostFunction_NativeTpstreamsCxxSpecJSI_multiply};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleH.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <ReactCommon/TurboModule.h>
|
|
13
|
+
#include <react/bridging/Bridging.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class JSI_EXPORT NativeTpstreamsCxxSpecJSI : public TurboModule {
|
|
19
|
+
protected:
|
|
20
|
+
NativeTpstreamsCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
virtual double multiply(jsi::Runtime &rt, double a, double b) = 0;
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
template <typename T>
|
|
28
|
+
class JSI_EXPORT NativeTpstreamsCxxSpec : public TurboModule {
|
|
29
|
+
public:
|
|
30
|
+
jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
|
31
|
+
return delegate_.create(rt, propName);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
|
|
35
|
+
return delegate_.getPropertyNames(runtime);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static constexpr std::string_view kModuleName = "Tpstreams";
|
|
39
|
+
|
|
40
|
+
protected:
|
|
41
|
+
NativeTpstreamsCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
|
42
|
+
: TurboModule(std::string{NativeTpstreamsCxxSpec::kModuleName}, jsInvoker),
|
|
43
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
class Delegate : public NativeTpstreamsCxxSpecJSI {
|
|
48
|
+
public:
|
|
49
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
|
50
|
+
NativeTpstreamsCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
double multiply(jsi::Runtime &rt, double a, double b) override {
|
|
55
|
+
static_assert(
|
|
56
|
+
bridging::getParameterCount(&T::multiply) == 3,
|
|
57
|
+
"Expected multiply(...) to have 3 parameters");
|
|
58
|
+
|
|
59
|
+
return bridging::callFromJs<double>(
|
|
60
|
+
rt, &T::multiply, jsInvoker_, instance_, std::move(a), std::move(b));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
friend class NativeTpstreamsCxxSpec;
|
|
65
|
+
T *instance_;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
Delegate delegate_;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
package com.tpstreams
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import androidx.fragment.app.FragmentActivity
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
|
+
import android.util.Log
|
|
10
|
+
import androidx.lifecycle.LiveData
|
|
11
|
+
import androidx.lifecycle.ViewModel
|
|
12
|
+
import androidx.lifecycle.ViewModelProvider
|
|
13
|
+
import com.facebook.react.bridge.Arguments
|
|
14
|
+
import com.facebook.react.bridge.WritableMap
|
|
15
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
16
|
+
import com.tpstream.player.data.Asset
|
|
17
|
+
import com.tpstream.player.offline.TpStreamDownloadManager
|
|
18
|
+
import com.tpstream.player.TPStreamsSDK
|
|
19
|
+
|
|
20
|
+
class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
21
|
+
|
|
22
|
+
lateinit var viewModel: DownloadListViewModel
|
|
23
|
+
private var assets = listOf<Asset>()
|
|
24
|
+
|
|
25
|
+
override fun initialize() {
|
|
26
|
+
super.initialize()
|
|
27
|
+
(currentActivity as? FragmentActivity)?.let {
|
|
28
|
+
viewModel = DownloadListViewModel.init(it)
|
|
29
|
+
}
|
|
30
|
+
Log.d("FragmentModule", "initialize: ")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun getName(): String {
|
|
34
|
+
return "FragmentModule"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun showCustomFragment(videoId: String, accessToken: String) {
|
|
39
|
+
Log.e("FragmentModule", "showCustomFragment() called")
|
|
40
|
+
// Ensure the currentActivity is a FragmentActivity
|
|
41
|
+
val activity = currentActivity as? FragmentActivity
|
|
42
|
+
activity?.let {
|
|
43
|
+
// Begin the fragment transaction
|
|
44
|
+
val fragmentTransaction = it.supportFragmentManager.beginTransaction()
|
|
45
|
+
|
|
46
|
+
// Create a new fragment instance
|
|
47
|
+
val bundle = Bundle()
|
|
48
|
+
bundle.putString("VIDEO_ID", videoId)
|
|
49
|
+
bundle.putString("ACCESS_TOKEN", accessToken)
|
|
50
|
+
val fragment = PlayerFragment()
|
|
51
|
+
fragment.setArguments(bundle)
|
|
52
|
+
|
|
53
|
+
// Find a container to add the fragment
|
|
54
|
+
val fragmentContainerId = android.R.id.content // or you could specify your own container ID
|
|
55
|
+
|
|
56
|
+
// Add the fragment
|
|
57
|
+
fragmentTransaction.replace(fragmentContainerId, fragment)
|
|
58
|
+
fragmentTransaction.addToBackStack(null) // Optional: Add fragment to back stack
|
|
59
|
+
fragmentTransaction.commit()
|
|
60
|
+
} ?: run {
|
|
61
|
+
// Handle the error if the activity is not a FragmentActivity
|
|
62
|
+
Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactMethod
|
|
67
|
+
fun closeCustomFragment() {
|
|
68
|
+
Log.e("FragmentModule", "closeCustomFragment() called")
|
|
69
|
+
// Ensure the currentActivity is a FragmentActivity
|
|
70
|
+
val activity = currentActivity as? FragmentActivity
|
|
71
|
+
activity?.let {
|
|
72
|
+
// Access the fragment manager
|
|
73
|
+
val fragmentManager = it.supportFragmentManager
|
|
74
|
+
|
|
75
|
+
// Check if there are any fragments in the back stack
|
|
76
|
+
if (fragmentManager.backStackEntryCount > 0) {
|
|
77
|
+
// Pop the last fragment off the back stack
|
|
78
|
+
fragmentManager.popBackStack()
|
|
79
|
+
} else {
|
|
80
|
+
Log.e("FragmentModule", "No fragments in the back stack to remove")
|
|
81
|
+
}
|
|
82
|
+
} ?: run {
|
|
83
|
+
// Handle the error if the activity is not a FragmentActivity
|
|
84
|
+
Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
fun observeDownloadData() {
|
|
90
|
+
// Ensure this code runs on the main thread
|
|
91
|
+
currentActivity?.runOnUiThread {
|
|
92
|
+
val activity = currentActivity as? FragmentActivity
|
|
93
|
+
activity?.let {
|
|
94
|
+
// Observe LiveData only on the main thread
|
|
95
|
+
viewModel.getDownloadData().observe(it) { assets ->
|
|
96
|
+
this.assets = assets ?: emptyList()
|
|
97
|
+
// Emit event to React Native
|
|
98
|
+
val eventMap = Arguments.createMap()
|
|
99
|
+
val assetsList = Arguments.createArray()
|
|
100
|
+
|
|
101
|
+
assets?.forEachIndexed { index , asset ->
|
|
102
|
+
val assetMap = Arguments.createMap()
|
|
103
|
+
assetMap.putString("id", index.toString())
|
|
104
|
+
assetMap.putString("videoId", asset.id)
|
|
105
|
+
assetMap.putString("title", asset.title)
|
|
106
|
+
assetMap.putString("percentage", asset.video.percentageDownloaded.toString())
|
|
107
|
+
assetMap.putString("status", asset.video.downloadState?.name ?: "Unknown")
|
|
108
|
+
assetMap.putString("duration", asset.video.duration.toString())
|
|
109
|
+
|
|
110
|
+
assetsList.pushMap(assetMap)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
eventMap.putArray("assets", assetsList)
|
|
114
|
+
reactApplicationContext
|
|
115
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
116
|
+
.emit("onDownloadDataChanged", eventMap)
|
|
117
|
+
}
|
|
118
|
+
} ?: run {
|
|
119
|
+
Log.e("FragmentModule", "Current activity is not a FragmentActivity")
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod
|
|
125
|
+
fun pauseDownload(videoId: String) {
|
|
126
|
+
val asset = assets.first { it.id == videoId }
|
|
127
|
+
viewModel.pauseDownload(asset)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@ReactMethod
|
|
131
|
+
fun resumeDownload(videoId: String) {
|
|
132
|
+
val asset = assets.first { it.id == videoId }
|
|
133
|
+
viewModel.resumeDownload(asset)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@ReactMethod
|
|
137
|
+
fun cancelDownload(videoId: String) {
|
|
138
|
+
val asset = assets.first { it.id == videoId }
|
|
139
|
+
viewModel.cancelDownload(asset)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@ReactMethod
|
|
143
|
+
fun deleteDownload(videoId: String) {
|
|
144
|
+
val asset = assets.first { it.id == videoId }
|
|
145
|
+
viewModel.deleteDownload(asset)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
class DownloadListViewModel(context: Context): ViewModel() {
|
|
151
|
+
|
|
152
|
+
private var tpStreamDownloadManager: TpStreamDownloadManager = TpStreamDownloadManager(context)
|
|
153
|
+
|
|
154
|
+
fun getDownloadData(): LiveData<List<Asset>?> {
|
|
155
|
+
return tpStreamDownloadManager.getAllDownloads()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fun pauseDownload(offlineAssetInfo: Asset) {
|
|
159
|
+
tpStreamDownloadManager.pauseDownload(offlineAssetInfo)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fun resumeDownload(offlineAssetInfo: Asset) {
|
|
163
|
+
tpStreamDownloadManager.resumeDownload(offlineAssetInfo)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fun cancelDownload(offlineAssetInfo: Asset) {
|
|
167
|
+
tpStreamDownloadManager.cancelDownload(offlineAssetInfo)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fun deleteDownload(offlineAssetInfo: Asset) {
|
|
171
|
+
tpStreamDownloadManager.deleteDownload(offlineAssetInfo)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
companion object {
|
|
175
|
+
fun init(fragmentActivity: FragmentActivity) : DownloadListViewModel {
|
|
176
|
+
return ViewModelProvider(fragmentActivity, object : ViewModelProvider.Factory {
|
|
177
|
+
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
|
178
|
+
return DownloadListViewModel(fragmentActivity) as T
|
|
179
|
+
}
|
|
180
|
+
})[DownloadListViewModel::class.java]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|