react-native-spalla-player 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Taghos Tecnologia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # react-native-spalla-player
2
+
3
+ Spalla SDK for RN
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-spalla-player
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import SpallaPlayer, { initialize } from 'react-native-spalla-player';
15
+
16
+ // make sure to call initialize as soon as possible on your app. Can be on top of index.js or App.js
17
+ initialize(
18
+ 'your spalla token',
19
+ null //application id for chromecast.
20
+ );
21
+
22
+ // ...
23
+
24
+ const playerRef = React.useRef<SpallaPlayer | null>(null);
25
+
26
+ const [muted, setMuted] = React.useState(false);
27
+ const [playing, setPlaying] = React.useState(true);
28
+
29
+ <SafeAreaView style={styles.container}>
30
+ <SpallaPlayer
31
+ ref={playerRef}
32
+ style={styles.videoPlayer}
33
+ contentId="Spalla contentId"
34
+ muted={muted}
35
+ hideUI={false}
36
+ onPlayerEvent={({ nativeEvent }) => {
37
+ switch (nativeEvent.event) {
38
+ case 'timeUpdate':
39
+ console.log('timeupdate', nativeEvent.time);
40
+ break;
41
+ case 'durationUpdate':
42
+ console.log('durationUpdate', nativeEvent.duration);
43
+ break;
44
+ case 'play':
45
+ case 'playing':
46
+ setPlaying(true);
47
+ break;
48
+ case 'pause':
49
+ setPlaying(false);
50
+ break;
51
+ case 'muted':
52
+ setMuted(true);
53
+ break;
54
+ case 'unmuted':
55
+ setMuted(false);
56
+ break;
57
+ default:
58
+ console.log('event', nativeEvent.event);
59
+ }
60
+ }}
61
+ >
62
+ <View style={styles.uicontainer}>{/*Place your custom UI here*/}</View>
63
+ </SpallaPlayer>
64
+ <Button
65
+ onPress={() => {
66
+ if (playing) {
67
+ playerRef.current?.pause();
68
+ } else {
69
+ playerRef.current?.play();
70
+ }
71
+ }}
72
+ title={playing ? 'Pause' : 'Play'}
73
+ />
74
+ <Button
75
+ onPress={() => setMuted(!muted)}
76
+ title={muted ? 'Unmute' : 'Mute'}
77
+ />
78
+ </SafeAreaView>
79
+ ```
80
+
81
+ ## Props
82
+
83
+ | Property | Type | Description |
84
+ | :----------------- | :------: | :----------- |
85
+ | **`contentId`** | string | Spalla contentId that will be played
86
+ | **`hideUI`** | boolean | hide or show the default UI (its a prop, but it can only be set once)
87
+ | **`muted`** | boolean | mute/unmute video
88
+ | **`onPlayerEvent`**| callback | Function that will be called with player events
89
+
90
+ ## Imperative Methods
91
+
92
+ You can control a player reference using 3 methods
93
+
94
+ | Method | Description |
95
+ | :----------------- | :----------- |
96
+ | **`play()`** | Resume playback
97
+ | **`pause()`** | Pause playback
98
+ | **`seekTo(time)`** | Seek to a time (in seconds)
99
+
100
+ ```js
101
+ playerRef.current?.play();
102
+ playerRef.current?.pause();
103
+ playerRef.current?.seekTo(12); //position in seconds, if higher than duration it will move to the end
104
+ ```
105
+
106
+ ## Contributing
107
+
108
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
109
+
110
+ ## License
111
+
112
+ MIT
113
+
114
+ ---
115
+
116
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,100 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["SpallaPlayer_kotlinVersion"]
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def reactNativeArchitectures() {
18
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
19
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
20
+ }
21
+
22
+ def isNewArchitectureEnabled() {
23
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
24
+ }
25
+
26
+ apply plugin: "com.android.library"
27
+ apply plugin: "kotlin-android"
28
+
29
+ if (isNewArchitectureEnabled()) {
30
+ apply plugin: "com.facebook.react"
31
+ }
32
+
33
+ def getExtOrDefault(name) {
34
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["SpallaPlayer_" + name]
35
+ }
36
+
37
+ def getExtOrIntegerDefault(name) {
38
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SpallaPlayer_" + name]).toInteger()
39
+ }
40
+
41
+ def supportsNamespace() {
42
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
43
+ def major = parsed[0].toInteger()
44
+ def minor = parsed[1].toInteger()
45
+
46
+ // Namespace support was added in 7.3.0
47
+ return (major == 7 && minor >= 3) || major >= 8
48
+ }
49
+
50
+ android {
51
+ if (supportsNamespace()) {
52
+ namespace "com.spallaplayer"
53
+
54
+ sourceSets {
55
+ main {
56
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
57
+ }
58
+ }
59
+ }
60
+
61
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
62
+
63
+ defaultConfig {
64
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
65
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
66
+
67
+ }
68
+
69
+ buildTypes {
70
+ release {
71
+ minifyEnabled false
72
+ }
73
+ }
74
+
75
+ lintOptions {
76
+ disable "GradleCompatible"
77
+ }
78
+
79
+ compileOptions {
80
+ sourceCompatibility JavaVersion.VERSION_1_8
81
+ targetCompatibility JavaVersion.VERSION_1_8
82
+ }
83
+ }
84
+
85
+ repositories {
86
+ mavenCentral()
87
+ google()
88
+ }
89
+
90
+ def kotlin_version = getExtOrDefault("kotlinVersion")
91
+
92
+ dependencies {
93
+ // For < 0.71, this will be from the local maven repo
94
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
95
+ //noinspection GradleDynamicVersion
96
+ implementation "com.facebook.react:react-native:+"
97
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
98
+ implementation("stream.spalla:spalla-android-sdk:1.2.2")
99
+ }
100
+
@@ -0,0 +1,5 @@
1
+ SpallaPlayer_kotlinVersion=1.7.0
2
+ SpallaPlayer_minSdkVersion=21
3
+ SpallaPlayer_targetSdkVersion=31
4
+ SpallaPlayer_compileSdkVersion=31
5
+ SpallaPlayer_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.spallaplayer">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,94 @@
1
+ package com.spallaplayer
2
+
3
+ import com.facebook.react.bridge.LifecycleEventListener
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReactMethod
7
+ import com.facebook.react.uimanager.NativeViewHierarchyManager
8
+ import com.facebook.react.uimanager.UIManagerModule
9
+ import com.spalla.sdk.android.core.SpallaSDK
10
+ import com.spalla.sdk.android.core.player.view.SpallaPlayerView
11
+
12
+ class SpallaPlayerModule(reactContext: ReactApplicationContext) :
13
+ ReactContextBaseJavaModule(reactContext),
14
+ LifecycleEventListener {
15
+ private val _reactContext: ReactApplicationContext
16
+
17
+ init {
18
+ reactContext.addLifecycleEventListener(this)
19
+ _reactContext = reactContext
20
+ }
21
+
22
+ override fun getName(): String {
23
+ return "RNSpallaPlayer"
24
+ }
25
+
26
+ override fun onHostResume() {
27
+ }
28
+
29
+ override fun onHostPause() {
30
+ }
31
+
32
+ override fun onHostDestroy() {
33
+ }
34
+
35
+ @ReactMethod
36
+ fun play(tag: Int) {
37
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
38
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
39
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
40
+ if (playerView is SpallaPlayerView) {
41
+ playerView.play()
42
+ } else {
43
+ throw ClassCastException(
44
+ String.format(
45
+ "Cannot play: view with tag #%d is not a SpallaPlayerView",
46
+ tag
47
+ )
48
+ )
49
+ }
50
+ }
51
+ }
52
+
53
+ @ReactMethod
54
+ fun pause(tag: Int) {
55
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
56
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
57
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
58
+ if (playerView is SpallaPlayerView) {
59
+ playerView.pause()
60
+ } else {
61
+ throw ClassCastException(
62
+ String.format(
63
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
64
+ tag
65
+ )
66
+ )
67
+ }
68
+ }
69
+ }
70
+
71
+ @ReactMethod
72
+ fun seekTo(tag: Int, time: Double) {
73
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
74
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
75
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
76
+ if (playerView is SpallaPlayerView) {
77
+ playerView.seekTo(time)
78
+ } else {
79
+ throw ClassCastException(
80
+ String.format(
81
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
82
+ tag
83
+ )
84
+ )
85
+ }
86
+ }
87
+ }
88
+
89
+ @ReactMethod
90
+ fun initialize(token: String, applicationId: String?) {
91
+ SpallaSDK.initialize(_reactContext, token)
92
+ }
93
+
94
+ }
@@ -0,0 +1,17 @@
1
+ package com.spallaplayer
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class SpallaPlayerPackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(SpallaPlayerModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return listOf(RNSpallaPlayerManager())
16
+ }
17
+ }
@@ -0,0 +1,96 @@
1
+ package com.spallaplayer
2
+
3
+ import android.util.Log
4
+ import com.facebook.react.bridge.Arguments
5
+ import com.facebook.react.bridge.ReactContext
6
+ import com.facebook.react.bridge.WritableMap
7
+ import com.facebook.react.common.MapBuilder
8
+ import com.facebook.react.uimanager.SimpleViewManager
9
+ import com.facebook.react.uimanager.ThemedReactContext
10
+ import com.facebook.react.uimanager.annotations.ReactProp
11
+ import com.facebook.react.uimanager.events.RCTEventEmitter
12
+ import com.spalla.sdk.android.core.player.entities.SpallaPlayerEvent
13
+ import com.spalla.sdk.android.core.player.entities.SpallaPlayerEvent.*
14
+ import com.spalla.sdk.android.core.player.listeners.SpallaPlayerListener
15
+ import com.spalla.sdk.android.core.player.view.SpallaPlayerView
16
+
17
+ class RNSpallaPlayerManager() : SimpleViewManager<SpallaPlayerView>(), SpallaPlayerListener {
18
+ private var _playerView: SpallaPlayerView? = null
19
+ private var _reactContext: ReactContext? = null
20
+
21
+ override fun getName() = "RNSpallaPlayer"
22
+
23
+ override fun createViewInstance(context: ThemedReactContext): SpallaPlayerView {
24
+ _reactContext = context
25
+ val player = SpallaPlayerView(context)
26
+ _playerView = player
27
+ player.registerPlayerListener(this)
28
+
29
+ return player
30
+ }
31
+
32
+ override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any> {
33
+ return MapBuilder.builder<String, Any>()
34
+ .put(
35
+ "onPlayerEvent",
36
+ MapBuilder.of(
37
+ "phasedRegistrationNames",
38
+ MapBuilder.of("bubbled", "onPlayerEvent")
39
+ )
40
+ )
41
+ .build()
42
+ }
43
+
44
+ override fun onDropViewInstance(view: SpallaPlayerView) {
45
+ Log.v("RNSpallaPlayerManager", "onDropViewInstance")
46
+
47
+ try {
48
+ view.onDestroy()
49
+ } catch (e: Exception) {
50
+ e.printStackTrace()
51
+ }
52
+ super.onDropViewInstance(view)
53
+ }
54
+
55
+ @ReactProp(name = "contentId")
56
+ fun setContentId(view: SpallaPlayerView, contentId: String) {
57
+ _playerView?.load(contentId, false, true)
58
+ }
59
+
60
+ @ReactProp(name = "muted")
61
+ fun setMuted(view: SpallaPlayerView, muted: Boolean) {
62
+ _playerView?.setMuted(muted)
63
+ }
64
+
65
+ override fun onEvent( spallaPlayerEvent: SpallaPlayerEvent) {
66
+ val map: WritableMap = Arguments.createMap()
67
+
68
+ when (spallaPlayerEvent) {
69
+ is DurationUpdate -> {
70
+ map.putString("event", "durationUpdate")
71
+ map.putDouble("duration", spallaPlayerEvent.duration)
72
+ }
73
+ Ended -> map.putString("event", "ended")
74
+ is Error -> {
75
+ map.putString("event", "error")
76
+ map.putString("message", spallaPlayerEvent.message)
77
+ }
78
+ Pause -> map.putString("event", "pause")
79
+ Play -> map.putString("event", "play")
80
+ Playing -> map.putString("event", "playing")
81
+ is TimeUpdate -> {
82
+ map.putString("event", "timeUpdate")
83
+ map.putDouble("time", spallaPlayerEvent.currentTime)
84
+ }
85
+ Waiting -> map.putString("event", "buffering")
86
+ }
87
+ _playerView?.let { player ->
88
+ _reactContext?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(
89
+ player.id,
90
+ "onPlayerEvent",
91
+ map
92
+ )
93
+ }
94
+
95
+ }
96
+ }
@@ -0,0 +1,60 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import <react_native_spalla_player-Swift.h>
4
+ @import SpallaSDK;
5
+
6
+ @interface RCT_EXTERN_MODULE(RNSpallaPlayer, RCTViewManager)
7
+
8
+ RCT_EXPORT_VIEW_PROPERTY(contentId, NSString)
9
+
10
+ RCT_EXPORT_VIEW_PROPERTY(muted, BOOL)
11
+
12
+ RCT_EXPORT_VIEW_PROPERTY(hideUI, BOOL)
13
+
14
+ RCT_EXPORT_METHOD(play: (nonnull NSNumber *) reactTag {
15
+
16
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
17
+ UIView *view = viewRegistry[reactTag];
18
+ if (!view || ![view isKindOfClass:[SpallaPlayerWrapper class]]) {
19
+ RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
20
+ return;
21
+ } else {
22
+ [(SpallaPlayerWrapper *)view play];
23
+ }
24
+
25
+ }];
26
+ })
27
+
28
+ RCT_EXPORT_METHOD(pause: (nonnull NSNumber *) reactTag {
29
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
30
+ UIView *view = viewRegistry[reactTag];
31
+ if (!view || ![view isKindOfClass:[SpallaPlayerWrapper class]]) {
32
+ RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
33
+ return;
34
+ } else {
35
+ [(SpallaPlayerWrapper *)view pause];
36
+ }
37
+ }];
38
+ })
39
+
40
+ RCT_EXPORT_METHOD(seekTo: (nonnull NSNumber *) reactTag time:(float)time) {
41
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
42
+ UIView *view = viewRegistry[reactTag];
43
+ if (!view || ![view isKindOfClass:[SpallaPlayerWrapper class]]) {
44
+ RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
45
+ return;
46
+ } else {
47
+ [(SpallaPlayerWrapper *)view seekToTime: time];
48
+ }
49
+ }];
50
+ }
51
+
52
+ RCT_EXPORT_METHOD(initialize: (nonnull NSString *) token: (NSString *) applicationId) {
53
+ dispatch_async(dispatch_get_main_queue(), ^{
54
+ [SpallaPlayerWrapper initializeWithToken: token applicationId: applicationId];
55
+ });
56
+ }
57
+
58
+ RCT_EXPORT_VIEW_PROPERTY(onPlayerEvent, RCTBubblingEventBlock)
59
+
60
+ @end
@@ -0,0 +1,11 @@
1
+ @objc(RNSpallaPlayer)
2
+ class RNSpallaPlayer: RCTViewManager {
3
+
4
+ override func view() -> (SpallaPlayerWrapper) {
5
+ return SpallaPlayerWrapper()
6
+ }
7
+
8
+ @objc override static func requiresMainQueueSetup() -> Bool {
9
+ return true
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ #import <React/RCTViewManager.h>
@@ -0,0 +1,129 @@
1
+ //
2
+ // SpallaPlayerWrapper.swift
3
+ // SpallaSample
4
+ //
5
+ // Created by Rogerio Shimizu on 11/30/23.
6
+ //
7
+
8
+ import Foundation
9
+ import UIKit
10
+ import SpallaSDK
11
+
12
+ @objc public class SpallaPlayerWrapper: UIView {
13
+
14
+ let viewController: SpallaPlayerViewController
15
+
16
+ @objc var contentId: String? {
17
+ didSet {
18
+ print("Content id: \(contentId ?? "nil")")
19
+ // hacky! this needs to be delayed a bit so hideUI can be set first when comming from RN
20
+ // ideally we should use a chromeless class
21
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
22
+ self.setupPlayer()
23
+ }
24
+ }
25
+ }
26
+
27
+ @objc var muted: Bool = false {
28
+ didSet {
29
+ if muted {
30
+ viewController.mute()
31
+ } else {
32
+ viewController.unmute()
33
+ }
34
+ }
35
+ }
36
+
37
+ @objc var hideUI: Bool = false
38
+
39
+ @objc var onPlayerEvent: RCTBubblingEventBlock?
40
+
41
+ convenience public init() {
42
+ self.init(frame: CGRect.zero)
43
+ }
44
+
45
+ override init(frame: CGRect) {
46
+ viewController = SpallaPlayerViewController()
47
+ super.init(frame: frame)
48
+
49
+ //add view controller on main window
50
+ self.window?.rootViewController?.addChild(viewController)
51
+ if let playerView = viewController.view {
52
+ self.addSubview(playerView)
53
+ }
54
+
55
+ //add listeners
56
+ viewController.registerPlayerListener(listener: self)
57
+ }
58
+
59
+ override public func layoutSubviews() {
60
+ super.layoutSubviews()
61
+ if let playerView = viewController.view {
62
+ playerView.frame = self.bounds
63
+ }
64
+
65
+ }
66
+
67
+ required init?(coder: NSCoder) {
68
+ fatalError("init(coder:) has not been implemented")
69
+ }
70
+
71
+ func setupPlayer() {
72
+ if let contentId {
73
+ viewController.setup(with: contentId, isLive: false, hideUI: hideUI)
74
+ }
75
+ }
76
+
77
+ @objc public func play() {
78
+ viewController.play()
79
+ }
80
+
81
+ @objc public func pause() {
82
+ viewController.pause()
83
+ }
84
+
85
+ @objc public func seekTo(time: Float) {
86
+ viewController.seekTo(time: TimeInterval(time))
87
+ }
88
+
89
+ @objc static public func initialize(token: String, applicationId: String) {
90
+ Spalla.shared.initialize(token: token, applicationId: applicationId)
91
+ }
92
+
93
+ deinit {
94
+ viewController.pause()
95
+ viewController.removeFromParent()
96
+ }
97
+ }
98
+
99
+ extension SpallaPlayerWrapper: SpallaPlayerListener {
100
+ public func onEvent(event: SpallaSDK.SpallaPlayerEvent) {
101
+
102
+ guard let onPlayerEvent else { return }
103
+
104
+ switch event {
105
+ case .durationUpdate(let time):
106
+ onPlayerEvent(["event": "durationUpdate", "duration": time])
107
+ case .ended:
108
+ onPlayerEvent(["event": "ended"])
109
+ case .muted:
110
+ onPlayerEvent(["event": "muted"])
111
+ case .pause:
112
+ onPlayerEvent(["event": "pause"])
113
+ case .play:
114
+ onPlayerEvent(["event": "play"])
115
+ case .playing:
116
+ onPlayerEvent(["event": "playing"])
117
+ case .unmuted:
118
+ onPlayerEvent(["event": "unmuted"])
119
+ case .error(let error, let canRetry):
120
+ onPlayerEvent(["event": "error", "error": error, "canRetry": canRetry])
121
+ case .timeUpdate(let time):
122
+ onPlayerEvent(["event": "timeUpdate", "time": time])
123
+ case .waiting:
124
+ onPlayerEvent(["event": "buffering"])
125
+ @unknown default:
126
+ break
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.seekTo = exports.play = exports.pause = exports.initialize = exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ const RNSpallaPlayer = (0, _reactNative.requireNativeComponent)('RNSpallaPlayer');
12
+ const RNSpallaPlayerModule = _reactNative.NativeModules.RNSpallaPlayer;
13
+ const play = ref => {
14
+ const handle = (0, _reactNative.findNodeHandle)(ref);
15
+ RNSpallaPlayerModule.play(handle);
16
+ };
17
+ exports.play = play;
18
+ const pause = ref => {
19
+ const handle = (0, _reactNative.findNodeHandle)(ref);
20
+ RNSpallaPlayerModule.pause(handle);
21
+ };
22
+ exports.pause = pause;
23
+ const seekTo = (ref, time) => {
24
+ const handle = (0, _reactNative.findNodeHandle)(ref);
25
+ RNSpallaPlayerModule.seekTo(handle, time);
26
+ };
27
+
28
+ //export default SpallaPlayer;
29
+ exports.seekTo = seekTo;
30
+ class SpallaPlayer extends _react.default.Component {
31
+ _player = null;
32
+ _setRef = ref => {
33
+ this._player = ref;
34
+ };
35
+ render() {
36
+ const {
37
+ style
38
+ } = this.props;
39
+
40
+ //const {maxHeight} = this.state;
41
+
42
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(RNSpallaPlayer, {
43
+ ...this.props,
44
+ ref: this._setRef,
45
+ style: style,
46
+ children: this.props.children
47
+ });
48
+ }
49
+ play = () => {
50
+ const handle = (0, _reactNative.findNodeHandle)(this._player);
51
+ RNSpallaPlayerModule.play(handle);
52
+ };
53
+ pause = () => {
54
+ const handle = (0, _reactNative.findNodeHandle)(this._player);
55
+ RNSpallaPlayerModule.pause(handle);
56
+ };
57
+ }
58
+ const initialize = (token, applicationId) => {
59
+ RNSpallaPlayerModule.initialize(token, applicationId);
60
+ };
61
+ exports.initialize = initialize;
62
+ var _default = exports.default = SpallaPlayer;
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_jsxRuntime","e","__esModule","default","RNSpallaPlayer","requireNativeComponent","RNSpallaPlayerModule","NativeModules","play","ref","handle","findNodeHandle","exports","pause","seekTo","time","SpallaPlayer","React","Component","_player","_setRef","render","style","props","jsx","children","initialize","token","applicationId","_default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAKsB,IAAAE,WAAA,GAAAF,OAAA;AAAA,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAQtB,MAAMG,cAAc,GAClB,IAAAC,mCAAsB,EAAsB,gBAAgB,CAAC;AAE/D,MAAMC,oBAAoB,GAAGC,0BAAa,CAACH,cAAc;AAsClD,MAAMI,IAAI,GAAIC,GAAQ,IAAK;EAChC,MAAMC,MAAM,GAAG,IAAAC,2BAAc,EAACF,GAAG,CAAC;EAClCH,oBAAoB,CAACE,IAAI,CAACE,MAAM,CAAC;AACnC,CAAC;AAACE,OAAA,CAAAJ,IAAA,GAAAA,IAAA;AAEK,MAAMK,KAAK,GAAIJ,GAAQ,IAAK;EACjC,MAAMC,MAAM,GAAG,IAAAC,2BAAc,EAACF,GAAG,CAAC;EAClCH,oBAAoB,CAACO,KAAK,CAACH,MAAM,CAAC;AACpC,CAAC;AAACE,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAEK,MAAMC,MAAM,GAAGA,CAACL,GAAQ,EAAEM,IAAY,KAAK;EAChD,MAAML,MAAM,GAAG,IAAAC,2BAAc,EAACF,GAAG,CAAC;EAClCH,oBAAoB,CAACQ,MAAM,CAACJ,MAAM,EAAEK,IAAI,CAAC;AAC3C,CAAC;;AAED;AAAAH,OAAA,CAAAE,MAAA,GAAAA,MAAA;AAEA,MAAME,YAAY,SAASC,cAAK,CAACC,SAAS,CAAQ;EAChDC,OAAO,GAAG,IAAI;EAEdC,OAAO,GAAIX,GAAQ,IAAK;IACtB,IAAI,CAACU,OAAO,GAAGV,GAAG;EACpB,CAAC;EAEDY,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEC;IAAM,CAAC,GAAG,IAAI,CAACC,KAAK;;IAE5B;;IAEA,oBACE,IAAAvB,WAAA,CAAAwB,GAAA,EAACpB,cAAc;MAAA,GAAK,IAAI,CAACmB,KAAK;MAAEd,GAAG,EAAE,IAAI,CAACW,OAAQ;MAACE,KAAK,EAAEA,KAAM;MAAAG,QAAA,EAC7D,IAAI,CAACF,KAAK,CAACE;IAAQ,CACN,CAAC;EAErB;EAEAjB,IAAI,GAAGA,CAAA,KAAM;IACX,MAAME,MAAM,GAAG,IAAAC,2BAAc,EAAC,IAAI,CAACQ,OAAO,CAAC;IAC3Cb,oBAAoB,CAACE,IAAI,CAACE,MAAM,CAAC;EACnC,CAAC;EAEDG,KAAK,GAAGA,CAAA,KAAM;IACZ,MAAMH,MAAM,GAAG,IAAAC,2BAAc,EAAC,IAAI,CAACQ,OAAO,CAAC;IAC3Cb,oBAAoB,CAACO,KAAK,CAACH,MAAM,CAAC;EACpC,CAAC;AACH;AAEO,MAAMgB,UAAU,GAAGA,CAACC,KAAa,EAAEC,aAA4B,KAAK;EACzEtB,oBAAoB,CAACoB,UAAU,CAACC,KAAK,EAAEC,aAAa,CAAC;AACvD,CAAC;AAAChB,OAAA,CAAAc,UAAA,GAAAA,UAAA;AAAA,IAAAG,QAAA,GAAAjB,OAAA,CAAAT,OAAA,GAEaa,YAAY","ignoreList":[]}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ import React from 'react';
4
+ import { requireNativeComponent, NativeModules, findNodeHandle } from 'react-native';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const RNSpallaPlayer = requireNativeComponent('RNSpallaPlayer');
7
+ const RNSpallaPlayerModule = NativeModules.RNSpallaPlayer;
8
+ export const play = ref => {
9
+ const handle = findNodeHandle(ref);
10
+ RNSpallaPlayerModule.play(handle);
11
+ };
12
+ export const pause = ref => {
13
+ const handle = findNodeHandle(ref);
14
+ RNSpallaPlayerModule.pause(handle);
15
+ };
16
+ export const seekTo = (ref, time) => {
17
+ const handle = findNodeHandle(ref);
18
+ RNSpallaPlayerModule.seekTo(handle, time);
19
+ };
20
+
21
+ //export default SpallaPlayer;
22
+
23
+ class SpallaPlayer extends React.Component {
24
+ _player = null;
25
+ _setRef = ref => {
26
+ this._player = ref;
27
+ };
28
+ render() {
29
+ const {
30
+ style
31
+ } = this.props;
32
+
33
+ //const {maxHeight} = this.state;
34
+
35
+ return /*#__PURE__*/_jsx(RNSpallaPlayer, {
36
+ ...this.props,
37
+ ref: this._setRef,
38
+ style: style,
39
+ children: this.props.children
40
+ });
41
+ }
42
+ play = () => {
43
+ const handle = findNodeHandle(this._player);
44
+ RNSpallaPlayerModule.play(handle);
45
+ };
46
+ pause = () => {
47
+ const handle = findNodeHandle(this._player);
48
+ RNSpallaPlayerModule.pause(handle);
49
+ };
50
+ }
51
+ export const initialize = (token, applicationId) => {
52
+ RNSpallaPlayerModule.initialize(token, applicationId);
53
+ };
54
+ export default SpallaPlayer;
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","requireNativeComponent","NativeModules","findNodeHandle","jsx","_jsx","RNSpallaPlayer","RNSpallaPlayerModule","play","ref","handle","pause","seekTo","time","SpallaPlayer","Component","_player","_setRef","render","style","props","children","initialize","token","applicationId"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,sBAAsB,EAEtBC,aAAa,EACbC,cAAc,QACT,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQtB,MAAMC,cAAc,GAClBL,sBAAsB,CAAsB,gBAAgB,CAAC;AAE/D,MAAMM,oBAAoB,GAAGL,aAAa,CAACI,cAAc;AAsCzD,OAAO,MAAME,IAAI,GAAIC,GAAQ,IAAK;EAChC,MAAMC,MAAM,GAAGP,cAAc,CAACM,GAAG,CAAC;EAClCF,oBAAoB,CAACC,IAAI,CAACE,MAAM,CAAC;AACnC,CAAC;AAED,OAAO,MAAMC,KAAK,GAAIF,GAAQ,IAAK;EACjC,MAAMC,MAAM,GAAGP,cAAc,CAACM,GAAG,CAAC;EAClCF,oBAAoB,CAACI,KAAK,CAACD,MAAM,CAAC;AACpC,CAAC;AAED,OAAO,MAAME,MAAM,GAAGA,CAACH,GAAQ,EAAEI,IAAY,KAAK;EAChD,MAAMH,MAAM,GAAGP,cAAc,CAACM,GAAG,CAAC;EAClCF,oBAAoB,CAACK,MAAM,CAACF,MAAM,EAAEG,IAAI,CAAC;AAC3C,CAAC;;AAED;;AAEA,MAAMC,YAAY,SAASd,KAAK,CAACe,SAAS,CAAQ;EAChDC,OAAO,GAAG,IAAI;EAEdC,OAAO,GAAIR,GAAQ,IAAK;IACtB,IAAI,CAACO,OAAO,GAAGP,GAAG;EACpB,CAAC;EAEDS,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEC;IAAM,CAAC,GAAG,IAAI,CAACC,KAAK;;IAE5B;;IAEA,oBACEf,IAAA,CAACC,cAAc;MAAA,GAAK,IAAI,CAACc,KAAK;MAAEX,GAAG,EAAE,IAAI,CAACQ,OAAQ;MAACE,KAAK,EAAEA,KAAM;MAAAE,QAAA,EAC7D,IAAI,CAACD,KAAK,CAACC;IAAQ,CACN,CAAC;EAErB;EAEAb,IAAI,GAAGA,CAAA,KAAM;IACX,MAAME,MAAM,GAAGP,cAAc,CAAC,IAAI,CAACa,OAAO,CAAC;IAC3CT,oBAAoB,CAACC,IAAI,CAACE,MAAM,CAAC;EACnC,CAAC;EAEDC,KAAK,GAAGA,CAAA,KAAM;IACZ,MAAMD,MAAM,GAAGP,cAAc,CAAC,IAAI,CAACa,OAAO,CAAC;IAC3CT,oBAAoB,CAACI,KAAK,CAACD,MAAM,CAAC;EACpC,CAAC;AACH;AAEA,OAAO,MAAMY,UAAU,GAAGA,CAACC,KAAa,EAAEC,aAA4B,KAAK;EACzEjB,oBAAoB,CAACe,UAAU,CAACC,KAAK,EAAEC,aAAa,CAAC;AACvD,CAAC;AAED,eAAeV,YAAY","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { type ViewStyle } from 'react-native';
3
+ interface PlayerEventTimeUpdate {
4
+ event: 'timeUpdate';
5
+ time: number;
6
+ }
7
+ interface PlayerEventDurationUpdate {
8
+ event: 'durationUpdate';
9
+ duration: number;
10
+ }
11
+ interface PlayerEvent {
12
+ event: 'play' | 'pause' | 'ended' | 'muted' | 'unmuted' | 'buffering' | 'playing';
13
+ }
14
+ interface Props {
15
+ style?: ViewStyle;
16
+ children?: React.ReactNode;
17
+ hideUI?: boolean;
18
+ contentId: string;
19
+ muted?: boolean;
20
+ autoplay?: boolean;
21
+ onPlayerEvent?: (event: {
22
+ nativeEvent: PlayerEventTimeUpdate | PlayerEvent | PlayerEventDurationUpdate;
23
+ }) => void;
24
+ }
25
+ export declare const play: (ref: any) => void;
26
+ export declare const pause: (ref: any) => void;
27
+ export declare const seekTo: (ref: any, time: number) => void;
28
+ declare class SpallaPlayer extends React.Component<Props> {
29
+ _player: null;
30
+ _setRef: (ref: any) => void;
31
+ render(): import("react/jsx-runtime").JSX.Element;
32
+ play: () => void;
33
+ pause: () => void;
34
+ }
35
+ export declare const initialize: (token: String, applicationId: String | null) => void;
36
+ export default SpallaPlayer;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,cAAc,CAAC;AAatB,UAAU,qBAAqB;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,yBAAyB;IACjC,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,WAAW;IACnB,KAAK,EACD,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,SAAS,GACT,WAAW,GACX,SAAS,CAAC;CACf;AAED,UAAU,KAAK;IACb,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,WAAW,EACP,qBAAqB,GACrB,WAAW,GACX,yBAAyB,CAAC;KAC/B,KAAK,IAAI,CAAC;CACZ;AAED,eAAO,MAAM,IAAI,QAAS,GAAG,SAG5B,CAAC;AAEF,eAAO,MAAM,KAAK,QAAS,GAAG,SAG7B,CAAC;AAEF,eAAO,MAAM,MAAM,QAAS,GAAG,QAAQ,MAAM,SAG5C,CAAC;AAIF,cAAM,YAAa,SAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;IAC/C,OAAO,OAAQ;IAEf,OAAO,QAAS,GAAG,UAEjB;IAEF,MAAM;IAYN,IAAI,aAGF;IAEF,KAAK,aAGH;CACH;AAED,eAAO,MAAM,UAAU,UAAW,MAAM,iBAAiB,MAAM,GAAG,IAAI,SAErE,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { type ViewStyle } from 'react-native';
3
+ interface PlayerEventTimeUpdate {
4
+ event: 'timeUpdate';
5
+ time: number;
6
+ }
7
+ interface PlayerEventDurationUpdate {
8
+ event: 'durationUpdate';
9
+ duration: number;
10
+ }
11
+ interface PlayerEvent {
12
+ event: 'play' | 'pause' | 'ended' | 'muted' | 'unmuted' | 'buffering' | 'playing';
13
+ }
14
+ interface Props {
15
+ style?: ViewStyle;
16
+ children?: React.ReactNode;
17
+ hideUI?: boolean;
18
+ contentId: string;
19
+ muted?: boolean;
20
+ autoplay?: boolean;
21
+ onPlayerEvent?: (event: {
22
+ nativeEvent: PlayerEventTimeUpdate | PlayerEvent | PlayerEventDurationUpdate;
23
+ }) => void;
24
+ }
25
+ export declare const play: (ref: any) => void;
26
+ export declare const pause: (ref: any) => void;
27
+ export declare const seekTo: (ref: any, time: number) => void;
28
+ declare class SpallaPlayer extends React.Component<Props> {
29
+ _player: null;
30
+ _setRef: (ref: any) => void;
31
+ render(): import("react/jsx-runtime").JSX.Element;
32
+ play: () => void;
33
+ pause: () => void;
34
+ }
35
+ export declare const initialize: (token: String, applicationId: String | null) => void;
36
+ export default SpallaPlayer;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,cAAc,CAAC;AAatB,UAAU,qBAAqB;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,yBAAyB;IACjC,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,WAAW;IACnB,KAAK,EACD,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,SAAS,GACT,WAAW,GACX,SAAS,CAAC;CACf;AAED,UAAU,KAAK;IACb,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,WAAW,EACP,qBAAqB,GACrB,WAAW,GACX,yBAAyB,CAAC;KAC/B,KAAK,IAAI,CAAC;CACZ;AAED,eAAO,MAAM,IAAI,QAAS,GAAG,SAG5B,CAAC;AAEF,eAAO,MAAM,KAAK,QAAS,GAAG,SAG7B,CAAC;AAEF,eAAO,MAAM,MAAM,QAAS,GAAG,QAAQ,MAAM,SAG5C,CAAC;AAIF,cAAM,YAAa,SAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;IAC/C,OAAO,OAAQ;IAEf,OAAO,QAAS,GAAG,UAEjB;IAEF,MAAM;IAYN,IAAI,aAGF;IAEF,KAAK,aAGH;CACH;AAED,eAAO,MAAM,UAAU,UAAW,MAAM,iBAAiB,MAAM,GAAG,IAAI,SAErE,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/package.json ADDED
@@ -0,0 +1,187 @@
1
+ {
2
+ "name": "react-native-spalla-player",
3
+ "version": "0.2.0",
4
+ "description": "Spalla SDK for RN",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/commonjs/index.js",
7
+ "module": "./lib/module/index.js",
8
+ "exports": {
9
+ ".": {
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
+ }
19
+ },
20
+ "files": [
21
+ "src",
22
+ "lib",
23
+ "android",
24
+ "ios",
25
+ "cpp",
26
+ "*.podspec",
27
+ "!ios/build",
28
+ "!android/build",
29
+ "!android/gradle",
30
+ "!android/gradlew",
31
+ "!android/gradlew.bat",
32
+ "!android/local.properties",
33
+ "!**/__tests__",
34
+ "!**/__fixtures__",
35
+ "!**/__mocks__",
36
+ "!**/.*"
37
+ ],
38
+ "scripts": {
39
+ "example": "yarn workspace react-native-spalla-player-example",
40
+ "test": "jest",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
44
+ "prepare": "bob build",
45
+ "release": "release-it"
46
+ },
47
+ "keywords": [
48
+ "react-native",
49
+ "ios",
50
+ "android"
51
+ ],
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/taghos/framework-sdk-spalla-react-native.git"
55
+ },
56
+ "author": "Rogerio Shimizu <roja@bunker79.com> (https://github.com/rojas)",
57
+ "license": "MIT",
58
+ "bugs": {
59
+ "url": "https://github.com/taghos/framework-sdk-spalla-react-native/issues"
60
+ },
61
+ "homepage": "https://github.com/taghos/framework-sdk-spalla-react-native#readme",
62
+ "publishConfig": {
63
+ "registry": "https://registry.npmjs.org/"
64
+ },
65
+ "devDependencies": {
66
+ "@commitlint/config-conventional": "^17.0.2",
67
+ "@evilmartians/lefthook": "^1.5.0",
68
+ "@react-native/eslint-config": "^0.73.1",
69
+ "@release-it/conventional-changelog": "^5.0.0",
70
+ "@types/jest": "^29.5.5",
71
+ "@types/react": "^18.2.44",
72
+ "commitlint": "^17.0.2",
73
+ "del-cli": "^5.1.0",
74
+ "eslint": "^8.51.0",
75
+ "eslint-config-prettier": "^9.0.0",
76
+ "eslint-plugin-prettier": "^5.0.1",
77
+ "jest": "^29.7.0",
78
+ "prettier": "^3.0.3",
79
+ "react": "18.3.1",
80
+ "react-native": "0.75.4",
81
+ "react-native-builder-bob": "^0.30.2",
82
+ "release-it": "^15.0.0",
83
+ "turbo": "^1.10.7",
84
+ "typescript": "^5.2.2"
85
+ },
86
+ "resolutions": {
87
+ "@types/react": "^18.2.44"
88
+ },
89
+ "peerDependencies": {
90
+ "react": "*",
91
+ "react-native": "*"
92
+ },
93
+ "workspaces": [
94
+ "example"
95
+ ],
96
+ "packageManager": "yarn@3.6.1",
97
+ "jest": {
98
+ "preset": "react-native",
99
+ "modulePathIgnorePatterns": [
100
+ "<rootDir>/example/node_modules",
101
+ "<rootDir>/lib/"
102
+ ]
103
+ },
104
+ "commitlint": {
105
+ "extends": [
106
+ "@commitlint/config-conventional"
107
+ ]
108
+ },
109
+ "release-it": {
110
+ "git": {
111
+ "commitMessage": "chore: release ${version}",
112
+ "tagName": "v${version}"
113
+ },
114
+ "npm": {
115
+ "publish": true
116
+ },
117
+ "github": {
118
+ "release": true
119
+ },
120
+ "plugins": {
121
+ "@release-it/conventional-changelog": {
122
+ "preset": "angular"
123
+ }
124
+ }
125
+ },
126
+ "eslintConfig": {
127
+ "root": true,
128
+ "extends": [
129
+ "@react-native",
130
+ "prettier"
131
+ ],
132
+ "rules": {
133
+ "react/react-in-jsx-scope": "off",
134
+ "prettier/prettier": [
135
+ "error",
136
+ {
137
+ "quoteProps": "consistent",
138
+ "singleQuote": true,
139
+ "tabWidth": 2,
140
+ "trailingComma": "es5",
141
+ "useTabs": false
142
+ }
143
+ ]
144
+ }
145
+ },
146
+ "eslintIgnore": [
147
+ "node_modules/",
148
+ "lib/"
149
+ ],
150
+ "prettier": {
151
+ "quoteProps": "consistent",
152
+ "singleQuote": true,
153
+ "tabWidth": 2,
154
+ "trailingComma": "es5",
155
+ "useTabs": false
156
+ },
157
+ "react-native-builder-bob": {
158
+ "source": "src",
159
+ "output": "lib",
160
+ "targets": [
161
+ [
162
+ "commonjs",
163
+ {
164
+ "esm": true
165
+ }
166
+ ],
167
+ [
168
+ "module",
169
+ {
170
+ "esm": true
171
+ }
172
+ ],
173
+ [
174
+ "typescript",
175
+ {
176
+ "project": "tsconfig.build.json",
177
+ "esm": true
178
+ }
179
+ ]
180
+ ]
181
+ },
182
+ "create-react-native-library": {
183
+ "type": "view-legacy",
184
+ "languages": "kotlin-swift",
185
+ "version": "0.41.2"
186
+ }
187
+ }
@@ -0,0 +1,44 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-spalla-player"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => min_ios_version_supported }
15
+ s.source = { :git => "https://github.com/taghos/framework-sdk-spalla-react-native.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+
19
+ s.dependency "SpallaSDK", "~> 0.7.4"
20
+
21
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
22
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
23
+ if respond_to?(:install_modules_dependencies, true)
24
+ install_modules_dependencies(s)
25
+ else
26
+ s.dependency "React-Core"
27
+
28
+ # Don't install the dependencies when we run `pod install` in the old architecture.
29
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
30
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
31
+ s.pod_target_xcconfig = {
32
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
33
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
34
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
35
+ }
36
+ s.dependency "React-RCTFabric"
37
+ s.dependency "React-Codegen"
38
+ s.dependency "RCT-Folly"
39
+ s.dependency "RCTRequired"
40
+ s.dependency "RCTTypeSafety"
41
+ s.dependency "ReactCommon/turbomodule/core"
42
+ end
43
+ end
44
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,107 @@
1
+ import React from 'react';
2
+ import {
3
+ requireNativeComponent,
4
+ type ViewStyle,
5
+ NativeModules,
6
+ findNodeHandle,
7
+ } from 'react-native';
8
+
9
+ interface RNSpallaPlayerProps {
10
+ children?: React.ReactNode;
11
+ style?: ViewStyle;
12
+ ref?: (ref: any) => void;
13
+ }
14
+
15
+ const RNSpallaPlayer =
16
+ requireNativeComponent<RNSpallaPlayerProps>('RNSpallaPlayer');
17
+
18
+ const RNSpallaPlayerModule = NativeModules.RNSpallaPlayer;
19
+
20
+ interface PlayerEventTimeUpdate {
21
+ event: 'timeUpdate';
22
+ time: number;
23
+ }
24
+
25
+ interface PlayerEventDurationUpdate {
26
+ event: 'durationUpdate';
27
+ duration: number;
28
+ }
29
+
30
+ interface PlayerEvent {
31
+ event:
32
+ | 'play'
33
+ | 'pause'
34
+ | 'ended'
35
+ | 'muted'
36
+ | 'unmuted'
37
+ | 'buffering'
38
+ | 'playing';
39
+ }
40
+
41
+ interface Props {
42
+ style?: ViewStyle;
43
+ children?: React.ReactNode;
44
+ hideUI?: boolean;
45
+ contentId: string;
46
+ muted?: boolean;
47
+ autoplay?: boolean;
48
+ onPlayerEvent?: (event: {
49
+ nativeEvent:
50
+ | PlayerEventTimeUpdate
51
+ | PlayerEvent
52
+ | PlayerEventDurationUpdate;
53
+ }) => void;
54
+ }
55
+
56
+ export const play = (ref: any) => {
57
+ const handle = findNodeHandle(ref);
58
+ RNSpallaPlayerModule.play(handle);
59
+ };
60
+
61
+ export const pause = (ref: any) => {
62
+ const handle = findNodeHandle(ref);
63
+ RNSpallaPlayerModule.pause(handle);
64
+ };
65
+
66
+ export const seekTo = (ref: any, time: number) => {
67
+ const handle = findNodeHandle(ref);
68
+ RNSpallaPlayerModule.seekTo(handle, time);
69
+ };
70
+
71
+ //export default SpallaPlayer;
72
+
73
+ class SpallaPlayer extends React.Component<Props> {
74
+ _player = null;
75
+
76
+ _setRef = (ref: any) => {
77
+ this._player = ref;
78
+ };
79
+
80
+ render() {
81
+ const { style } = this.props;
82
+
83
+ //const {maxHeight} = this.state;
84
+
85
+ return (
86
+ <RNSpallaPlayer {...this.props} ref={this._setRef} style={style}>
87
+ {this.props.children}
88
+ </RNSpallaPlayer>
89
+ );
90
+ }
91
+
92
+ play = () => {
93
+ const handle = findNodeHandle(this._player);
94
+ RNSpallaPlayerModule.play(handle);
95
+ };
96
+
97
+ pause = () => {
98
+ const handle = findNodeHandle(this._player);
99
+ RNSpallaPlayerModule.pause(handle);
100
+ };
101
+ }
102
+
103
+ export const initialize = (token: String, applicationId: String | null) => {
104
+ RNSpallaPlayerModule.initialize(token, applicationId);
105
+ };
106
+
107
+ export default SpallaPlayer;