amazon-ivs-react-native-player 1.0.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 (168) hide show
  1. package/LICENSE +175 -0
  2. package/README.md +56 -0
  3. package/amazon-ivs-react-native-player.podspec +31 -0
  4. package/android/.project +17 -0
  5. package/android/.settings/org.eclipse.buildship.core.prefs +13 -0
  6. package/android/build/.transforms/1f4dbdc38179d2776be8ed38c6bd3b8d/classes/classes.dex +0 -0
  7. package/android/build/.transforms/1f4dbdc38179d2776be8ed38c6bd3b8d.bin +1 -0
  8. package/android/build/generated/source/buildConfig/debug/com/amazonaws/ivs/reactnative/player/BuildConfig.java +10 -0
  9. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +20 -0
  10. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +16 -0
  11. package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +2 -0
  12. package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +1 -0
  13. package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
  14. package/android/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
  15. package/android/build/intermediates/compile_symbol_list/debug/R.txt +1864 -0
  16. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  17. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  18. package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
  19. package/android/build/intermediates/incremental/packageDebugResources/compile-file-map.properties +1 -0
  20. package/android/build/intermediates/incremental/packageDebugResources/merger.xml +2 -0
  21. package/android/build/intermediates/javac/debug/classes/com/amazonaws/ivs/reactnative/player/BuildConfig.class +0 -0
  22. package/android/build/intermediates/library_java_res/debug/res.jar +0 -0
  23. package/android/build/intermediates/library_manifest/debug/AndroidManifest.xml +20 -0
  24. package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +2 -0
  25. package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +28 -0
  26. package/android/build/intermediates/navigation_json/debug/navigation.json +1 -0
  27. package/android/build/intermediates/packaged_manifests/debug/output-metadata.json +16 -0
  28. package/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
  29. package/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +1384 -0
  30. package/android/build/kotlin/compileDebugKotlin/build-history.bin +0 -0
  31. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab +0 -0
  32. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  33. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  34. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab.len +0 -0
  35. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  36. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab_i +0 -0
  37. package/android/build/kotlin/compileDebugKotlin/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
  38. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  39. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  40. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  41. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  42. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  43. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  44. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
  45. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  46. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  47. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  48. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  49. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  50. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  51. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
  52. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab +0 -0
  53. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  54. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  55. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  56. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  57. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  58. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
  59. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  60. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  61. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  62. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  63. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  64. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  65. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
  66. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  67. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  68. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  69. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  70. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  71. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  72. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
  73. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  74. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  75. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  76. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  77. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  78. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  79. package/android/build/kotlin/compileDebugKotlin/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
  80. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/counters.tab +2 -0
  81. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab +0 -0
  82. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  83. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  84. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab.len +0 -0
  85. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  86. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab_i +0 -0
  87. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
  88. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab +0 -0
  89. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  90. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  91. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab.len +0 -0
  92. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  93. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab_i +0 -0
  94. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
  95. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab +0 -0
  96. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab.keystream +0 -0
  97. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  98. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab.len +0 -0
  99. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab.values.at +0 -0
  100. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab_i +0 -0
  101. package/android/build/kotlin/compileDebugKotlin/caches-jvm/lookups/lookups.tab_i.len +0 -0
  102. package/android/build/kotlin/compileDebugKotlin/last-build.bin +0 -0
  103. package/android/build/outputs/logs/manifest-merger-debug-report.txt +52 -0
  104. package/android/build/tmp/compileDebugJavaWithJavac/source-classes-mapping.txt +2 -0
  105. package/android/build/tmp/kotlin-classes/debug/META-INF/amazonivsreactnativeplayer_debug.kotlin_module +0 -0
  106. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsPackage.class +0 -0
  107. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView$$special$$inlined$timerTask$1.class +0 -0
  108. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView$1.class +0 -0
  109. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView$Events.class +0 -0
  110. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView$WhenMappings.class +0 -0
  111. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView$mLayoutRunnable$1.class +0 -0
  112. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsView.class +0 -0
  113. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsViewManager$Commands.class +0 -0
  114. package/android/build/tmp/kotlin-classes/debug/com/amazonaws/ivs/reactnative/player/AmazonIvsViewManager.class +0 -0
  115. package/android/build.gradle +138 -0
  116. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  117. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  118. package/android/gradle.properties +5 -0
  119. package/android/gradlew +183 -0
  120. package/android/gradlew.bat +84 -0
  121. package/android/src/main/AndroidManifest.xml +11 -0
  122. package/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsPackage.kt +16 -0
  123. package/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsView.kt +410 -0
  124. package/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsViewManager.kt +115 -0
  125. package/ios/AmazonIvs-Bridging-Header.h +3 -0
  126. package/ios/AmazonIvs.xcodeproj/project.pbxproj +283 -0
  127. package/ios/AmazonIvsManager.m +35 -0
  128. package/ios/AmazonIvsManager.swift +29 -0
  129. package/ios/AmazonIvsView.swift +414 -0
  130. package/lib/commonjs/IVSPlayer.js +245 -0
  131. package/lib/commonjs/IVSPlayer.js.flow +53 -0
  132. package/lib/commonjs/IVSPlayer.js.map +1 -0
  133. package/lib/commonjs/enums.js +27 -0
  134. package/lib/commonjs/enums.js.flow +21 -0
  135. package/lib/commonjs/enums.js.map +1 -0
  136. package/lib/commonjs/index.js +43 -0
  137. package/lib/commonjs/index.js.flow +11 -0
  138. package/lib/commonjs/index.js.map +1 -0
  139. package/lib/commonjs/types.js +2 -0
  140. package/lib/commonjs/types.js.flow +44 -0
  141. package/lib/commonjs/types.js.map +1 -0
  142. package/lib/module/IVSPlayer.js +229 -0
  143. package/lib/module/IVSPlayer.js.flow +53 -0
  144. package/lib/module/IVSPlayer.js.map +1 -0
  145. package/lib/module/enums.js +19 -0
  146. package/lib/module/enums.js.flow +21 -0
  147. package/lib/module/enums.js.map +1 -0
  148. package/lib/module/index.js +5 -0
  149. package/lib/module/index.js.flow +11 -0
  150. package/lib/module/index.js.map +1 -0
  151. package/lib/module/types.js +2 -0
  152. package/lib/module/types.js.flow +44 -0
  153. package/lib/module/types.js.map +1 -0
  154. package/lib/typescript/IVSPlayer.d.ts +41 -0
  155. package/lib/typescript/__tests__/index.test.d.ts +1 -0
  156. package/lib/typescript/enums.d.ts +13 -0
  157. package/lib/typescript/index.d.ts +4 -0
  158. package/lib/typescript/types.d.ts +37 -0
  159. package/package.json +149 -0
  160. package/src/IVSPlayer.js.flow +53 -0
  161. package/src/IVSPlayer.tsx +366 -0
  162. package/src/__tests__/index.test.tsx +226 -0
  163. package/src/enums.js.flow +21 -0
  164. package/src/enums.ts +14 -0
  165. package/src/index.js.flow +11 -0
  166. package/src/index.ts +5 -0
  167. package/src/types.js.flow +44 -0
  168. package/src/types.ts +42 -0
@@ -0,0 +1,414 @@
1
+ import Foundation
2
+ import UIKit
3
+ import AmazonIVSPlayer
4
+
5
+ @objc(AmazonIvsView)
6
+ class AmazonIvsView: UIView, IVSPlayer.Delegate {
7
+ @objc var onSeek: RCTDirectEventBlock?
8
+ @objc var onData: RCTDirectEventBlock?
9
+ @objc var onVideoStatistics: RCTDirectEventBlock?
10
+ @objc var onPlayerStateChange: RCTDirectEventBlock?
11
+ @objc var onDurationChange: RCTDirectEventBlock?
12
+ @objc var onQualityChange: RCTDirectEventBlock?
13
+ @objc var onRebuffering: RCTDirectEventBlock?
14
+ @objc var onLoadStart: RCTDirectEventBlock?
15
+ @objc var onLoad: RCTDirectEventBlock?
16
+ @objc var onTextCue: RCTDirectEventBlock?
17
+ @objc var onTextMetadataCue: RCTDirectEventBlock?
18
+ @objc var onLiveLatencyChange: RCTDirectEventBlock?
19
+ @objc var onProgress: RCTDirectEventBlock?
20
+ @objc var onTimePoint: RCTDirectEventBlock?
21
+
22
+ @objc var onError: RCTDirectEventBlock?
23
+
24
+ private let player = IVSPlayer()
25
+ private let playerView = IVSPlayerView()
26
+ private var finishedLoading: Bool = false;
27
+
28
+ private var progressObserverToken: Any?
29
+ private var playerObserverToken: Any?
30
+ private var timePointObserver: Any?
31
+ private var oldQualities: [IVSQuality] = [];
32
+ private var lastLiveLatency: Double?;
33
+ private var lastBitrate: Int?;
34
+ private var lastDuration: CMTime?;
35
+ private var lastFramesDropped: Int?;
36
+ private var lastFramesDecoded: Int?;
37
+
38
+ override init(frame: CGRect) {
39
+ self.muted = player.muted
40
+ self.liveLowLatency = player.isLiveLowLatency
41
+ self.autoQualityMode = player.autoQualityMode
42
+ self.playbackRate = Double(player.playbackRate)
43
+ self.logLevel = NSNumber(value: player.logLevel.rawValue)
44
+ self.progressInterval = 1
45
+ self.volume = Double(player.volume)
46
+ self.breakpoints = []
47
+ self.initialBufferDuration = 1
48
+
49
+ super.init(frame: frame)
50
+
51
+ self.addSubview(self.playerView)
52
+ self.playerView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
53
+ self.addProgressObserver()
54
+ self.addPlayerObserver()
55
+ self.addTimePointObserver()
56
+ self.addApplicationLifecycleObservers()
57
+
58
+ player.delegate = self
59
+ self.playerView.player = player
60
+ }
61
+
62
+ deinit {
63
+ self.removeProgressObserver()
64
+ self.removePlayerObserver()
65
+ self.removeTimePointObserver()
66
+ self.removeApplicationLifecycleObservers()
67
+ }
68
+
69
+ func load(urlString: String) {
70
+ finishedLoading = false
71
+ let url = URL(string: urlString)
72
+
73
+ onLoadStart?(["": NSNull()])
74
+ player.load(url)
75
+ }
76
+
77
+ @objc var progressInterval: NSNumber {
78
+ // TODO: Figure out why updatating observer does not work and results in multiple calls per second
79
+ didSet {
80
+ self.removeProgressObserver()
81
+ self.addProgressObserver()
82
+ }
83
+ }
84
+
85
+ @objc var muted: Bool {
86
+ didSet {
87
+ player.muted = muted
88
+ }
89
+ }
90
+
91
+ @objc var playbackRate: Double {
92
+ didSet {
93
+ player.playbackRate = Float(playbackRate)
94
+ }
95
+ }
96
+
97
+ @objc var liveLowLatency: Bool {
98
+ didSet {
99
+ player.setLiveLowLatencyEnabled(liveLowLatency)
100
+ }
101
+ }
102
+
103
+ @objc var quality: NSDictionary? {
104
+ didSet {
105
+ let newQuality = findQuality(quality: quality)
106
+ player.quality = newQuality
107
+ }
108
+ }
109
+
110
+ @objc var autoQualityMode: Bool {
111
+ didSet {
112
+ player.autoQualityMode = autoQualityMode
113
+ }
114
+ }
115
+
116
+ @objc var autoMaxQuality: NSDictionary? {
117
+ didSet {
118
+ let quality = findQuality(quality: autoMaxQuality)
119
+ player.setAutoMaxQuality(quality)
120
+ }
121
+ }
122
+
123
+ @objc var initialBufferDuration: Double {
124
+ didSet {
125
+ let parsedTime = CMTimeMakeWithSeconds(initialBufferDuration, preferredTimescale: 10)
126
+ player.setInitialBufferDuration(parsedTime)
127
+ }
128
+ }
129
+
130
+ private func findQuality(quality: NSDictionary?) -> IVSQuality? {
131
+ let quality = player.qualities.first(where: {
132
+ $0.name == quality?["name"] as? String &&
133
+ $0.codecs == quality?["codecs"] as? String &&
134
+ $0.bitrate == quality?["bitrate"] as? Int &&
135
+ $0.framerate == quality?["framerate"] as? Float &&
136
+ $0.width == quality?["width"] as? Int &&
137
+ $0.height == quality?["height"] as? Int
138
+ })
139
+
140
+ return quality
141
+ }
142
+
143
+ private func getDuration(_ duration: CMTime) -> NSNumber? {
144
+ let value: NSNumber?
145
+ if duration.isNumeric {
146
+ value = NSNumber(value: duration.seconds);
147
+ } else {
148
+ value = 0
149
+ }
150
+ return value
151
+ }
152
+
153
+ @objc var streamUrl: String? {
154
+ didSet {
155
+ if let url = streamUrl, !streamUrl!.isEmpty {
156
+ self.load(urlString: url)
157
+ }
158
+ }
159
+ }
160
+
161
+ @objc var volume: Double {
162
+ didSet {
163
+ player.volume = Float(volume)
164
+ }
165
+ }
166
+
167
+ @objc var logLevel: NSNumber {
168
+ didSet {
169
+ switch logLevel {
170
+ case 0:
171
+ player.logLevel = IVSPlayer.LogLevel.debug
172
+ case 1:
173
+ player.logLevel = IVSPlayer.LogLevel.info
174
+ case 2:
175
+ player.logLevel = IVSPlayer.LogLevel.warning
176
+ case 3:
177
+ player.logLevel = IVSPlayer.LogLevel.error
178
+ default:
179
+ break
180
+ }
181
+ }
182
+ }
183
+
184
+ @objc var breakpoints: NSArray {
185
+ didSet {
186
+ self.removeTimePointObserver()
187
+ self.addTimePointObserver()
188
+ }
189
+ }
190
+
191
+ @objc func play() {
192
+ player.play()
193
+ }
194
+
195
+ @objc func pause() {
196
+ player.pause()
197
+ }
198
+
199
+ @objc func seek(position: Double) {
200
+ let parsedTime = CMTimeMakeWithSeconds(position, preferredTimescale: 1000000)
201
+ player.seek(to: parsedTime)
202
+ }
203
+
204
+ required init?(coder: NSCoder) {
205
+ fatalError("init(coder:) has not been implemented")
206
+ }
207
+
208
+ func addPlayerObserver() {
209
+ playerObserverToken = player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: CMTimeScale(NSEC_PER_SEC)), queue: .main) {
210
+ [weak self] time in
211
+ if self?.lastLiveLatency != self?.player.liveLatency.seconds {
212
+ if let liveLatency = self?.player.liveLatency.seconds {
213
+ let parsedValue = 1000*liveLatency
214
+ self?.onLiveLatencyChange?(["liveLatency": parsedValue])
215
+ } else {
216
+ self?.onLiveLatencyChange?(["liveLatency": NSNull()])
217
+ }
218
+
219
+ self?.lastLiveLatency = self?.player.liveLatency.seconds
220
+ }
221
+
222
+ if
223
+ self?.lastBitrate != self?.player.videoBitrate ||
224
+ self?.lastDuration != self?.player.duration ||
225
+ self?.lastFramesDecoded != self?.player.videoFramesDecoded ||
226
+ self?.lastFramesDropped != self?.player.videoFramesDropped ||
227
+ self?.onVideoStatistics != nil {
228
+ let videoData: [String: Any] = [
229
+ "duration": self?.getDuration(self!.player.duration) ?? NSNull(),
230
+ "bitrate": self?.player.videoBitrate ?? NSNull(),
231
+ "framesDropped": self?.player.videoFramesDropped ?? NSNull(),
232
+ "framesDecoded": self?.player.videoFramesDecoded ?? NSNull()
233
+ ]
234
+
235
+ self?.onVideoStatistics?(["videoData": videoData])
236
+
237
+ self?.lastBitrate = self?.player.videoBitrate
238
+ self?.lastDuration = self?.player.duration
239
+ self?.lastFramesDropped = self?.player.videoFramesDropped
240
+ self?.lastFramesDecoded = self?.player.videoFramesDecoded
241
+ }
242
+ }
243
+ }
244
+
245
+ private var didPauseOnBackground = false
246
+
247
+ @objc private func applicationDidEnterBackground(notification: Notification) {
248
+ if player.state == .playing || player.state == .buffering {
249
+ didPauseOnBackground = true
250
+ pause()
251
+ } else {
252
+ didPauseOnBackground = false
253
+ }
254
+ }
255
+
256
+ @objc private func applicationDidBecomeActive(notification: Notification) {
257
+ if didPauseOnBackground && player.error == nil {
258
+ play()
259
+ didPauseOnBackground = false
260
+ }
261
+ }
262
+
263
+ private func addApplicationLifecycleObservers() {
264
+ NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(notification:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
265
+ NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(notification:)), name: UIApplication.didBecomeActiveNotification, object: nil)
266
+ }
267
+
268
+ private func removeApplicationLifecycleObservers() {
269
+ NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
270
+ NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil)
271
+ }
272
+
273
+ private func mapPlayerState(state: IVSPlayer.State) -> String {
274
+ switch state {
275
+ case IVSPlayer.State.playing: return "Playing"
276
+ case IVSPlayer.State.buffering: return "Buffering"
277
+ case IVSPlayer.State.ready: return "Ready"
278
+ case IVSPlayer.State.idle: return "Idle"
279
+ case IVSPlayer.State.ended: return "Ended"
280
+ }
281
+ }
282
+
283
+ func addProgressObserver() {
284
+ progressObserverToken = player.addPeriodicTimeObserver(forInterval: CMTime(seconds: Double(truncating: progressInterval), preferredTimescale: CMTimeScale(NSEC_PER_SEC)), queue: .main) {
285
+ [weak self] time in
286
+ self?.onProgress?(["position": (self?.player.position.seconds ?? nil) as Any])
287
+ }
288
+ }
289
+
290
+ func addTimePointObserver() {
291
+ timePointObserver = player.addBoundaryTimeObserver(forTimes: breakpoints as! [NSNumber], queue: .main) {
292
+ [weak self] in
293
+ self?.onTimePoint?(["position": (self?.player.position.seconds ?? nil) as Any])
294
+
295
+ }
296
+ }
297
+
298
+ func removePlayerObserver() {
299
+ if let token = playerObserverToken {
300
+ player.removeTimeObserver(token)
301
+ self.playerObserverToken = nil
302
+ }
303
+ }
304
+
305
+ func removeProgressObserver() {
306
+ if let token = progressObserverToken {
307
+ player.removeTimeObserver(token)
308
+ self.progressObserverToken = nil
309
+ }
310
+ }
311
+
312
+ func removeTimePointObserver() {
313
+ if let token = timePointObserver {
314
+ player.removeTimeObserver(token)
315
+ self.timePointObserver = nil
316
+ }
317
+ }
318
+
319
+ func player(_ player: IVSPlayer, didSeekTo time: CMTime) {
320
+ onSeek?(["position": CMTimeGetSeconds(time)])
321
+ }
322
+
323
+ func player(_ player: IVSPlayer, didChangeState state: IVSPlayer.State) {
324
+ onPlayerStateChange?(["state": mapPlayerState(state: state)])
325
+
326
+ if state == IVSPlayer.State.playing, finishedLoading == false {
327
+ let duration = getDuration(player.duration)
328
+ onLoad?(["duration": duration ?? NSNull()])
329
+ finishedLoading = true
330
+ }
331
+
332
+ if state == IVSPlayer.State.ready {
333
+ if player.qualities != oldQualities {
334
+ let qualities: NSMutableArray = []
335
+ for quality in player.qualities {
336
+ let qualityData: [String: Any] = [
337
+ "name": quality.name,
338
+ "codecs": quality.codecs,
339
+ "bitrate": quality.bitrate,
340
+ "framerate": quality.framerate,
341
+ "width": quality.width,
342
+ "height": quality.height
343
+ ]
344
+
345
+ qualities.add(qualityData)
346
+ }
347
+
348
+ onData?(["playerData": [
349
+ "qualities": qualities,
350
+ "version": player.version,
351
+ "sessionId": player.sessionId
352
+ ]])
353
+ }
354
+
355
+ oldQualities = player.qualities
356
+ }
357
+ }
358
+
359
+ func player(_ player: IVSPlayer, didChangeDuration duration: CMTime) {
360
+ let parsedDuration = getDuration(duration)
361
+ onDurationChange?(["duration": parsedDuration ?? NSNull()])
362
+ }
363
+
364
+ func player(_ player: IVSPlayer, didChangeQuality quality: IVSQuality?) {
365
+ if quality == nil {
366
+ onQualityChange?(["quality": NSNull()])
367
+ } else {
368
+ let qualityData: [String: Any] = [
369
+ "name": quality?.name ?? "",
370
+ "codecs": quality?.codecs ?? "",
371
+ "bitrate": quality?.bitrate ?? 0,
372
+ "framerate": quality?.framerate ?? 0,
373
+ "width": quality?.width ?? 0,
374
+ "height": quality?.height ?? 0
375
+ ]
376
+
377
+ onQualityChange?(["quality": qualityData])
378
+ }
379
+ }
380
+
381
+ func player(_ player: IVSPlayer, didOutputCue cue: IVSCue) {
382
+ if let cue = cue as? IVSTextCue {
383
+ let textCue: [String: Any] = [
384
+ "type": cue.type.rawValue,
385
+ "line": cue.line,
386
+ "size": cue.size,
387
+ "position": cue.position,
388
+ "text": cue.text,
389
+ "textAlignment": cue.textAlignment
390
+ ]
391
+
392
+ onTextCue?(["textCue": textCue])
393
+ }
394
+
395
+ if let cue = cue as? IVSTextMetadataCue {
396
+ let textMetadataCue = [
397
+ "type": cue.type.rawValue,
398
+ "text": cue.text,
399
+ "textDescription": cue.textDescription
400
+
401
+ ]
402
+
403
+ onTextMetadataCue?(["textMetadataCue": textMetadataCue])
404
+ }
405
+ }
406
+
407
+ func playerWillRebuffer(_ player: IVSPlayer) {
408
+ onRebuffering?(["": NSNull()])
409
+ }
410
+
411
+ func player(_ player: IVSPlayer, didFailWithError error: Error) {
412
+ onError?(["error": error.localizedDescription])
413
+ }
414
+ }
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ const VIEW_NAME = 'AmazonIvs';
17
+ const IVSPlayer = (0, _reactNative.requireNativeComponent)(VIEW_NAME);
18
+
19
+ function parseDuration(duration) {
20
+ if (duration == null) {
21
+ return duration;
22
+ }
23
+
24
+ return duration > 0 ? duration : Infinity;
25
+ }
26
+
27
+ const IVSPlayerContainer = /*#__PURE__*/_react.default.forwardRef(({
28
+ style,
29
+ streamUrl,
30
+ paused,
31
+ muted,
32
+ autoplay = true,
33
+ liveLowLatency,
34
+ playbackRate,
35
+ logLevel,
36
+ progressInterval,
37
+ volume,
38
+ quality,
39
+ autoMaxQuality,
40
+ autoQualityMode,
41
+ breakpoints = [],
42
+ maxBitrate,
43
+ initialBufferDuration,
44
+ onSeek,
45
+ onData,
46
+ onVideoStatistics,
47
+ onPlayerStateChange,
48
+ onDurationChange,
49
+ onQualityChange,
50
+ onRebuffering,
51
+ onLoadStart,
52
+ onLoad,
53
+ onLiveLatencyChange,
54
+ onTextCue,
55
+ onTextMetadataCue,
56
+ onProgress,
57
+ onError,
58
+ onTimePoint,
59
+ children
60
+ }, ref) => {
61
+ const mediaPlayerRef = (0, _react.useRef)(null);
62
+ const initialized = (0, _react.useRef)(false);
63
+ const play = (0, _react.useCallback)(() => {
64
+ _reactNative.UIManager.dispatchViewManagerCommand((0, _reactNative.findNodeHandle)(mediaPlayerRef.current), _reactNative.UIManager.getViewManagerConfig(VIEW_NAME).Commands.play, []);
65
+ }, []);
66
+ const pause = (0, _react.useCallback)(() => {
67
+ _reactNative.UIManager.dispatchViewManagerCommand((0, _reactNative.findNodeHandle)(mediaPlayerRef.current), _reactNative.UIManager.getViewManagerConfig(VIEW_NAME).Commands.pause, []);
68
+ }, []);
69
+ const seekTo = (0, _react.useCallback)(value => {
70
+ _reactNative.UIManager.dispatchViewManagerCommand((0, _reactNative.findNodeHandle)(mediaPlayerRef.current), _reactNative.UIManager.getViewManagerConfig(VIEW_NAME).Commands.seekTo, [value]);
71
+ }, []);
72
+ (0, _react.useEffect)(() => {
73
+ if (initialized.current || autoplay) {
74
+ if (paused) {
75
+ pause();
76
+ } else {
77
+ play();
78
+ }
79
+ }
80
+
81
+ initialized.current = true;
82
+ }, [pause, paused, play, autoplay]);
83
+ (0, _react.useImperativeHandle)(ref, () => ({
84
+ play,
85
+ pause,
86
+ seekTo
87
+ }), [play, pause, seekTo]);
88
+
89
+ const onSeekHandler = event => {
90
+ const {
91
+ position
92
+ } = event.nativeEvent;
93
+ onSeek === null || onSeek === void 0 ? void 0 : onSeek(position);
94
+ };
95
+
96
+ const onPlayerStateChangeHandler = event => {
97
+ const {
98
+ state
99
+ } = event.nativeEvent;
100
+ onPlayerStateChange === null || onPlayerStateChange === void 0 ? void 0 : onPlayerStateChange(state);
101
+ };
102
+
103
+ const onDurationChangeHandler = event => {
104
+ const {
105
+ duration
106
+ } = event.nativeEvent;
107
+ onDurationChange === null || onDurationChange === void 0 ? void 0 : onDurationChange(parseDuration(duration));
108
+ };
109
+
110
+ const onQualityChangeHandler = event => {
111
+ const {
112
+ quality: newQuality
113
+ } = event.nativeEvent;
114
+ onQualityChange === null || onQualityChange === void 0 ? void 0 : onQualityChange(newQuality);
115
+ };
116
+
117
+ const onLoadHandler = event => {
118
+ if (!paused) {
119
+ play();
120
+ } else {
121
+ pause();
122
+ }
123
+
124
+ const {
125
+ duration
126
+ } = event.nativeEvent;
127
+ onLoad === null || onLoad === void 0 ? void 0 : onLoad(parseDuration(duration));
128
+ };
129
+
130
+ const onLiveLatencyChangeHandler = event => {
131
+ const {
132
+ liveLatency
133
+ } = event.nativeEvent;
134
+ onLiveLatencyChange === null || onLiveLatencyChange === void 0 ? void 0 : onLiveLatencyChange(liveLatency);
135
+ };
136
+
137
+ const onDataHandler = event => {
138
+ const {
139
+ playerData
140
+ } = event.nativeEvent;
141
+ onData === null || onData === void 0 ? void 0 : onData(playerData);
142
+ };
143
+
144
+ const onTextCueHandler = event => {
145
+ const {
146
+ textCue
147
+ } = event.nativeEvent;
148
+ onTextCue === null || onTextCue === void 0 ? void 0 : onTextCue(textCue);
149
+ };
150
+
151
+ const onVideoStatisticsHandler = event => {
152
+ const {
153
+ videoData
154
+ } = event.nativeEvent;
155
+ const statistics = { ...videoData,
156
+ duration: parseDuration(videoData.duration)
157
+ };
158
+ onVideoStatistics === null || onVideoStatistics === void 0 ? void 0 : onVideoStatistics(statistics);
159
+ };
160
+
161
+ const onTextMetadataCueHandler = event => {
162
+ const {
163
+ textMetadataCue
164
+ } = event.nativeEvent;
165
+ onTextMetadataCue === null || onTextMetadataCue === void 0 ? void 0 : onTextMetadataCue(textMetadataCue);
166
+ };
167
+
168
+ const onProgressHandler = event => {
169
+ const {
170
+ position
171
+ } = event.nativeEvent;
172
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(position);
173
+ };
174
+
175
+ const onErrorHandler = event => {
176
+ const {
177
+ error
178
+ } = event.nativeEvent;
179
+ onError === null || onError === void 0 ? void 0 : onError(error);
180
+ };
181
+
182
+ const onTimePointHandler = event => {
183
+ const {
184
+ position
185
+ } = event.nativeEvent;
186
+ onTimePoint === null || onTimePoint === void 0 ? void 0 : onTimePoint(position);
187
+ };
188
+
189
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
190
+ style: [styles.container, style],
191
+ ref: ref
192
+ }, /*#__PURE__*/_react.default.createElement(IVSPlayer, {
193
+ testID: "IVSPlayer",
194
+ muted: muted,
195
+ liveLowLatency: liveLowLatency,
196
+ style: styles.mediaPlayer,
197
+ ref: mediaPlayerRef,
198
+ playbackRate: playbackRate,
199
+ streamUrl: streamUrl,
200
+ logLevel: logLevel,
201
+ progressInterval: progressInterval,
202
+ volume: volume,
203
+ quality: quality,
204
+ initialBufferDuration: initialBufferDuration,
205
+ autoMaxQuality: autoMaxQuality,
206
+ autoQualityMode: autoQualityMode,
207
+ breakpoints: breakpoints,
208
+ maxBitrate: maxBitrate,
209
+ onVideoStatistics: onVideoStatistics ? onVideoStatisticsHandler : undefined,
210
+ onData: onDataHandler,
211
+ onSeek: onSeekHandler,
212
+ onQualityChange: onQualityChangeHandler,
213
+ onPlayerStateChange: onPlayerStateChangeHandler,
214
+ onDurationChange: onDurationChangeHandler,
215
+ onRebuffering: onRebuffering,
216
+ onLoadStart: onLoadStart,
217
+ onLoad: onLoadHandler,
218
+ onTextCue: onTextCueHandler,
219
+ onTextMetadataCue: onTextMetadataCueHandler,
220
+ onProgress: onProgressHandler,
221
+ onLiveLatencyChange: onLiveLatencyChange ? onLiveLatencyChangeHandler : undefined,
222
+ onError: onErrorHandler,
223
+ onTimePoint: onTimePointHandler
224
+ }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
225
+ style: styles.children
226
+ }, children));
227
+ });
228
+
229
+ const styles = _reactNative.StyleSheet.create({
230
+ container: {
231
+ flex: 1
232
+ },
233
+ mediaPlayer: {
234
+ flex: 1
235
+ },
236
+ children: {
237
+ position: 'absolute',
238
+ width: '100%',
239
+ height: '100%'
240
+ }
241
+ });
242
+
243
+ var _default = IVSPlayerContainer;
244
+ exports.default = _default;
245
+ //# sourceMappingURL=IVSPlayer.js.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Flowtype definitions for IVSPlayer
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.13.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from 'react';
9
+ import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
10
+ import typeof { LogLevel } from './enums';
11
+ import type {
12
+ Quality,
13
+ PlayerData,
14
+ TextCue,
15
+ TextMetadataCue,
16
+ VideoData,
17
+ IVSPlayerRef,
18
+ } from './types';
19
+
20
+ declare type Props = {|
21
+ style?: ViewStyleProp,
22
+ paused?: boolean,
23
+ muted?: boolean,
24
+ autoplay?: boolean,
25
+ streamUrl?: string,
26
+ liveLowLatency?: boolean,
27
+ playbackRate?: number,
28
+ logLevel?: LogLevel,
29
+ progressInterval?: number,
30
+ volume?: number,
31
+ quality?: Quality | null,
32
+ autoMaxQuality?: Quality | null,
33
+ autoQualityMode?: boolean,
34
+ breakpoints?: number[],
35
+ maxBitrate?: number,
36
+ onSeek?: (position: number) => void,
37
+ onData?: (data: PlayerData) => void,
38
+ onVideoStatistics?: (data: VideoData) => void,
39
+ onPlayerStateChange?: (state: number) => void,
40
+ onDurationChange?: (duration: number | null) => void,
41
+ onQualityChange?: (quality: Quality | null) => void,
42
+ onRebuffering?: () => void,
43
+ onLoadStart?: () => void,
44
+ onLoad?: (duration: number | null) => void,
45
+ onLiveLatencyChange?: (liveLatency: number) => void,
46
+ onTextCue?: (textCue: TextCue) => void,
47
+ onTextMetadataCue?: (textMetadataCue: TextMetadataCue) => void,
48
+ onProgress?: (progress: number) => void,
49
+ onError?: (error: string) => void,
50
+ onTimePoint?: (position: number) => void,
51
+ |};
52
+ declare var IVSPlayerContainer: React.AbstractComponent<Props, IVSPlayerRef>;
53
+ declare export default typeof IVSPlayerContainer;