react-native-tpstreams 0.1.2 → 0.1.4

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.
@@ -35,7 +35,7 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
35
35
  }
36
36
 
37
37
  @ReactMethod
38
- fun showCustomFragment(videoId: String, accessToken: String) {
38
+ fun showCustomFragment(videoId: String, accessToken: String, enableDownload: Boolean, autoPlay: Boolean) {
39
39
  Log.e("FragmentModule", "showCustomFragment() called")
40
40
  // Ensure the currentActivity is a FragmentActivity
41
41
  val activity = currentActivity as? FragmentActivity
@@ -47,6 +47,8 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
47
47
  val bundle = Bundle()
48
48
  bundle.putString("VIDEO_ID", videoId)
49
49
  bundle.putString("ACCESS_TOKEN", accessToken)
50
+ bundle.putBoolean("ENABLE_DOWNLOAD_SUPPORT", enableDownload)
51
+ bundle.putBoolean("AUTO_PLAY", autoPlay)
50
52
  val fragment = PlayerFragment()
51
53
  fragment.setArguments(bundle)
52
54
 
@@ -21,6 +21,8 @@ class PlayerFragment : Fragment() {
21
21
  lateinit var playerFragment: TpStreamPlayerFragment
22
22
  private var videoId :String = ""
23
23
  private var accessToken :String = ""
24
+ private var enableDownloadSupport :Boolean = true
25
+ private var setAutoPlay :Boolean = true
24
26
 
25
27
  override fun onCreate(savedInstanceState: Bundle?) {
26
28
  super.onCreate(savedInstanceState)
@@ -28,6 +30,9 @@ class PlayerFragment : Fragment() {
28
30
  if (bundle != null) {
29
31
  videoId = bundle.getString("VIDEO_ID") ?: ""
30
32
  accessToken = bundle.getString("ACCESS_TOKEN") ?: ""
33
+ enableDownloadSupport = bundle.getBoolean("ENABLE_DOWNLOAD_SUPPORT", true)
34
+ setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
35
+
31
36
  }
32
37
  }
33
38
 
@@ -56,8 +61,8 @@ class PlayerFragment : Fragment() {
56
61
  val parameters = TpInitParams.Builder()
57
62
  .setVideoId(videoId)
58
63
  .setAccessToken(accessToken)
59
- .enableDownloadSupport(true)
60
- .setAutoPlay(true)
64
+ .enableDownloadSupport(enableDownloadSupport)
65
+ .setAutoPlay(setAutoPlay)
61
66
  .build()
62
67
  player.load(parameters)
63
68
  }
@@ -1,5 +1,6 @@
1
1
  package com.tpstreams
2
2
 
3
+ import kotlinx.coroutines.*
3
4
  import android.content.Context
4
5
  import android.util.AttributeSet
5
6
  import android.widget.FrameLayout
@@ -10,12 +11,18 @@ import com.facebook.react.uimanager.ThemedReactContext
10
11
  class TpStreamsPlayerView @JvmOverloads constructor(
11
12
  context: Context,
12
13
  attrs: AttributeSet? = null
13
- ) : FrameLayout(context, attrs) {
14
+ ) : FrameLayout(context, attrs), CoroutineScope {
14
15
 
15
16
  private var videoId: String? = null
16
17
  private var accessToken: String? = null
18
+ private var enableDownload: Boolean = true
19
+ private var autoPlay :Boolean = true
17
20
  private var fragmentModule: FragmentModule? = null
18
21
 
22
+ private val job = SupervisorJob()
23
+ override val coroutineContext = Dispatchers.Main + job
24
+ private var updateJob: Job? = null
25
+
19
26
  init {
20
27
  if (context is ThemedReactContext) {
21
28
  val reactContext = context.reactApplicationContext
@@ -37,15 +44,35 @@ class TpStreamsPlayerView @JvmOverloads constructor(
37
44
  updateFragment()
38
45
  }
39
46
 
47
+ fun setEnableDownload(enableDownload: Boolean?) {
48
+ this.enableDownload = enableDownload ?: true
49
+ updateFragment()
50
+ }
51
+
52
+ fun setAutoPlay(autoPlay: Boolean?) {
53
+ this.autoPlay = autoPlay ?: true
54
+ updateFragment()
55
+ }
56
+
40
57
  private fun updateFragment() {
41
58
  if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
42
- fragmentModule?.closeCustomFragment()
43
- fragmentModule?.showCustomFragment(videoId!!, accessToken!!)
59
+ updateJob?.cancel()
60
+ updateJob = launch {
61
+ delay(50)
62
+ fragmentModule?.closeCustomFragment()
63
+ fragmentModule?.showCustomFragment(
64
+ videoId!!,
65
+ accessToken!!,
66
+ enableDownload,
67
+ autoPlay ?: true
68
+ )
69
+ }
44
70
  }
45
71
  }
46
72
 
47
73
  override fun onDetachedFromWindow() {
48
74
  super.onDetachedFromWindow()
75
+ coroutineContext.cancel()
49
76
  fragmentModule?.closeCustomFragment()
50
77
  }
51
78
 
@@ -21,6 +21,17 @@ class TpStreamsPlayerViewManager : SimpleViewManager<TpStreamsPlayerView>() {
21
21
  fun setAccessToken(view: TpStreamsPlayerView, accessToken: String?) {
22
22
  accessToken?.let { view.setAccessToken(it) }
23
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
+
24
35
  }
25
36
 
26
37
 
@@ -1,6 +1,8 @@
1
1
  export type TpStreamsPlayerProps = {
2
2
  videoId: string;
3
3
  accessToken: string;
4
+ enableDownload?: boolean;
5
+ autoPlay?: boolean;
4
6
  style?: import('react-native').ViewStyle;
5
7
  };
6
8
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export type TpStreamsPlayerProps = {
2
2
  videoId: string;
3
3
  accessToken: string;
4
+ enableDownload?: boolean;
5
+ autoPlay?: boolean;
4
6
  style?: import('react-native').ViewStyle;
5
7
  };
6
8
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Video Component for TPStreams",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
package/src/types.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export type TpStreamsPlayerProps = {
2
2
  videoId: string;
3
3
  accessToken: string;
4
+ enableDownload?: boolean;
5
+ autoPlay?: boolean;
4
6
  style?: import('react-native').ViewStyle;
5
7
  };