diff --git a/.gitignore b/.gitignore index d3b53df..4c34e95 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ android.iml # Cocoapods # example/ios/Pods +example/ios/.xcode.env.local # Ruby example/vendor/ diff --git a/example/ios/FindLocalDevicesExample.xcodeproj/project.pbxproj b/example/ios/FindLocalDevicesExample.xcodeproj/project.pbxproj index 8cae072..faea348 100644 --- a/example/ios/FindLocalDevicesExample.xcodeproj/project.pbxproj +++ b/example/ios/FindLocalDevicesExample.xcodeproj/project.pbxproj @@ -413,6 +413,7 @@ baseConfigurationReference = 5826AF35579CB8523C3F6260 /* Pods-FindLocalDevicesExample-FindLocalDevicesExampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + DEVELOPMENT_TEAM = TGL8X23Y88; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -441,6 +442,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; + DEVELOPMENT_TEAM = TGL8X23Y88; INFOPLIST_FILE = FindLocalDevicesExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -466,7 +468,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 443N9AHV6P; + DEVELOPMENT_TEAM = TGL8X23Y88; ENABLE_BITCODE = NO; INFOPLIST_FILE = FindLocalDevicesExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -494,7 +496,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 443N9AHV6P; + DEVELOPMENT_TEAM = TGL8X23Y88; INFOPLIST_FILE = FindLocalDevicesExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -582,10 +584,7 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = false; @@ -653,10 +652,7 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = false; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 368ea3e..80398ae 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -911,7 +911,7 @@ PODS: - React-Mapbuffer (0.73.6): - glog - React-debug - - react-native-find-local-devices (2.0.11): + - react-native-find-local-devices (2.0.12): - glog - RCT-Folly (= 2022.05.16.00) - React-Core @@ -1308,7 +1308,7 @@ SPEC CHECKSUMS: React-jsinspector: 85583ef014ce53d731a98c66a0e24496f7a83066 React-logger: 3eb80a977f0d9669468ef641a5e1fabbc50a09ec React-Mapbuffer: 84ea43c6c6232049135b1550b8c60b2faac19fab - react-native-find-local-devices: 6f376c462282b0cfa6ec6383b1a6210400ee55b5 + react-native-find-local-devices: c18479978549629f1a6ca878f27b75efd4906a14 React-nativeconfig: b4d4e9901d4cabb57be63053fd2aa6086eb3c85f React-NativeModulesApple: ae99dc0e80c9027f54572c45635449fbdc36e4f1 React-perflogger: 5f49905de275bac07ac7ea7f575a70611fa988f2 @@ -1334,4 +1334,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 2b0d399bfd4ebfbe27ac21cd2e6de729af603252 -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/example/src/App.tsx b/example/src/App.tsx index 9d28c21..edc34c1 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react'; -import { Button, SafeAreaView, StyleSheet, Text, View } from 'react-native'; +import React, { useEffect, useState } from 'react'; +import { Button, StyleSheet, Text, View } from 'react-native'; import PortScanner, { type IDevice } from 'react-native-find-local-devices'; const styles = StyleSheet.create({ @@ -30,40 +30,46 @@ const styles = StyleSheet.create({ export default function App() { const [deviceFound, setDeviceFound] = useState([]); const [isFinished, setIsFinished] = useState(false); + const [scanner, setScanner] = useState(null); const [checkedDevice, setCheckedDevice] = useState(null); - const scanner = new PortScanner({ - timeout: 40, - ports: [78999], - onDeviceFound: (device) => { - console.log('Found device!', device); - setDeviceFound((prev) => [...prev, device]); - }, - onFinish: (devices) => { - console.log('Finished scanning', devices); - scanner.stop(); - setIsFinished(true); - setCheckedDevice(null); - }, - onCheck: (device) => { - console.log('Checking IP: ', device.ip, device.port); - setCheckedDevice(device); - }, - onNoDevices: () => { - console.log('Done without results!'); - setIsFinished(true); - setCheckedDevice(null); - }, - onError: (error) => { - // Handle error messages for each socket connection - console.log('Error', error); - }, - }); + const init = () => { + setScanner( + new PortScanner({ + timeout: 40, + ports: [50001], + onDeviceFound: (device) => { + console.log('Found device!', device); + setDeviceFound((prev) => [...prev, device]); + }, + onFinish: (devices) => { + console.log('Finished scanning', devices); + setIsFinished(true); + setCheckedDevice(null); + }, + onCheck: (device) => { + console.log('Checking IP: ', device.ip, device.port); + setCheckedDevice(device); + }, + onNoDevices: () => { + console.log('Done without results!'); + setIsFinished(true); + setCheckedDevice(null); + }, + onError: (error) => { + // Handle error messages for each socket connection + console.log('Error', error); + }, + }) + ); + }; + + useEffect(() => { + init(); + }, []); const start = () => { console.log('init'); - setDeviceFound([]); - setIsFinished(false); scanner?.start(); }; @@ -72,14 +78,16 @@ export default function App() { setCheckedDevice(null); setIsFinished(false); setDeviceFound([]); + setScanner(null); + init(); }; return ( - + Wi-Fi connection is required! {!checkedDevice && ( -