blix-expo-settings 0.1.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/.eslintrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['universe/native', 'universe/web'],
4
+ ignorePatterns: ['build'],
5
+ };
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # expo-settings
2
+
3
+ LiveStream
4
+
5
+ # API documentation
6
+
7
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/settings/)
8
+ - [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/settings/)
9
+
10
+ # Installation in managed Expo projects
11
+
12
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
13
+
14
+ # Installation in bare React Native projects
15
+
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
+
18
+ ### Add the package to your npm dependencies
19
+
20
+ ```
21
+ npm install expo-settings
22
+ ```
23
+
24
+ ### Configure for Android
25
+
26
+
27
+
28
+
29
+ ### Configure for iOS
30
+
31
+ Run `npx pod-install` after installing the npm package.
32
+
33
+ # Contributing
34
+
35
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing).
@@ -0,0 +1,43 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ group = 'expo.modules.settings'
4
+ version = '0.1.0'
5
+
6
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
+ apply from: expoModulesCorePlugin
8
+ applyKotlinExpoModulesCorePlugin()
9
+ useCoreDependencies()
10
+ useExpoPublishing()
11
+
12
+ // If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
13
+ // The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
14
+ // Most of the time, you may like to manage the Android SDK versions yourself.
15
+ def useManagedAndroidSdkVersions = false
16
+ if (useManagedAndroidSdkVersions) {
17
+ useDefaultAndroidSdkVersions()
18
+ } else {
19
+ buildscript {
20
+ // Simple helper that allows the root project to override versions declared by this library.
21
+ ext.safeExtGet = { prop, fallback ->
22
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
+ }
24
+ }
25
+ project.android {
26
+ compileSdkVersion safeExtGet("compileSdkVersion", 34)
27
+ defaultConfig {
28
+ minSdkVersion safeExtGet("minSdkVersion", 21)
29
+ targetSdkVersion safeExtGet("targetSdkVersion", 34)
30
+ }
31
+ }
32
+ }
33
+
34
+ android {
35
+ namespace "expo.modules.settings"
36
+ defaultConfig {
37
+ versionCode 1
38
+ versionName "0.1.0"
39
+ }
40
+ lintOptions {
41
+ abortOnError false
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -0,0 +1,50 @@
1
+ package expo.modules.settings
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+ import java.net.URL
6
+
7
+ class ExpoSettingsModule : Module() {
8
+ // Each module class must implement the definition function. The definition consists of components
9
+ // that describes the module's functionality and behavior.
10
+ // See https://docs.expo.dev/modules/module-api for more details about available components.
11
+ override fun definition() = ModuleDefinition {
12
+ // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
13
+ // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
14
+ // The module will be accessible from `requireNativeModule('ExpoSettings')` in JavaScript.
15
+ Name("ExpoSettings")
16
+
17
+ // Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
18
+ Constants(
19
+ "PI" to Math.PI
20
+ )
21
+
22
+ // Defines event names that the module can send to JavaScript.
23
+ Events("onChange")
24
+
25
+ // Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
26
+ Function("hello") {
27
+ "Hello world! 👋"
28
+ }
29
+
30
+ // Defines a JavaScript function that always returns a Promise and whose native code
31
+ // is by default dispatched on the different thread than the JavaScript runtime runs on.
32
+ AsyncFunction("setValueAsync") { value: String ->
33
+ // Send an event to JavaScript.
34
+ sendEvent("onChange", mapOf(
35
+ "value" to value
36
+ ))
37
+ }
38
+
39
+ // Enables the module to be used as a native view. Definition components that are accepted as part of
40
+ // the view definition: Prop, Events.
41
+ View(ExpoSettingsView::class) {
42
+ // Defines a setter for the `url` prop.
43
+ Prop("url") { view: ExpoSettingsView, url: URL ->
44
+ view.webView.loadUrl(url.toString())
45
+ }
46
+ // Defines an event that the view can send to JavaScript.
47
+ Events("onLoad")
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,30 @@
1
+ package expo.modules.settings
2
+
3
+ import android.content.Context
4
+ import android.webkit.WebView
5
+ import android.webkit.WebViewClient
6
+ import expo.modules.kotlin.AppContext
7
+ import expo.modules.kotlin.viewevent.EventDispatcher
8
+ import expo.modules.kotlin.views.ExpoView
9
+
10
+ class ExpoSettingsView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
11
+ // Creates and initializes an event dispatcher for the `onLoad` event.
12
+ // The name of the event is inferred from the value and needs to match the event name defined in the module.
13
+ private val onLoad by EventDispatcher()
14
+
15
+ // Defines a WebView that will be used as the root subview.
16
+ internal val webView = WebView(context).apply {
17
+ layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
18
+ webViewClient = object : WebViewClient() {
19
+ override fun onPageFinished(view: WebView, url: String) {
20
+ // Sends an event to JavaScript. Triggers a callback defined on the view component in JavaScript.
21
+ onLoad(mapOf("url" to url))
22
+ }
23
+ }
24
+ }
25
+
26
+ init {
27
+ // Adds the WebView to the view hierarchy.
28
+ addView(webView)
29
+ }
30
+ }
@@ -0,0 +1,5 @@
1
+ import { ViewStyle } from 'react-native/types';
2
+ export type ExpoSettingsViewProps = {
3
+ style?: ViewStyle;
4
+ };
5
+ //# sourceMappingURL=ExpoSettings.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettings.types.d.ts","sourceRoot":"","sources":["../src/ExpoSettings.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,MAAM,qBAAqB,GAAG;IAChC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExpoSettings.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettings.types.js","sourceRoot":"","sources":["../src/ExpoSettings.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ViewStyle } from 'react-native/types';\n\nexport type ExpoSettingsViewProps = {\n style?: ViewStyle;\n };\n "]}
@@ -0,0 +1,3 @@
1
+ declare const ExpoSettingsModule: any;
2
+ export default ExpoSettingsModule;
3
+ //# sourceMappingURL=ExpoSettingsModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettingsModule.d.ts","sourceRoot":"","sources":["../src/ExpoSettingsModule.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,kBAAkB,KAQnB,CAAC;AAEN,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Platform } from 'react-native';
2
+ import { requireNativeModule } from 'expo-modules-core';
3
+ // Só carrega o native module no iOS; no Android, exporta stubs vazios
4
+ const ExpoSettingsModule = Platform.OS === 'ios'
5
+ ? requireNativeModule('ExpoSettings')
6
+ : {
7
+ // Métodos usados pelo seu fluxo de live-stream
8
+ initializePreview: () => Promise.resolve(), // se for async, senão só () => {}
9
+ startStream: (_url, _streamKey) => { },
10
+ publishStream: (_url, _streamKey) => { },
11
+ stopStream: () => { },
12
+ };
13
+ export default ExpoSettingsModule;
14
+ //# sourceMappingURL=ExpoSettingsModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettingsModule.js","sourceRoot":"","sources":["../src/ExpoSettingsModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,sEAAsE;AACtE,MAAM,kBAAkB,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK;IAC9C,CAAC,CAAC,mBAAmB,CAAC,cAAc,CAAC;IACrC,CAAC,CAAC;QACE,+CAA+C;QAC/C,iBAAiB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAG,kCAAkC;QAC/E,WAAW,EAAE,CAAC,IAAY,EAAE,UAAkB,EAAE,EAAE,GAAE,CAAC;QACrD,aAAa,EAAE,CAAC,IAAY,EAAE,UAAkB,EAAE,EAAE,GAAE,CAAC;QACvD,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;KACrB,CAAC;AAEN,eAAe,kBAAkB,CAAC","sourcesContent":["import { Platform } from 'react-native';\nimport { requireNativeModule } from 'expo-modules-core';\n\n// Só carrega o native module no iOS; no Android, exporta stubs vazios\nconst ExpoSettingsModule = Platform.OS === 'ios'\n ? requireNativeModule('ExpoSettings')\n : {\n // Métodos usados pelo seu fluxo de live-stream\n initializePreview: () => Promise.resolve(), // se for async, senão só () => {}\n startStream: (_url: string, _streamKey: string) => {},\n publishStream: (_url: string, _streamKey: string) => {},\n stopStream: () => {},\n };\n\nexport default ExpoSettingsModule;\n\n"]}
@@ -0,0 +1,4 @@
1
+ import * as React from "react";
2
+ import { ExpoSettingsViewProps } from "./ExpoSettings.types";
3
+ export default function ExpoSettingsView(props: ExpoSettingsViewProps): React.JSX.Element;
4
+ //# sourceMappingURL=ExpoSettingsView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettingsView.d.ts","sourceRoot":"","sources":["../src/ExpoSettingsView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAK5B,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qBAEpE"}
@@ -0,0 +1,7 @@
1
+ import { requireNativeViewManager } from "expo-modules-core";
2
+ import * as React from "react";
3
+ const NativeView = requireNativeViewManager("ExpoSettings");
4
+ export default function ExpoSettingsView(props) {
5
+ return <NativeView {...props}/>;
6
+ }
7
+ //# sourceMappingURL=ExpoSettingsView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSettingsView.js","sourceRoot":"","sources":["../src/ExpoSettingsView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,UAAU,GACd,wBAAwB,CAAC,cAAc,CAAC,CAAC;AAEzC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAA4B;IACnE,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeViewManager } from \"expo-modules-core\";\nimport * as React from \"react\";\nimport {\n ExpoSettingsViewProps,\n} from \"./ExpoSettings.types\";\n\nconst NativeView: React.ComponentType<ExpoSettingsViewProps> =\n requireNativeViewManager(\"ExpoSettings\");\n\n export default function ExpoSettingsView(props: ExpoSettingsViewProps) {\n return <NativeView {...props} />;\n }\n"]}
@@ -0,0 +1,12 @@
1
+ import { Subscription } from "expo-modules-core";
2
+ import ExpoSettingsView from './ExpoSettingsView';
3
+ export { ExpoSettingsView };
4
+ export type LiveChangeEvent = {
5
+ status: "started" | "stopped" | "previewReady";
6
+ };
7
+ export declare function addLiveListener(listener: (event: LiveChangeEvent) => void): Subscription;
8
+ export declare function initializePreview(): void;
9
+ export declare function publishStream(url: String, streamKey: String): void;
10
+ export declare function stopStream(): void;
11
+ export declare function startStream(url: String, streamKey: String): void;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,cAAc,CAAC;CAChD,CAAC;AAEF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GACzC,YAAY,CAEd;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAGD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAElE;AAED,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAE/D"}
package/build/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { EventEmitter } from "expo-modules-core";
2
+ import ExpoSettingsModule from "./ExpoSettingsModule";
3
+ import ExpoSettingsView from './ExpoSettingsView';
4
+ const emitter = new EventEmitter(ExpoSettingsModule);
5
+ export { ExpoSettingsView };
6
+ export function addLiveListener(listener) {
7
+ return emitter.addListener("onStreamStatus", listener);
8
+ }
9
+ export function initializePreview() {
10
+ return ExpoSettingsModule.initializePreview();
11
+ }
12
+ // ← RENOMEADO startStream → publishStream, agora só publica
13
+ export function publishStream(url, streamKey) {
14
+ return ExpoSettingsModule.publishStream(url, streamKey);
15
+ }
16
+ export function stopStream() {
17
+ return ExpoSettingsModule.stopStream();
18
+ }
19
+ export function startStream(url, streamKey) {
20
+ return ExpoSettingsModule.startStream(url, streamKey);
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAM5B,MAAM,UAAU,eAAe,CAC7B,QAA0C;IAE1C,OAAO,OAAO,CAAC,WAAW,CAAkB,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,kBAAkB,CAAC,iBAAiB,EAAE,CAAC;AAChD,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,SAAiB;IAC1D,OAAO,kBAAkB,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,kBAAkB,CAAC,UAAU,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,SAAiB;IACxD,OAAO,kBAAkB,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { EventEmitter, Subscription } from \"expo-modules-core\";\nimport ExpoSettingsModule from \"./ExpoSettingsModule\";\nimport ExpoSettingsView from './ExpoSettingsView'; \n\nconst emitter = new EventEmitter(ExpoSettingsModule);\n\nexport { ExpoSettingsView }; \n\nexport type LiveChangeEvent = {\n status: \"started\" | \"stopped\" | \"previewReady\";\n};\n\nexport function addLiveListener(\n listener: (event: LiveChangeEvent) => void\n): Subscription {\n return emitter.addListener<LiveChangeEvent>(\"onStreamStatus\", listener);\n}\n\nexport function initializePreview(): void {\n return ExpoSettingsModule.initializePreview();\n}\n\n// ← RENOMEADO startStream → publishStream, agora só publica\nexport function publishStream(url: String, streamKey: String): void {\n return ExpoSettingsModule.publishStream(url, streamKey);\n}\n\nexport function stopStream(): void {\n return ExpoSettingsModule.stopStream();\n}\n\nexport function startStream(url: String, streamKey: String): void {\n return ExpoSettingsModule.startStream(url, streamKey);\n }\n \n"]}
@@ -0,0 +1,6 @@
1
+ {
2
+ "platforms": ["apple", "web"],
3
+ "apple": {
4
+ "modules": ["ExpoSettingsModule"]
5
+ }
6
+ }
@@ -0,0 +1,22 @@
1
+ Pod::Spec.new do |s|
2
+ s.name = 'ExpoSettings'
3
+ s.version = '1.0.0'
4
+ s.summary = 'A sample project summary'
5
+ s.description = 'A sample project description'
6
+ s.author = ''
7
+ s.homepage = 'https://docs.expo.dev/modules/'
8
+ s.platforms = { :ios => '13.4', :tvos => '13.4' }
9
+ s.source = { git: '' }
10
+ s.static_framework = true
11
+
12
+ s.dependency 'ExpoModulesCore'
13
+ s.dependency 'HaishinKit', '~> 1.9.8'
14
+
15
+ # Swift/Objective-C compatibility
16
+ s.pod_target_xcconfig = {
17
+ 'DEFINES_MODULE' => 'YES',
18
+ 'SWIFT_COMPILATION_MODE' => 'wholemodule'
19
+ }
20
+
21
+ s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
22
+ end
@@ -0,0 +1,177 @@
1
+ import ExpoModulesCore
2
+ import HaishinKit
3
+ import AVFoundation
4
+ import VideoToolbox
5
+
6
+ public class ExpoSettingsModule: Module {
7
+ private var rtmpConnection: RTMPConnection?
8
+ private var rtmpStream: RTMPStream?
9
+
10
+ public func definition() -> ModuleDefinition {
11
+ Name("ExpoSettings")
12
+
13
+ // Registra o view component para o admin se enxergar na live
14
+
15
+ View(ExpoSettingsView.self) {
16
+ // não precisa colocar nada aqui se você não tiver Props
17
+ }
18
+
19
+ Events("onStreamStatus")
20
+
21
+ Function("initializePreview") { () -> Void in
22
+ Task {
23
+ sendEvent("onStreamStatus", ["status": "previewInitializing"])
24
+
25
+ do {
26
+
27
+ // 0) Configura e ativa o AVAudioSession
28
+ let session = AVAudioSession.sharedInstance()
29
+ do {
30
+ try session.setCategory(.playAndRecord,
31
+ mode: .default,
32
+ options: [.defaultToSpeaker, .allowBluetooth])
33
+ try session.setActive(true)
34
+ } catch {
35
+ print("[ExpoSettings] AVAudioSession error:", error)
36
+ }
37
+
38
+ // 1) Conectar ao servidor RTMP, mas não publica
39
+ let connection = RTMPConnection()
40
+ self.rtmpConnection = connection
41
+
42
+ // 2) Criar RTMPStream, mas não publica pro servidor ainda
43
+ let stream = RTMPStream(connection: connection)
44
+ self.rtmpStream = stream
45
+ print("[ExpoSettings] RTMPStream initialized")
46
+
47
+ // 3) Configurar captura: frame rate e preset
48
+ stream.frameRate = 30
49
+ stream.sessionPreset = .medium
50
+ stream.configuration { captureSession in
51
+ captureSession.automaticallyConfiguresApplicationAudioSession = true
52
+ }
53
+
54
+ // 4) Configurar áudio: anexa microfone
55
+ if let audioDevice = AVCaptureDevice.default(for: .audio) {
56
+ print("[ExpoSettings] Attaching audio device")
57
+ stream.attachAudio(audioDevice)
58
+ } else {
59
+ print("[ExpoSettings] No audio device found")
60
+ }
61
+
62
+ // 5) Configurar vídeo: anexa câmera frontal
63
+ if let camera = AVCaptureDevice.default(.builtInWideAngleCamera,
64
+ for: .video,
65
+ position: .front) {
66
+ print("[ExpoSettings] Attaching camera device")
67
+ stream.attachCamera(camera) { videoUnit, error in
68
+ guard let unit = videoUnit else {
69
+ print("[ExpoSettings] attachCamera error:", error?.localizedDescription ?? "unknown")
70
+ return
71
+ }
72
+ unit.isVideoMirrored = true
73
+ unit.preferredVideoStabilizationMode = .standard
74
+ unit.colorFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
75
+
76
+ }
77
+ if let preview = await ExpoSettingsView.current {
78
+ print("[ExpoSettings] Attaching stream to preview view")
79
+ await preview.attachStream(stream)
80
+ } else {
81
+ print("[ExpoSettings] ERROR: Preview view not found!")
82
+ }
83
+ } else {
84
+ print("[ExpoSettings] No camera device found")
85
+ }
86
+
87
+ //6) Definir configurações de codec
88
+ print("[ExpoSettings] Setting audio and video codecs")
89
+ var audioSettings = AudioCodecSettings()
90
+ audioSettings.bitRate = 128 * 1000
91
+ stream.audioSettings = audioSettings
92
+
93
+ let videoSettings = VideoCodecSettings(
94
+ videoSize: .init(width: 720, height: 1280),
95
+ bitRate: 1500 * 1000,
96
+ profileLevel: kVTProfileLevel_H264_Baseline_3_1 as String,
97
+ scalingMode: .trim,
98
+ bitRateMode: .average,
99
+ maxKeyFrameIntervalDuration: 2,
100
+ allowFrameReordering: nil,
101
+ isHardwareEncoderEnabled: true
102
+ )
103
+ stream.videoSettings = videoSettings
104
+ }
105
+ sendEvent("onStreamStatus", ["status": "previewReady"])
106
+ }
107
+ }
108
+
109
+ Function("publishStream") { (url: String, streamKey: String) -> Void in
110
+ Task {
111
+
112
+ print("[ExpoSettings] Publishing stream to URL: \(url) with key: \(streamKey)")
113
+
114
+ sendEvent("onStreamStatus", ["status": "connecting"])
115
+
116
+ // se não houve initializePreview→recria a connection
117
+ if self.rtmpConnection == nil || self.rtmpStream == nil {
118
+ print("[ExpoSettings] WARNING: Connection or stream not initialized, creating new ones")
119
+ // Create new connection
120
+ let connection = RTMPConnection()
121
+ self.rtmpConnection = connection
122
+ connection.connect(url)
123
+
124
+ // Create new stream
125
+ let stream = RTMPStream(connection: connection)
126
+ self.rtmpStream = stream
127
+
128
+ // Attach to view if available
129
+ if let preview = await ExpoSettingsView.current {
130
+ await preview.attachStream(stream)
131
+ } else {
132
+ print("[ExpoSettings] ERROR: Preview view not found during publish!")
133
+ }
134
+ } else {
135
+ // Use existing connection
136
+ self.rtmpConnection?.connect(url)
137
+ }
138
+
139
+ sendEvent("onStreamStatus", ["status": "connected"])
140
+
141
+ sendEvent("onStreamStatus", ["status": "publishing"])
142
+ self.rtmpStream?.publish(streamKey)
143
+ print("[ExpoSettings] Stream published successfully")
144
+ sendEvent("onStreamStatus", ["status": "started"])
145
+ }
146
+ }
147
+
148
+ Function("stopStream") { () -> Void in
149
+ Task {
150
+ print("[ExpoSettings] stopStream called")
151
+
152
+ // Primeiro pare a publicação (se estiver publicando)
153
+ if let stream = self.rtmpStream {
154
+ print("[ExpoSettings] Stopping stream publication")
155
+ stream.close()
156
+
157
+ // Desanexa a câmera e o áudio para liberar recursos
158
+ stream.attachCamera(nil)
159
+ stream.attachAudio(nil)
160
+ }
161
+
162
+ // Depois feche a conexão RTMP
163
+ if let connection = self.rtmpConnection {
164
+ print("[ExpoSettings] Closing RTMP connection")
165
+ connection.close()
166
+ }
167
+
168
+ // Limpe as referências
169
+ self.rtmpStream = nil
170
+ self.rtmpConnection = nil
171
+
172
+ print("[ExpoSettings] Stream and connection closed and resources released")
173
+ sendEvent("onStreamStatus", ["status": "stopped"])
174
+ }
175
+ }
176
+ }
177
+ }
@@ -0,0 +1,42 @@
1
+ import ExpoModulesCore
2
+ import HaishinKit
3
+ import AVFoundation
4
+
5
+ public class ExpoSettingsView: ExpoView {
6
+
7
+ public static weak var current: ExpoSettingsView?
8
+
9
+ // A view de preview do HaishinKit
10
+ private let hkView: MTHKView = {
11
+ let view = MTHKView(frame: .zero)
12
+ view.videoGravity = .resizeAspectFill
13
+ return view
14
+ }()
15
+
16
+ required init(appContext: AppContext? = nil) {
17
+ super.init(appContext: appContext)
18
+ clipsToBounds = true
19
+ addSubview(hkView)
20
+ ExpoSettingsView.current = self
21
+ print("[ExpoSettingsView] View initialized and set as current")
22
+ }
23
+
24
+ override public func layoutSubviews() {
25
+ super.layoutSubviews()
26
+ hkView.frame = bounds
27
+ print("[ExpoSettingsView] Layout updated, frame: \(bounds)")
28
+ }
29
+
30
+ /// Conecta o RTMPStream a essa view (internamente já faz o attachCamera + renderização)
31
+ public func attachStream(_ stream: RTMPStream) {
32
+ print("[ExpoSettingsView] Attaching stream to view")
33
+ hkView.attachStream(stream)
34
+ }
35
+
36
+ deinit {
37
+ print("[ExpoSettingsView] View being deinitialized")
38
+ if ExpoSettingsView.current === self {
39
+ ExpoSettingsView.current = nil
40
+ }
41
+ }
42
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "blix-expo-settings",
3
+ "version": "0.1.0",
4
+ "description": "LiveStream",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "scripts": {
8
+ "build": "expo-module build",
9
+ "clean": "expo-module clean",
10
+ "lint": "expo-module lint",
11
+ "test": "expo-module test",
12
+ "prepare": "expo-module prepare",
13
+ "prepublishOnly": "expo-module prepublishOnly",
14
+ "expo-module": "expo-module",
15
+ "open:ios": "xed example/ios",
16
+ "open:android": "open -a \"Android Studio\" example/android"
17
+ },
18
+ "keywords": [
19
+ "react-native",
20
+ "expo",
21
+ "expo-settings",
22
+ "ExpoSettings"
23
+ ],
24
+ "repository": "https://github.com/BlixTechnology/expo-settings",
25
+ "bugs": {
26
+ "url": "https://github.com/BlixTechnology/expo-settings/issues"
27
+ },
28
+ "author": "Blix <blix.aplicativos@gmail.com> (https://github.com/BlixTechnology)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/BlixTechnology/expo-settings#readme",
31
+ "dependencies": {},
32
+ "devDependencies": {
33
+ "@types/react": "~19.0.0",
34
+ "expo-module-scripts": "^4.1.6",
35
+ "expo": "^50.0.21",
36
+ "react-native": "0.79.1"
37
+ },
38
+ "peerDependencies": {
39
+ "expo": "*",
40
+ "react": "*",
41
+ "react-native": "*"
42
+ }
43
+ }
@@ -0,0 +1,6 @@
1
+ import { ViewStyle } from 'react-native/types';
2
+
3
+ export type ExpoSettingsViewProps = {
4
+ style?: ViewStyle;
5
+ };
6
+
@@ -0,0 +1,16 @@
1
+ import { Platform } from 'react-native';
2
+ import { requireNativeModule } from 'expo-modules-core';
3
+
4
+ // Só carrega o native module no iOS; no Android, exporta stubs vazios
5
+ const ExpoSettingsModule = Platform.OS === 'ios'
6
+ ? requireNativeModule('ExpoSettings')
7
+ : {
8
+ // Métodos usados pelo seu fluxo de live-stream
9
+ initializePreview: () => Promise.resolve(), // se for async, senão só () => {}
10
+ startStream: (_url: string, _streamKey: string) => {},
11
+ publishStream: (_url: string, _streamKey: string) => {},
12
+ stopStream: () => {},
13
+ };
14
+
15
+ export default ExpoSettingsModule;
16
+
@@ -0,0 +1,12 @@
1
+ import { requireNativeViewManager } from "expo-modules-core";
2
+ import * as React from "react";
3
+ import {
4
+ ExpoSettingsViewProps,
5
+ } from "./ExpoSettings.types";
6
+
7
+ const NativeView: React.ComponentType<ExpoSettingsViewProps> =
8
+ requireNativeViewManager("ExpoSettings");
9
+
10
+ export default function ExpoSettingsView(props: ExpoSettingsViewProps) {
11
+ return <NativeView {...props} />;
12
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { EventEmitter, Subscription } from "expo-modules-core";
2
+ import ExpoSettingsModule from "./ExpoSettingsModule";
3
+ import ExpoSettingsView from './ExpoSettingsView';
4
+
5
+ const emitter = new EventEmitter(ExpoSettingsModule);
6
+
7
+ export { ExpoSettingsView };
8
+
9
+ export type LiveChangeEvent = {
10
+ status: "started" | "stopped" | "previewReady";
11
+ };
12
+
13
+ export function addLiveListener(
14
+ listener: (event: LiveChangeEvent) => void
15
+ ): Subscription {
16
+ return emitter.addListener<LiveChangeEvent>("onStreamStatus", listener);
17
+ }
18
+
19
+ export function initializePreview(): void {
20
+ return ExpoSettingsModule.initializePreview();
21
+ }
22
+
23
+ // ← RENOMEADO startStream → publishStream, agora só publica
24
+ export function publishStream(url: String, streamKey: String): void {
25
+ return ExpoSettingsModule.publishStream(url, streamKey);
26
+ }
27
+
28
+ export function stopStream(): void {
29
+ return ExpoSettingsModule.stopStream();
30
+ }
31
+
32
+ export function startStream(url: String, streamKey: String): void {
33
+ return ExpoSettingsModule.startStream(url, streamKey);
34
+ }
35
+
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ // @generated by expo-module-scripts
2
+ {
3
+ "extends": "expo-module-scripts/tsconfig.base",
4
+ "compilerOptions": {
5
+ "outDir": "./build"
6
+ },
7
+ "include": ["./src"],
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__rsc_tests__/*"]
9
+ }