react-native-tpstreams 0.1.14 → 0.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.
Files changed (71) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +20 -418
  3. package/Tpstreams.podspec +3 -25
  4. package/android/build.gradle +14 -42
  5. package/android/src/main/AndroidManifest.xml +1 -3
  6. package/android/src/main/java/com/tpstreams/TPStreamsRNModule.kt +18 -0
  7. package/android/src/main/java/com/tpstreams/{TpstreamsPackage.kt → TPStreamsRNPackage.kt} +10 -5
  8. package/android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt +53 -0
  9. package/android/src/main/java/com/tpstreams/TPStreamsRNPlayerViewManager.kt +46 -0
  10. package/ios/TpstreamsView.h +14 -0
  11. package/ios/TpstreamsView.mm +71 -0
  12. package/ios/TpstreamsViewManager.mm +19 -0
  13. package/lib/module/TPStreamsPlayerViewNativeComponent.ts +9 -0
  14. package/lib/module/index.js +9 -3
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/typescript/package.json +1 -0
  17. package/lib/typescript/src/TPStreamsPlayerViewNativeComponent.d.ts +9 -0
  18. package/lib/typescript/src/TPStreamsPlayerViewNativeComponent.d.ts.map +1 -0
  19. package/lib/typescript/src/index.d.ts +6 -0
  20. package/lib/typescript/src/index.d.ts.map +1 -0
  21. package/package.json +42 -76
  22. package/src/TPStreamsPlayerViewNativeComponent.ts +9 -0
  23. package/src/index.tsx +9 -7
  24. package/android/generated/java/com/tpstreams/NativeTpstreamsSpec.java +0 -37
  25. package/android/generated/jni/CMakeLists.txt +0 -36
  26. package/android/generated/jni/RNTpstreamsSpec-generated.cpp +0 -32
  27. package/android/generated/jni/RNTpstreamsSpec.h +0 -31
  28. package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI-generated.cpp +0 -28
  29. package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI.h +0 -71
  30. package/android/libs/extracted-aar/META-INF/com/android/build/gradle/aar-metadata.properties +0 -4
  31. package/android/src/main/AndroidManifestNew.xml +0 -2
  32. package/android/src/main/java/com/tpstreams/FragmentModule.kt +0 -192
  33. package/android/src/main/java/com/tpstreams/PlayerFragment.kt +0 -226
  34. package/android/src/main/java/com/tpstreams/TpStreamsPlayerView.kt +0 -93
  35. package/android/src/main/java/com/tpstreams/TpStreamsPlayerViewManager.kt +0 -49
  36. package/android/src/main/java/com/tpstreams/TpstreamsModule.kt +0 -168
  37. package/android/src/main/res/layout/fragment_player.xml +0 -29
  38. package/android/src/main/res/xml/network_security_config.xml +0 -8
  39. package/ios/Tpstreams.h +0 -6
  40. package/ios/Tpstreams.mm +0 -18
  41. package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec-generated.mm +0 -39
  42. package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec.h +0 -63
  43. package/ios/generated/RNTpstreamsSpecJSI-generated.cpp +0 -28
  44. package/ios/generated/RNTpstreamsSpecJSI.h +0 -71
  45. package/lib/commonjs/NativeTpstreams.js +0 -9
  46. package/lib/commonjs/NativeTpstreams.js.map +0 -1
  47. package/lib/commonjs/index.js +0 -10
  48. package/lib/commonjs/index.js.map +0 -1
  49. package/lib/commonjs/types.js +0 -2
  50. package/lib/commonjs/types.js.map +0 -1
  51. package/lib/module/NativeTpstreams.js +0 -5
  52. package/lib/module/NativeTpstreams.js.map +0 -1
  53. package/lib/module/types.js +0 -2
  54. package/lib/module/types.js.map +0 -1
  55. package/lib/typescript/commonjs/package.json +0 -1
  56. package/lib/typescript/commonjs/src/NativeTpstreams.d.ts +0 -7
  57. package/lib/typescript/commonjs/src/NativeTpstreams.d.ts.map +0 -1
  58. package/lib/typescript/commonjs/src/index.d.ts +0 -5
  59. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  60. package/lib/typescript/commonjs/src/types.d.ts +0 -10
  61. package/lib/typescript/commonjs/src/types.d.ts.map +0 -1
  62. package/lib/typescript/module/src/NativeTpstreams.d.ts +0 -7
  63. package/lib/typescript/module/src/NativeTpstreams.d.ts.map +0 -1
  64. package/lib/typescript/module/src/index.d.ts +0 -5
  65. package/lib/typescript/module/src/index.d.ts.map +0 -1
  66. package/lib/typescript/module/src/types.d.ts +0 -10
  67. package/lib/typescript/module/src/types.d.ts.map +0 -1
  68. package/react-native.config.js +0 -12
  69. package/src/NativeTpstreams.ts +0 -8
  70. package/src/types.ts +0 -9
  71. /package/lib/{typescript/module → module}/package.json +0 -0
@@ -1,71 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- aarFormatVersion=1.0
2
- aarMetadataVersion=1.0
3
- minCompileSdk=1
4
- minAndroidGradlePluginVersion=1.0.0
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,192 +0,0 @@
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, enableDownload: Boolean, autoPlay: Boolean, startAt: Int, offlineLicenseExpireTime: Int) {
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
- bundle.putBoolean("ENABLE_DOWNLOAD_SUPPORT", enableDownload)
51
- bundle.putBoolean("AUTO_PLAY", autoPlay)
52
- bundle.putInt("START_AT", startAt)
53
- bundle.putInt("OFFLINE_LICENSE_EXPIRE_TIME", offlineLicenseExpireTime)
54
- val fragment = PlayerFragment()
55
- fragment.setArguments(bundle)
56
-
57
- // Find a container to add the fragment
58
- val fragmentContainerId = android.R.id.content // or you could specify your own container ID
59
-
60
- // Add the fragment
61
- fragmentTransaction.replace(fragmentContainerId, fragment)
62
- fragmentTransaction.addToBackStack(null) // Optional: Add fragment to back stack
63
- fragmentTransaction.commit()
64
- } ?: run {
65
- // Handle the error if the activity is not a FragmentActivity
66
- Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
67
- }
68
- }
69
-
70
- @ReactMethod
71
- fun closeCustomFragment() {
72
- Log.e("FragmentModule", "closeCustomFragment() called")
73
-
74
- // Ensure currentActivity is a FragmentActivity
75
- val activity = currentActivity as? FragmentActivity
76
- if (activity == null || activity.isFinishing || activity.isDestroyed) {
77
- Log.e("FragmentModule", "Activity is null, finishing, or destroyed")
78
- return
79
- }
80
-
81
- val fragmentManager = activity.supportFragmentManager
82
- val playerFragment = fragmentManager.findFragmentByTag("PLAYER_FRAGMENT") as? PlayerFragment
83
-
84
- if (playerFragment != null) {
85
- Log.d("FragmentModule", "Removing PlayerFragment")
86
- fragmentManager.beginTransaction()
87
- .remove(playerFragment)
88
- .commitAllowingStateLoss() // Avoid IllegalStateException
89
- } else if (fragmentManager.backStackEntryCount > 0) {
90
- Log.d("FragmentModule", "Popping back stack")
91
- fragmentManager.popBackStack()
92
- } else {
93
- Log.e("FragmentModule", "No fragments to remove")
94
- }
95
- }
96
-
97
- @ReactMethod
98
- fun observeDownloadData() {
99
- // Ensure this code runs on the main thread
100
- currentActivity?.runOnUiThread {
101
- val activity = currentActivity as? FragmentActivity
102
- activity?.let {
103
- // Observe LiveData only on the main thread
104
- viewModel.getDownloadData().observe(it) { assets ->
105
- this.assets = assets ?: emptyList()
106
- // Emit event to React Native
107
- val eventMap = Arguments.createMap()
108
- val assetsList = Arguments.createArray()
109
-
110
- assets?.forEachIndexed { index , asset ->
111
- val assetMap = Arguments.createMap()
112
- assetMap.putString("id", index.toString())
113
- assetMap.putString("videoId", asset.id)
114
- assetMap.putString("title", asset.title)
115
- assetMap.putString("percentage", asset.video.percentageDownloaded.toString())
116
- assetMap.putString("status", asset.video.downloadState?.name ?: "Unknown")
117
- assetMap.putString("duration", asset.video.duration.toString())
118
-
119
- assetsList.pushMap(assetMap)
120
- }
121
-
122
- eventMap.putArray("assets", assetsList)
123
- reactApplicationContext
124
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
125
- .emit("onDownloadDataChanged", eventMap)
126
- }
127
- } ?: run {
128
- Log.e("FragmentModule", "Current activity is not a FragmentActivity")
129
- }
130
- }
131
- }
132
-
133
- @ReactMethod
134
- fun pauseDownload(videoId: String) {
135
- val asset = assets.first { it.id == videoId }
136
- viewModel.pauseDownload(asset)
137
- }
138
-
139
- @ReactMethod
140
- fun resumeDownload(videoId: String) {
141
- val asset = assets.first { it.id == videoId }
142
- viewModel.resumeDownload(asset)
143
- }
144
-
145
- @ReactMethod
146
- fun cancelDownload(videoId: String) {
147
- val asset = assets.first { it.id == videoId }
148
- viewModel.cancelDownload(asset)
149
- }
150
-
151
- @ReactMethod
152
- fun deleteDownload(videoId: String) {
153
- val asset = assets.first { it.id == videoId }
154
- viewModel.deleteDownload(asset)
155
- }
156
-
157
- }
158
-
159
- class DownloadListViewModel(context: Context): ViewModel() {
160
-
161
- private var tpStreamDownloadManager: TpStreamDownloadManager = TpStreamDownloadManager(context)
162
-
163
- fun getDownloadData(): LiveData<List<Asset>?> {
164
- return tpStreamDownloadManager.getAllDownloads()
165
- }
166
-
167
- fun pauseDownload(offlineAssetInfo: Asset) {
168
- tpStreamDownloadManager.pauseDownload(offlineAssetInfo)
169
- }
170
-
171
- fun resumeDownload(offlineAssetInfo: Asset) {
172
- tpStreamDownloadManager.resumeDownload(offlineAssetInfo)
173
- }
174
-
175
- fun cancelDownload(offlineAssetInfo: Asset) {
176
- tpStreamDownloadManager.cancelDownload(offlineAssetInfo)
177
- }
178
-
179
- fun deleteDownload(offlineAssetInfo: Asset) {
180
- tpStreamDownloadManager.deleteDownload(offlineAssetInfo)
181
- }
182
-
183
- companion object {
184
- fun init(fragmentActivity: FragmentActivity) : DownloadListViewModel {
185
- return ViewModelProvider(fragmentActivity, object : ViewModelProvider.Factory {
186
- override fun <T : ViewModel> create(modelClass: Class<T>): T {
187
- return DownloadListViewModel(fragmentActivity) as T
188
- }
189
- })[DownloadListViewModel::class.java]
190
- }
191
- }
192
- }
@@ -1,226 +0,0 @@
1
- package com.tpstreams
2
-
3
- import android.os.Bundle
4
- import android.util.Log
5
- import android.view.LayoutInflater
6
- import android.view.View
7
- import android.view.ViewGroup
8
- import android.widget.Toast
9
- import androidx.fragment.app.Fragment
10
- import com.tpstream.player.TPStreamPlayerListener
11
- import com.tpstream.player.TpInitParams
12
- import com.tpstream.player.TpStreamPlayer
13
- import com.tpstream.player.ui.InitializationListener
14
- import com.tpstream.player.ui.TPStreamPlayerView
15
- import com.tpstream.player.ui.TpStreamPlayerFragment
16
- import com.tpstream.player.constants.PlaybackError
17
- import com.tpstream.player.Tracks
18
- import com.tpstream.player.Timeline
19
- import com.tpstream.player.DeviceInfo
20
- import com.tpstreams.TpstreamsModule
21
-
22
- internal typealias onAccessTokenCallbase = (String) -> Unit
23
-
24
- class PlayerFragment : Fragment() {
25
-
26
- lateinit var player: TpStreamPlayer
27
- lateinit var playerView: TPStreamPlayerView
28
- lateinit var playerFragment: TpStreamPlayerFragment
29
- private var videoId :String = ""
30
- private var accessToken :String = ""
31
- private var enableDownloadSupport :Boolean = true
32
- private var setAutoPlay :Boolean = true
33
- private var startAt :Int = 0
34
- private var offlineLicenseExpireTime :Int = 60 * 60 * 24 * 15 //15 days
35
-
36
- private var accessTokenCallback : onAccessTokenCallbase? = null
37
-
38
- companion object {
39
- var instance: PlayerFragment? = null
40
- }
41
-
42
- override fun onCreate(savedInstanceState: Bundle?) {
43
- super.onCreate(savedInstanceState)
44
- val bundle = arguments
45
- if (bundle != null) {
46
- videoId = bundle.getString("VIDEO_ID") ?: ""
47
- accessToken = bundle.getString("ACCESS_TOKEN") ?: ""
48
- enableDownloadSupport = bundle.getBoolean("ENABLE_DOWNLOAD_SUPPORT", true)
49
- setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
50
- startAt = bundle.getInt("START_AT", 0)
51
- offlineLicenseExpireTime = bundle.getInt("OFFLINE_LICENSE_EXPIRE_TIME", offlineLicenseExpireTime)
52
-
53
- }
54
- }
55
-
56
- override fun onCreateView(
57
- inflater: LayoutInflater, container: ViewGroup?,
58
- savedInstanceState: Bundle?
59
- ): View? {
60
- return inflater.inflate(R.layout.fragment_player, container, false)
61
- }
62
-
63
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
64
- super.onViewCreated(view, savedInstanceState)
65
- instance = this
66
- playerFragment = childFragmentManager.findFragmentById(R.id.tpstream_player_fragment) as TpStreamPlayerFragment
67
- playerFragment.setOnInitializationListener(object: InitializationListener {
68
-
69
- override fun onInitializationSuccess(player: TpStreamPlayer) {
70
- this@PlayerFragment.player = player
71
- playerView = playerFragment.tpStreamPlayerView
72
- loadPLayer()
73
- addPlayerListener()
74
- }
75
- })
76
- }
77
-
78
- fun loadPLayer() {
79
- val parameters = TpInitParams.Builder()
80
- .setVideoId(videoId)
81
- .setAccessToken(accessToken)
82
- .enableDownloadSupport(enableDownloadSupport)
83
- .setAutoPlay(setAutoPlay)
84
- .startAt(startAt.toLong())
85
- .setOfflineLicenseExpireTime(offlineLicenseExpireTime)
86
- .build()
87
- requireActivity().runOnUiThread {
88
- player.load(parameters)
89
- }
90
- }
91
-
92
- private fun sendEvent(eventName: String, params: Any?) {
93
- TpstreamsModule.sendEvent(eventName, params)
94
- }
95
-
96
- private fun addPlayerListener(){
97
- player.setListener( object : TPStreamPlayerListener {
98
- override fun onPlaybackStateChanged(playbackState: Int) {
99
- sendEvent("onPlaybackStateChanged", playbackState)
100
- }
101
-
102
- override fun onAccessTokenExpired(videoId: String, callback: (String) -> Unit) {
103
- Log.d("ReactNativeJS", "onTokenExpired: $videoId")
104
- accessTokenCallback = callback
105
- sendEvent("onAccessTokenExpired", videoId)
106
- }
107
-
108
- override fun onMarkerCallback(timesInSeconds: Long) {
109
- requireActivity().runOnUiThread {
110
- Toast.makeText(requireContext(),"Time $timesInSeconds", Toast.LENGTH_SHORT).show()
111
- }
112
- sendEvent("onMarkerCallback", timesInSeconds)
113
- }
114
-
115
- override fun onDeviceInfoChanged(deviceInfo: DeviceInfo) {
116
- sendEvent("onDeviceInfoChanged", deviceInfo.toString())
117
- }
118
-
119
- override fun onFullScreenChanged(isFullScreen: Boolean) {
120
- sendEvent("onFullScreenChanged", isFullScreen)
121
- }
122
-
123
- override fun onIsLoadingChanged(isLoading: Boolean) {
124
- sendEvent("onIsLoadingChanged", isLoading)
125
- }
126
-
127
- override fun onIsPlayingChanged(isPlaying: Boolean) {
128
- sendEvent("onIsPlayingChanged", isPlaying)
129
- }
130
-
131
- override fun onPlayerError(playbackError: PlaybackError) {
132
- sendEvent("onPlayerError", playbackError.toString())
133
- }
134
-
135
- override fun onSeekBackIncrementChanged(incrementMs: Long) {
136
- sendEvent("onSeekBackIncrementChanged", incrementMs)
137
- }
138
-
139
- override fun onSeekForwardIncrementChanged(incrementMs: Long) {
140
- sendEvent("onSeekForwardIncrementChanged", incrementMs)
141
- }
142
-
143
- override fun onTimelineChanged(timeline: Timeline, reason: Int) {
144
- sendEvent("onTimelineChanged", null)
145
- }
146
-
147
- override fun onTracksChanged(tracks: Tracks) {
148
- sendEvent("onTracksChanged", tracks.toString())
149
- }
150
- })
151
- }
152
- // Core Player Controls
153
- fun play() {
154
- requireActivity().runOnUiThread {
155
- player.play()
156
- }
157
- }
158
-
159
- fun pause() {
160
- requireActivity().runOnUiThread {
161
- player.pause()
162
- }
163
- }
164
-
165
- fun seekTo(position: Long) {
166
- requireActivity().runOnUiThread {
167
- player.seekTo(position)
168
- }
169
- }
170
-
171
- fun release() {
172
- requireActivity().runOnUiThread {
173
- player.release()
174
- }
175
- }
176
-
177
- fun load(params: TpInitParams) {
178
- requireActivity().runOnUiThread {
179
- player.load(params)
180
- }
181
- }
182
-
183
- // Playback & State Management
184
- fun getCurrentTime(): Double = player.getCurrentTime().toDouble()
185
-
186
- fun getDuration(): Double = player.getDuration().toDouble()
187
-
188
- fun getBufferedTime(): Double = player.getBufferedTime().toDouble()
189
-
190
- fun getPlaybackState(): Int = player.getPlaybackState()
191
-
192
- fun getPlayWhenReady(): Boolean = player.getPlayWhenReady()
193
-
194
- fun setPlayWhenReady(playWhenReady: Boolean) {
195
- requireActivity().runOnUiThread {
196
- player.setPlayWhenReady(playWhenReady)
197
- }
198
- }
199
-
200
-
201
- // Speed & Volume
202
- fun getPlaybackSpeed(): Float = player.getPlayBackSpeed()
203
-
204
- fun setPlaybackSpeed(speed: Float) {
205
- requireActivity().runOnUiThread {
206
- player.setPlaybackSpeed(speed)
207
- }
208
- }
209
-
210
- fun setNewAccessToken(token: String) {
211
- accessTokenCallback?.invoke(token)
212
- accessTokenCallback = null
213
- }
214
-
215
- override fun onResume() {
216
- super.onResume()
217
- Log.d("ReactNativeJS", "onResume: ")
218
- }
219
-
220
- override fun onDestroy() {
221
- super.onDestroy()
222
- instance = null
223
- Log.d("ReactNativeJS", "onDestroy: ")
224
- }
225
-
226
- }
@@ -1,93 +0,0 @@
1
- package com.tpstreams
2
-
3
- import kotlinx.coroutines.*
4
- import android.content.Context
5
- import android.util.AttributeSet
6
- import android.widget.FrameLayout
7
- import androidx.fragment.app.FragmentActivity
8
- import com.facebook.react.bridge.ReactApplicationContext
9
- import com.facebook.react.uimanager.ThemedReactContext
10
-
11
- class TpStreamsPlayerView @JvmOverloads constructor(
12
- context: Context,
13
- attrs: AttributeSet? = null
14
- ) : FrameLayout(context, attrs), CoroutineScope {
15
-
16
- private var videoId: String? = null
17
- private var accessToken: String? = null
18
- private var enableDownload: Boolean = true
19
- private var autoPlay :Boolean = true
20
- private var startAt :Int = 0
21
- private var offlineLicenseExpireTime :Int = 60 * 60 * 24 * 15
22
- private var fragmentModule: FragmentModule? = null
23
-
24
- private val job = SupervisorJob()
25
- override val coroutineContext = Dispatchers.Main + job
26
- private var updateJob: Job? = null
27
-
28
- init {
29
- if (context is ThemedReactContext) {
30
- val reactContext = context.reactApplicationContext
31
- val activity = context.currentActivity as? FragmentActivity
32
-
33
- if (activity != null) {
34
- fragmentModule = FragmentModule(reactContext)
35
- }
36
- }
37
- }
38
-
39
- fun setVideoId(id: String) {
40
- videoId = id
41
- updateFragment()
42
- }
43
-
44
- fun setAccessToken(token: String) {
45
- accessToken = token
46
- updateFragment()
47
- }
48
-
49
- fun setEnableDownload(enableDownload: Boolean?) {
50
- this.enableDownload = enableDownload ?: true
51
- updateFragment()
52
- }
53
-
54
- fun setAutoPlay(autoPlay: Boolean?) {
55
- this.autoPlay = autoPlay ?: true
56
- updateFragment()
57
- }
58
-
59
- fun setStartTime(startAt: Int?) {
60
- this.startAt = startAt ?: 0
61
- updateFragment()
62
- }
63
-
64
- fun setOfflineLicenseExpireTime(offlineLicenseExpireTime: Int?) {
65
- this.offlineLicenseExpireTime = offlineLicenseExpireTime ?: 60 * 60 * 24 * 15
66
- updateFragment()
67
- }
68
-
69
- private fun updateFragment() {
70
- if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
71
- updateJob?.cancel()
72
- updateJob = launch {
73
- delay(50)
74
- fragmentModule?.closeCustomFragment()
75
- fragmentModule?.showCustomFragment(
76
- videoId!!,
77
- accessToken!!,
78
- enableDownload,
79
- autoPlay ?: true,
80
- startAt,
81
- offlineLicenseExpireTime,
82
- )
83
- }
84
- }
85
- }
86
-
87
- override fun onDetachedFromWindow() {
88
- super.onDetachedFromWindow()
89
- coroutineContext.cancel()
90
- fragmentModule?.closeCustomFragment()
91
- }
92
-
93
- }
@@ -1,49 +0,0 @@
1
- package com.tpstreams
2
-
3
- import com.facebook.react.uimanager.SimpleViewManager
4
- import com.facebook.react.uimanager.ThemedReactContext
5
- import com.facebook.react.uimanager.annotations.ReactProp
6
-
7
- class TpStreamsPlayerViewManager : SimpleViewManager<TpStreamsPlayerView>() {
8
-
9
- override fun getName() = "TpStreamsPlayerView"
10
-
11
- override fun createViewInstance(reactContext : ThemedReactContext) :TpStreamsPlayerView {
12
- return TpStreamsPlayerView(reactContext)
13
- }
14
-
15
- @ReactProp(name = "videoId")
16
- fun setVideoId(view: TpStreamsPlayerView, videoId: String?) {
17
- videoId?.let { view.setVideoId(it) }
18
- }
19
-
20
- @ReactProp(name = "accessToken")
21
- fun setAccessToken(view: TpStreamsPlayerView, accessToken: String?) {
22
- accessToken?.let { view.setAccessToken(it) }
23
- }
24
-
25
- @ReactProp(name = "enableDownload")
26
- fun setEnableDownload(view: TpStreamsPlayerView, enableDownload: Boolean?) {
27
- view.setEnableDownload(enableDownload)
28
- }
29
-
30
- @ReactProp(name = "autoPlay")
31
- fun setAutoPlay(view: TpStreamsPlayerView, autoPlay: Boolean?) {
32
- view.setAutoPlay(autoPlay)
33
- }
34
-
35
- @ReactProp(name = "startAt")
36
- fun setStartTime(view: TpStreamsPlayerView, startAt: Int?) {
37
- view.setStartTime(startAt ?: 0)
38
- }
39
-
40
- @ReactProp(name = "offlineLicenseExpireTime")
41
- fun setOfflineLicenseExpireTime(view: TpStreamsPlayerView, offlineLicenseExpireTime: Int?) {
42
- view.setOfflineLicenseExpireTime(offlineLicenseExpireTime ?: 60 * 60 * 24 * 15)
43
- }
44
- }
45
-
46
-
47
-
48
-
49
-