react-native-tpstreams 0.1.15 → 0.2.1

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 (76) 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 +162 -0
  9. package/android/src/main/java/com/tpstreams/TPStreamsRNPlayerViewManager.kt +97 -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/TPStreamsPlayer.js +159 -0
  14. package/lib/module/TPStreamsPlayer.js.map +1 -0
  15. package/lib/module/TPStreamsPlayerViewNativeComponent.ts +70 -0
  16. package/lib/module/index.js +10 -3
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/typescript/package.json +1 -0
  19. package/lib/typescript/src/TPStreamsPlayer.d.ts +32 -0
  20. package/lib/typescript/src/TPStreamsPlayer.d.ts.map +1 -0
  21. package/lib/typescript/src/TPStreamsPlayerViewNativeComponent.d.ts +54 -0
  22. package/lib/typescript/src/TPStreamsPlayerViewNativeComponent.d.ts.map +1 -0
  23. package/lib/typescript/src/index.d.ts +8 -0
  24. package/lib/typescript/src/index.d.ts.map +1 -0
  25. package/package.json +42 -76
  26. package/src/TPStreamsPlayer.tsx +225 -0
  27. package/src/TPStreamsPlayerViewNativeComponent.ts +70 -0
  28. package/src/index.tsx +12 -7
  29. package/android/generated/java/com/tpstreams/NativeTpstreamsSpec.java +0 -37
  30. package/android/generated/jni/CMakeLists.txt +0 -36
  31. package/android/generated/jni/RNTpstreamsSpec-generated.cpp +0 -32
  32. package/android/generated/jni/RNTpstreamsSpec.h +0 -31
  33. package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI-generated.cpp +0 -28
  34. package/android/generated/jni/react/renderer/components/RNTpstreamsSpec/RNTpstreamsSpecJSI.h +0 -71
  35. package/android/libs/extracted-aar/META-INF/com/android/build/gradle/aar-metadata.properties +0 -4
  36. package/android/src/main/AndroidManifestNew.xml +0 -2
  37. package/android/src/main/java/com/tpstreams/FragmentModule.kt +0 -225
  38. package/android/src/main/java/com/tpstreams/PlayerFragment.kt +0 -234
  39. package/android/src/main/java/com/tpstreams/TpStreamsPlayerView.kt +0 -102
  40. package/android/src/main/java/com/tpstreams/TpStreamsPlayerViewManager.kt +0 -55
  41. package/android/src/main/java/com/tpstreams/TpstreamsModule.kt +0 -168
  42. package/android/src/main/res/layout/fragment_player.xml +0 -29
  43. package/android/src/main/res/xml/network_security_config.xml +0 -8
  44. package/ios/Tpstreams.h +0 -6
  45. package/ios/Tpstreams.mm +0 -18
  46. package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec-generated.mm +0 -39
  47. package/ios/generated/RNTpstreamsSpec/RNTpstreamsSpec.h +0 -63
  48. package/ios/generated/RNTpstreamsSpecJSI-generated.cpp +0 -28
  49. package/ios/generated/RNTpstreamsSpecJSI.h +0 -71
  50. package/lib/commonjs/NativeTpstreams.js +0 -9
  51. package/lib/commonjs/NativeTpstreams.js.map +0 -1
  52. package/lib/commonjs/index.js +0 -10
  53. package/lib/commonjs/index.js.map +0 -1
  54. package/lib/commonjs/types.js +0 -2
  55. package/lib/commonjs/types.js.map +0 -1
  56. package/lib/module/NativeTpstreams.js +0 -5
  57. package/lib/module/NativeTpstreams.js.map +0 -1
  58. package/lib/module/types.js +0 -2
  59. package/lib/module/types.js.map +0 -1
  60. package/lib/typescript/commonjs/package.json +0 -1
  61. package/lib/typescript/commonjs/src/NativeTpstreams.d.ts +0 -7
  62. package/lib/typescript/commonjs/src/NativeTpstreams.d.ts.map +0 -1
  63. package/lib/typescript/commonjs/src/index.d.ts +0 -5
  64. package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
  65. package/lib/typescript/commonjs/src/types.d.ts +0 -11
  66. package/lib/typescript/commonjs/src/types.d.ts.map +0 -1
  67. package/lib/typescript/module/src/NativeTpstreams.d.ts +0 -7
  68. package/lib/typescript/module/src/NativeTpstreams.d.ts.map +0 -1
  69. package/lib/typescript/module/src/index.d.ts +0 -5
  70. package/lib/typescript/module/src/index.d.ts.map +0 -1
  71. package/lib/typescript/module/src/types.d.ts +0 -11
  72. package/lib/typescript/module/src/types.d.ts.map +0 -1
  73. package/react-native.config.js +0 -12
  74. package/src/NativeTpstreams.ts +0 -8
  75. package/src/types.ts +0 -10
  76. /package/lib/{typescript/module → module}/package.json +0 -0
@@ -0,0 +1,54 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="react-native/types/modules/Codegen" />
3
+ import type { ViewProps } from 'react-native';
4
+ import type { Double, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
5
+ import type { HostComponent } from 'react-native';
6
+ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
7
+ export interface ErrorEvent {
8
+ message: string;
9
+ code: Int32;
10
+ details?: string;
11
+ }
12
+ export interface NativeProps extends ViewProps {
13
+ videoId?: string;
14
+ accessToken?: string;
15
+ onCurrentPosition?: DirectEventHandler<{
16
+ position: Double;
17
+ }>;
18
+ onDuration?: DirectEventHandler<{
19
+ duration: Double;
20
+ }>;
21
+ onIsPlaying?: DirectEventHandler<{
22
+ isPlaying: boolean;
23
+ }>;
24
+ onPlaybackSpeed?: DirectEventHandler<{
25
+ speed: Float;
26
+ }>;
27
+ onPlayerStateChanged?: DirectEventHandler<{
28
+ playbackState: Int32;
29
+ }>;
30
+ onIsPlayingChanged?: DirectEventHandler<{
31
+ isPlaying: boolean;
32
+ }>;
33
+ onPlaybackSpeedChanged?: DirectEventHandler<{
34
+ speed: Double;
35
+ }>;
36
+ onIsLoadingChanged?: DirectEventHandler<{
37
+ isLoading: boolean;
38
+ }>;
39
+ onError?: DirectEventHandler<ErrorEvent>;
40
+ }
41
+ interface TPStreamsPlayerViewCommands {
42
+ play: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
43
+ pause: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
44
+ seekTo: (viewRef: React.ElementRef<HostComponent<NativeProps>>, positionMs: Double) => void;
45
+ setPlaybackSpeed: (viewRef: React.ElementRef<HostComponent<NativeProps>>, speed: Float) => void;
46
+ getCurrentPosition: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
47
+ getDuration: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
48
+ isPlaying: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
49
+ getPlaybackSpeed: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
50
+ }
51
+ export declare const Commands: TPStreamsPlayerViewCommands;
52
+ declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
53
+ export default _default;
54
+ //# sourceMappingURL=TPStreamsPlayerViewNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TPStreamsPlayerViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/TPStreamsPlayerViewNativeComponent.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EACV,MAAM,EACN,KAAK,EACL,KAAK,EACN,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAGpF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,UAAU,CAAC,EAAE,kBAAkB,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,WAAW,CAAC,EAAE,kBAAkB,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACzD,eAAe,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAGvD,oBAAoB,CAAC,EAAE,kBAAkB,CAAC;QAAE,aAAa,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IACpE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAChE,sBAAsB,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAChE,OAAO,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,UAAU,2BAA2B;IACnC,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IACtE,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IACvE,MAAM,EAAE,CACN,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,EACrD,UAAU,EAAE,MAAM,KACf,IAAI,CAAC;IACV,gBAAgB,EAAE,CAChB,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,EACrD,KAAK,EAAE,KAAK,KACT,IAAI,CAAC;IACV,kBAAkB,EAAE,CAClB,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAClD,IAAI,CAAC;IACV,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IAC7E,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3E,gBAAgB,EAAE,CAChB,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,KAClD,IAAI,CAAC;CACX;AAED,eAAO,MAAM,QAAQ,6BAWnB,CAAC;;AAEH,wBAA4E"}
@@ -0,0 +1,8 @@
1
+ export { default as TPStreamsPlayerView } from './TPStreamsPlayerViewNativeComponent';
2
+ export * from './TPStreamsPlayerViewNativeComponent';
3
+ export { default as TPStreamsPlayer } from './TPStreamsPlayer';
4
+ export type { TPStreamsPlayerRef } from './TPStreamsPlayer';
5
+ export declare const TPStreams: {
6
+ initialize: (organizationId: string) => void;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACtF,cAAc,sCAAsC,CAAC;AAErD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,eAAO,MAAM,SAAS;iCACS,MAAM,KAAG,IAAI;CAG3C,CAAC"}
package/package.json CHANGED
@@ -1,21 +1,16 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.1.15",
4
- "description": "Video Component for TPStreams",
5
- "source": "./src/index.tsx",
6
- "main": "./lib/commonjs/index.js",
7
- "module": "./lib/module/index.js",
3
+ "version": "0.2.1",
4
+ "description": "Video component for TPStreams",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
8
7
  "exports": {
9
8
  ".": {
10
- "import": {
11
- "types": "./lib/typescript/module/src/index.d.ts",
12
- "default": "./lib/module/index.js"
13
- },
14
- "require": {
15
- "types": "./lib/typescript/commonjs/src/index.d.ts",
16
- "default": "./lib/commonjs/index.js"
17
- }
18
- }
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
19
14
  },
20
15
  "files": [
21
16
  "src",
@@ -43,7 +38,7 @@
43
38
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
44
39
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
45
40
  "prepare": "bob build",
46
- "release": "release-it"
41
+ "release": "release-it --only-version"
47
42
  },
48
43
  "keywords": [
49
44
  "react-native",
@@ -52,41 +47,42 @@
52
47
  ],
53
48
  "repository": {
54
49
  "type": "git",
55
- "url": "git+https://github.com/testpress/react-native-player-sdk.git"
50
+ "url": "git+https://github.com/testpress/react-native-tpstreams.git"
56
51
  },
57
- "author": "Bharath <bharath@testpress.in> (https://github.com/bharathwaaj)",
52
+ "author": "Testpress <support@testpress.in> (https://github.com/testpress)",
58
53
  "license": "MIT",
59
54
  "bugs": {
60
- "url": "https://github.com/testpress/react-native-player-sdk/issues"
55
+ "url": "https://github.com/testpress/react-native-tpstreams/issues"
61
56
  },
62
- "homepage": "https://github.com/testpress/react-native-player-sdk#readme",
57
+ "homepage": "https://github.com/testpress/react-native-tpstreams#readme",
63
58
  "publishConfig": {
64
59
  "registry": "https://registry.npmjs.org/"
65
60
  },
66
61
  "devDependencies": {
67
- "@commitlint/config-conventional": "^17.0.2",
62
+ "@commitlint/config-conventional": "^19.6.0",
63
+ "@eslint/compat": "^1.2.7",
64
+ "@eslint/eslintrc": "^3.3.0",
65
+ "@eslint/js": "^9.22.0",
68
66
  "@evilmartians/lefthook": "^1.5.0",
69
- "@react-native-community/cli": "15.0.1",
70
- "@react-native/eslint-config": "^0.73.1",
67
+ "@react-native-community/cli": "15.0.0-alpha.2",
68
+ "@react-native/babel-preset": "0.79.2",
69
+ "@react-native/eslint-config": "^0.78.0",
71
70
  "@release-it/conventional-changelog": "^9.0.2",
72
71
  "@types/jest": "^29.5.5",
73
- "@types/react": "^18.2.44",
74
- "commitlint": "^17.0.2",
72
+ "@types/react": "^19.0.0",
73
+ "commitlint": "^19.6.1",
75
74
  "del-cli": "^5.1.0",
76
- "eslint": "^8.51.0",
77
- "eslint-config-prettier": "^9.0.0",
78
- "eslint-plugin-prettier": "^5.0.1",
75
+ "eslint": "^9.22.0",
76
+ "eslint-config-prettier": "^10.1.1",
77
+ "eslint-plugin-prettier": "^5.2.3",
79
78
  "jest": "^29.7.0",
80
79
  "prettier": "^3.0.3",
81
80
  "react": "19.0.0",
82
- "react-native": "0.78.0",
83
- "react-native-builder-bob": "^0.37.0",
81
+ "react-native": "0.79.2",
82
+ "react-native-builder-bob": "^0.40.11",
84
83
  "release-it": "^17.10.0",
85
84
  "turbo": "^1.10.7",
86
- "typescript": "^5.2.2"
87
- },
88
- "resolutions": {
89
- "@types/react": "^18.2.44"
85
+ "typescript": "5.4.5"
90
86
  },
91
87
  "peerDependencies": {
92
88
  "react": "*",
@@ -121,34 +117,12 @@
121
117
  },
122
118
  "plugins": {
123
119
  "@release-it/conventional-changelog": {
124
- "preset": "angular"
125
- }
126
- }
127
- },
128
- "eslintConfig": {
129
- "root": true,
130
- "extends": [
131
- "@react-native",
132
- "prettier"
133
- ],
134
- "rules": {
135
- "react/react-in-jsx-scope": "off",
136
- "prettier/prettier": [
137
- "error",
138
- {
139
- "quoteProps": "consistent",
140
- "singleQuote": true,
141
- "tabWidth": 2,
142
- "trailingComma": "es5",
143
- "useTabs": false
120
+ "preset": {
121
+ "name": "angular"
144
122
  }
145
- ]
123
+ }
146
124
  }
147
125
  },
148
- "eslintIgnore": [
149
- "node_modules/",
150
- "lib/"
151
- ],
152
126
  "prettier": {
153
127
  "quoteProps": "consistent",
154
128
  "singleQuote": true,
@@ -160,13 +134,6 @@
160
134
  "source": "src",
161
135
  "output": "lib",
162
136
  "targets": [
163
- "codegen",
164
- [
165
- "commonjs",
166
- {
167
- "esm": true
168
- }
169
- ],
170
137
  [
171
138
  "module",
172
139
  {
@@ -176,28 +143,27 @@
176
143
  [
177
144
  "typescript",
178
145
  {
179
- "project": "tsconfig.build.json",
180
- "esm": true
146
+ "project": "tsconfig.build.json"
181
147
  }
182
148
  ]
183
149
  ]
184
150
  },
185
151
  "codegenConfig": {
186
- "name": "RNTpstreamsSpec",
187
- "type": "modules",
152
+ "name": "TPStreamsPlayerViewSpec",
153
+ "type": "all",
188
154
  "jsSrcsDir": "src",
189
- "outputDir": {
190
- "ios": "ios/generated",
191
- "android": "android/generated"
192
- },
193
155
  "android": {
194
156
  "javaPackageName": "com.tpstreams"
195
157
  },
196
- "includesGeneratedCode": true
158
+ "ios": {
159
+ "componentProvider": {
160
+ "TPStreamsPlayerView": "TPStreamsPlayerView"
161
+ }
162
+ }
197
163
  },
198
164
  "create-react-native-library": {
199
- "type": "turbo-module",
200
165
  "languages": "kotlin-objc",
201
- "version": "0.48.3"
166
+ "type": "fabric-view",
167
+ "version": "0.50.3"
202
168
  }
203
169
  }
@@ -0,0 +1,225 @@
1
+ import { forwardRef, useImperativeHandle, useRef, useCallback } from 'react';
2
+ import TPStreamsPlayerView, {
3
+ Commands,
4
+ } from './TPStreamsPlayerViewNativeComponent';
5
+ import type {
6
+ NativeProps,
7
+ ErrorEvent,
8
+ } from './TPStreamsPlayerViewNativeComponent';
9
+ import type { ViewProps } from 'react-native';
10
+
11
+ // Create a unique ID for each instance to track promises
12
+ let nextInstanceId = 0;
13
+
14
+ // Type for tracking promises waiting to be resolved
15
+ type PromiseMap = {
16
+ [key: string]: {
17
+ resolve: (value: any) => void;
18
+ reject: (reason?: any) => void;
19
+ };
20
+ };
21
+
22
+ // Return type for player API methods
23
+ export interface TPStreamsPlayerRef {
24
+ play: () => void;
25
+ pause: () => void;
26
+ seekTo: (positionMs: number) => void;
27
+ setPlaybackSpeed: (speed: number) => void;
28
+ getCurrentPosition: () => Promise<number>;
29
+ getDuration: () => Promise<number>;
30
+ isPlaying: () => Promise<boolean>;
31
+ getPlaybackSpeed: () => Promise<number>;
32
+ }
33
+
34
+ // Prop types for the player component
35
+ export interface TPStreamsPlayerProps extends ViewProps {
36
+ videoId?: string;
37
+ accessToken?: string;
38
+ onPlayerStateChanged?: (state: number) => void;
39
+ onIsPlayingChanged?: (isPlaying: boolean) => void;
40
+ onPlaybackSpeedChanged?: (speed: number) => void;
41
+ onIsLoadingChanged?: (isLoading: boolean) => void;
42
+ onError?: (error: {
43
+ message: string;
44
+ code: number;
45
+ details?: string;
46
+ }) => void;
47
+ }
48
+
49
+ /**
50
+ * TPStreamsPlayer - React component wrapper for TPStreamsPlayerView
51
+ * Provides a simple imperative API for controlling the player
52
+ */
53
+ const TPStreamsPlayer = forwardRef<TPStreamsPlayerRef, TPStreamsPlayerProps>(
54
+ (props, ref) => {
55
+ const {
56
+ videoId,
57
+ accessToken,
58
+ style,
59
+ onPlayerStateChanged,
60
+ onIsPlayingChanged,
61
+ onPlaybackSpeedChanged,
62
+ onIsLoadingChanged,
63
+ onError,
64
+ ...restProps
65
+ } = props;
66
+
67
+ const nativeRef = useRef(null);
68
+ const instanceId = useRef<number>(nextInstanceId++);
69
+ const promiseMap = useRef<PromiseMap>({});
70
+
71
+ // Event handlers that resolve promises
72
+ const onCurrentPosition = useCallback((event: any) => {
73
+ const key = `position-${instanceId.current}`;
74
+ const handler = promiseMap.current[key];
75
+ if (handler) {
76
+ handler.resolve(event.nativeEvent.position);
77
+ delete promiseMap.current[key];
78
+ }
79
+ }, []);
80
+
81
+ const onDuration = useCallback((event: any) => {
82
+ const key = `duration-${instanceId.current}`;
83
+ const handler = promiseMap.current[key];
84
+ if (handler) {
85
+ handler.resolve(event.nativeEvent.duration);
86
+ delete promiseMap.current[key];
87
+ }
88
+ }, []);
89
+
90
+ const onIsPlaying = useCallback((event: any) => {
91
+ const key = `isPlaying-${instanceId.current}`;
92
+ const handler = promiseMap.current[key];
93
+ if (handler) {
94
+ handler.resolve(event.nativeEvent.isPlaying);
95
+ delete promiseMap.current[key];
96
+ }
97
+ }, []);
98
+
99
+ const onPlaybackSpeed = useCallback((event: any) => {
100
+ const key = `playbackSpeed-${instanceId.current}`;
101
+ const handler = promiseMap.current[key];
102
+ if (handler) {
103
+ handler.resolve(event.nativeEvent.speed);
104
+ delete promiseMap.current[key];
105
+ }
106
+ }, []);
107
+
108
+ // Player event handlers
109
+ const handlePlayerStateChanged = useCallback(
110
+ (event: any) => {
111
+ onPlayerStateChanged?.(event.nativeEvent.playbackState);
112
+ },
113
+ [onPlayerStateChanged]
114
+ );
115
+
116
+ const handleIsPlayingChanged = useCallback(
117
+ (event: any) => {
118
+ onIsPlayingChanged?.(event.nativeEvent.isPlaying);
119
+ },
120
+ [onIsPlayingChanged]
121
+ );
122
+
123
+ const handlePlaybackSpeedChanged = useCallback(
124
+ (event: any) => {
125
+ onPlaybackSpeedChanged?.(event.nativeEvent.speed);
126
+ },
127
+ [onPlaybackSpeedChanged]
128
+ );
129
+
130
+ const handleIsLoadingChanged = useCallback(
131
+ (event: any) => {
132
+ onIsLoadingChanged?.(event.nativeEvent.isLoading);
133
+ },
134
+ [onIsLoadingChanged]
135
+ );
136
+
137
+ const handleError = useCallback(
138
+ (event: { nativeEvent: ErrorEvent }) => {
139
+ const { message, code, details } = event.nativeEvent;
140
+
141
+ // Reject any pending promises with this error
142
+ Object.entries(promiseMap.current).forEach(([key, handler]) => {
143
+ handler.reject(
144
+ new Error(`${message}: ${details || 'Unknown error'}`)
145
+ );
146
+ delete promiseMap.current[key];
147
+ });
148
+
149
+ // Forward the error to the client if they provided an onError handler
150
+ onError?.({ message, code, details });
151
+ },
152
+ [onError]
153
+ );
154
+
155
+ // Helper to create promise-based API methods
156
+ const createPromiseMethod = useCallback(
157
+ (command: (ref: any) => void, eventKey: string) => {
158
+ return () =>
159
+ new Promise<any>((resolve, reject) => {
160
+ if (nativeRef.current) {
161
+ const key = `${eventKey}-${instanceId.current}`;
162
+ promiseMap.current[key] = { resolve, reject };
163
+ command(nativeRef.current);
164
+
165
+ // Set a timeout to reject the promise if it's not resolved in time
166
+ setTimeout(() => {
167
+ if (promiseMap.current[key]) {
168
+ reject(new Error(`Timeout getting ${eventKey}`));
169
+ delete promiseMap.current[key];
170
+ }
171
+ }, 5000);
172
+ } else {
173
+ reject(new Error('Player is not initialized'));
174
+ }
175
+ });
176
+ },
177
+ []
178
+ );
179
+
180
+ useImperativeHandle(
181
+ ref,
182
+ () => ({
183
+ play: () => nativeRef.current && Commands.play(nativeRef.current),
184
+ pause: () => nativeRef.current && Commands.pause(nativeRef.current),
185
+ seekTo: (positionMs: number) =>
186
+ nativeRef.current && Commands.seekTo(nativeRef.current, positionMs),
187
+ setPlaybackSpeed: (speed: number) =>
188
+ nativeRef.current &&
189
+ Commands.setPlaybackSpeed(nativeRef.current, speed),
190
+ getCurrentPosition: createPromiseMethod(
191
+ Commands.getCurrentPosition,
192
+ 'position'
193
+ ),
194
+ getDuration: createPromiseMethod(Commands.getDuration, 'duration'),
195
+ isPlaying: createPromiseMethod(Commands.isPlaying, 'isPlaying'),
196
+ getPlaybackSpeed: createPromiseMethod(
197
+ Commands.getPlaybackSpeed,
198
+ 'speed'
199
+ ),
200
+ }),
201
+ [createPromiseMethod]
202
+ );
203
+
204
+ // Create native props object with the correct types
205
+ const nativeProps: NativeProps = {
206
+ ...restProps,
207
+ videoId,
208
+ accessToken,
209
+ style,
210
+ onCurrentPosition,
211
+ onDuration,
212
+ onIsPlaying,
213
+ onPlaybackSpeed,
214
+ onPlayerStateChanged: handlePlayerStateChanged,
215
+ onIsPlayingChanged: handleIsPlayingChanged,
216
+ onPlaybackSpeedChanged: handlePlaybackSpeedChanged,
217
+ onIsLoadingChanged: handleIsLoadingChanged,
218
+ onError: handleError,
219
+ };
220
+
221
+ return <TPStreamsPlayerView {...nativeProps} ref={nativeRef} />;
222
+ }
223
+ );
224
+
225
+ export default TPStreamsPlayer;
@@ -0,0 +1,70 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ViewProps } from 'react-native';
3
+ import type {
4
+ Double,
5
+ Float,
6
+ Int32,
7
+ } from 'react-native/Libraries/Types/CodegenTypes';
8
+ import type { HostComponent } from 'react-native';
9
+ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
10
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
11
+
12
+ export interface ErrorEvent {
13
+ message: string;
14
+ code: Int32;
15
+ details?: string;
16
+ }
17
+
18
+ export interface NativeProps extends ViewProps {
19
+ videoId?: string;
20
+ accessToken?: string;
21
+
22
+ // Event props for receiving data from native methods
23
+ onCurrentPosition?: DirectEventHandler<{ position: Double }>;
24
+ onDuration?: DirectEventHandler<{ duration: Double }>;
25
+ onIsPlaying?: DirectEventHandler<{ isPlaying: boolean }>;
26
+ onPlaybackSpeed?: DirectEventHandler<{ speed: Float }>;
27
+
28
+ // Player event props
29
+ onPlayerStateChanged?: DirectEventHandler<{ playbackState: Int32 }>;
30
+ onIsPlayingChanged?: DirectEventHandler<{ isPlaying: boolean }>;
31
+ onPlaybackSpeedChanged?: DirectEventHandler<{ speed: Double }>;
32
+ onIsLoadingChanged?: DirectEventHandler<{ isLoading: boolean }>;
33
+ onError?: DirectEventHandler<ErrorEvent>;
34
+ }
35
+
36
+ interface TPStreamsPlayerViewCommands {
37
+ play: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
38
+ pause: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
39
+ seekTo: (
40
+ viewRef: React.ElementRef<HostComponent<NativeProps>>,
41
+ positionMs: Double
42
+ ) => void;
43
+ setPlaybackSpeed: (
44
+ viewRef: React.ElementRef<HostComponent<NativeProps>>,
45
+ speed: Float
46
+ ) => void;
47
+ getCurrentPosition: (
48
+ viewRef: React.ElementRef<HostComponent<NativeProps>>
49
+ ) => void;
50
+ getDuration: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
51
+ isPlaying: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
52
+ getPlaybackSpeed: (
53
+ viewRef: React.ElementRef<HostComponent<NativeProps>>
54
+ ) => void;
55
+ }
56
+
57
+ export const Commands = codegenNativeCommands<TPStreamsPlayerViewCommands>({
58
+ supportedCommands: [
59
+ 'play',
60
+ 'pause',
61
+ 'seekTo',
62
+ 'setPlaybackSpeed',
63
+ 'getCurrentPosition',
64
+ 'getDuration',
65
+ 'isPlaying',
66
+ 'getPlaybackSpeed',
67
+ ],
68
+ });
69
+
70
+ export default codegenNativeComponent<NativeProps>('TPStreamsRNPlayerView');
package/src/index.tsx CHANGED
@@ -1,9 +1,14 @@
1
- import type { TpStreamsPlayerProps } from './types';
2
- import { requireNativeComponent } from 'react-native';
1
+ import { NativeModules } from 'react-native';
2
+ export { default as TPStreamsPlayerView } from './TPStreamsPlayerViewNativeComponent';
3
+ export * from './TPStreamsPlayerViewNativeComponent';
3
4
 
4
- const TpStreamsPlayerView = requireNativeComponent<TpStreamsPlayerProps>(
5
- 'TpStreamsPlayerView'
6
- );
5
+ export { default as TPStreamsPlayer } from './TPStreamsPlayer';
6
+ export type { TPStreamsPlayerRef } from './TPStreamsPlayer';
7
7
 
8
- export default TpStreamsPlayerView;
9
- export type { TpStreamsPlayerProps };
8
+ const TPStreamsModule = NativeModules.TPStreams;
9
+
10
+ export const TPStreams = {
11
+ initialize: (organizationId: string): void => {
12
+ TPStreamsModule.initialize(organizationId);
13
+ },
14
+ };
@@ -1,37 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
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
- )