mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2025-12-21 05:20:06 -06:00
Local DNS resolution Fails (#367)
Fixes an issue where connecting via a local domain wasn't possible
This commit is contained in:
@@ -179,6 +179,7 @@ This app was designed with me and my dad in mind. I wanted us to have a sleek, o
|
||||
|
||||
[Jellyfin SDK](https://typescript-sdk.jellyfin.org/)\
|
||||
[Tanstack Query](https://tanstack.com/query/latest/docs/framework/react/react-native)\
|
||||
[React Native DNS Lookup](https://github.com/tableau/react-native-dns-lookup)\
|
||||
[React Native File Access](https://github.com/alpha0010/react-native-file-access)\
|
||||
[React Native MMKV](https://github.com/mrousavy/react-native-mmkv)\
|
||||
[React Native OTA Hot Update](https://github.com/vantuan88291/react-native-ota-hot-update)\
|
||||
|
||||
@@ -32,9 +32,24 @@
|
||||
<true/>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
<key>NSAllowsLocalNetworkingUsageDescription</key>
|
||||
<dict>
|
||||
<key>NSATSExceptionThirdPartyServiceConnectionUsage</key>
|
||||
<dict>
|
||||
<key>NSATSExceptionThirdPartyServiceConnectionPurpose</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>NSThirdPartyMediaStreaming</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>NSAllowsArbitraryLoadsForMedia</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>${PRODUCT_NAME} uses the local network to connect to one's Jellyfin server for streaming music</string>
|
||||
<string>${PRODUCT_NAME} uses the local network to connect to one's Jellyfin server for streaming music</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>UIAppFonts</key>
|
||||
|
||||
@@ -1897,6 +1897,8 @@ PODS:
|
||||
- Yoga
|
||||
- RNDeviceInfo (14.0.4):
|
||||
- React-Core
|
||||
- RNDnsLookup (1.0.6):
|
||||
- React
|
||||
- RNFastImage (8.6.3):
|
||||
- React-Core
|
||||
- SDWebImage (~> 5.11.1)
|
||||
@@ -2271,6 +2273,7 @@ DEPENDENCIES:
|
||||
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
|
||||
- "RNCMaskedView (from `../node_modules/@react-native-masked-view/masked-view`)"
|
||||
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
|
||||
- RNDnsLookup (from `../node_modules/react-native-dns-lookup`)
|
||||
- RNFastImage (from `../node_modules/react-native-fast-image`)
|
||||
- RNFS (from `../node_modules/react-native-fs`)
|
||||
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
|
||||
@@ -2455,6 +2458,8 @@ EXTERNAL SOURCES:
|
||||
:path: "../node_modules/@react-native-masked-view/masked-view"
|
||||
RNDeviceInfo:
|
||||
:path: "../node_modules/react-native-device-info"
|
||||
RNDnsLookup:
|
||||
:path: "../node_modules/react-native-dns-lookup"
|
||||
RNFastImage:
|
||||
:path: "../node_modules/react-native-fast-image"
|
||||
RNFS:
|
||||
@@ -2557,6 +2562,7 @@ SPEC CHECKSUMS:
|
||||
ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0
|
||||
RNCMaskedView: ae521efb1c6c2b183ae0f8479487db03c826184c
|
||||
RNDeviceInfo: d863506092aef7e7af3a1c350c913d867d795047
|
||||
RNDnsLookup: db4a89381b80ec1a5153088518d2c4f8e51f2521
|
||||
RNFastImage: 462a183c4b0b6b26fdfd639e1ed6ba37536c3b87
|
||||
RNFS: 89de7d7f4c0f6bafa05343c578f61118c8282ed8
|
||||
RNGestureHandler: ebef699ea17e7c0006c1074e1e423ead60ce0121
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
"react-native-blob-util": "^0.21.2",
|
||||
"react-native-carplay": "^2.4.1-beta.0",
|
||||
"react-native-device-info": "^14.0.4",
|
||||
"react-native-dns-lookup": "^1.0.6",
|
||||
"react-native-draggable-flatlist": "^4.0.3",
|
||||
"react-native-fast-image": "^8.6.3",
|
||||
"react-native-fs": "^2.20.0",
|
||||
@@ -129,4 +130,4 @@
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import Toast from 'react-native-toast-message'
|
||||
import { useJellifyContext } from '../../../providers'
|
||||
import { useSettingsContext } from '../../../providers/Settings'
|
||||
import Icon from '../../Global/components/icon'
|
||||
import { PublicSystemInfo } from '@jellyfin/sdk/lib/generated-client/models'
|
||||
import { getIpAddressesForHostname } from 'react-native-dns-lookup'
|
||||
|
||||
export default function ServerAddress({
|
||||
navigation,
|
||||
@@ -35,7 +37,7 @@ export default function ServerAddress({
|
||||
}, [])
|
||||
|
||||
const useServerMutation = useMutation({
|
||||
mutationFn: () => {
|
||||
mutationFn: async () => {
|
||||
console.debug(`Connecting to ${useHttps ? https : http}${serverAddress}`)
|
||||
|
||||
const jellyfin = new Jellyfin(JellyfinInfo)
|
||||
@@ -44,20 +46,63 @@ export default function ServerAddress({
|
||||
|
||||
const api = jellyfin.createApi(`${useHttps ? https : http}${serverAddress}`)
|
||||
|
||||
return getSystemApi(api).getPublicSystemInfo()
|
||||
const connectViaHostnamePromise = () =>
|
||||
new Promise<PublicSystemInfo>((resolve, reject) => {
|
||||
getSystemApi(api)
|
||||
.getPublicSystemInfo()
|
||||
.then((response) => {
|
||||
if (!response.data.Version)
|
||||
return reject(
|
||||
new Error(
|
||||
'Jellyfin instance did not respond to our hostname request',
|
||||
),
|
||||
)
|
||||
return resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('An error occurred getting public system info', error)
|
||||
return reject(new Error('Unable to connect to Jellyfin via hostname'))
|
||||
})
|
||||
})
|
||||
|
||||
const ipAddress = await getIpAddressesForHostname(serverAddress.split(':')[0])
|
||||
|
||||
const ipAddressApi = jellyfin.createApi(
|
||||
`${useHttps ? https : http}${ipAddress[0]}:${serverAddress.split(':')[1]}`,
|
||||
)
|
||||
const connectViaLocalNetworkPromise = () =>
|
||||
new Promise<PublicSystemInfo>((resolve, reject) => {
|
||||
getSystemApi(ipAddressApi)
|
||||
.getPublicSystemInfo()
|
||||
.then((response) => {
|
||||
if (!response.data.Version)
|
||||
return reject(
|
||||
new Error(
|
||||
'Jellyfin instance did not respond to our IP Address request',
|
||||
),
|
||||
)
|
||||
return resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('An error occurred getting public system info', error)
|
||||
return reject(new Error('Unable to connect to Jellyfin via IP Address'))
|
||||
})
|
||||
})
|
||||
|
||||
return connectViaHostnamePromise().catch(() => connectViaLocalNetworkPromise())
|
||||
},
|
||||
onSuccess: (publicSystemInfoResponse) => {
|
||||
if (!publicSystemInfoResponse.data.Version)
|
||||
if (!publicSystemInfoResponse.Version)
|
||||
throw new Error('Jellyfin instance did not respond')
|
||||
|
||||
console.log(`Connected to Jellyfin ${publicSystemInfoResponse.data.Version!}`)
|
||||
console.log(`Connected to Jellyfin ${publicSystemInfoResponse.Version!}`)
|
||||
|
||||
const server: JellifyServer = {
|
||||
url: `${useHttps ? https : http}${serverAddress!}`,
|
||||
address: serverAddress!,
|
||||
name: publicSystemInfoResponse.data.ServerName!,
|
||||
version: publicSystemInfoResponse.data.Version!,
|
||||
startUpComplete: publicSystemInfoResponse.data.StartupWizardCompleted!,
|
||||
name: publicSystemInfoResponse.ServerName!,
|
||||
version: publicSystemInfoResponse.Version!,
|
||||
startUpComplete: publicSystemInfoResponse.StartupWizardCompleted!,
|
||||
}
|
||||
|
||||
setServer(server)
|
||||
|
||||
@@ -8139,6 +8139,11 @@ react-native-device-info@^14.0.4:
|
||||
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-14.0.4.tgz#56b24ace9ff29a66bdfc667209086421ed6cfdce"
|
||||
integrity sha512-NX0wMAknSDBeFnEnSFQ8kkAcQrFHrG4Cl0mVjoD+0++iaKrOupiGpBXqs8xR0SeJyPC5zpdPl4h/SaBGly6UxA==
|
||||
|
||||
react-native-dns-lookup@^1.0.6:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/react-native-dns-lookup/-/react-native-dns-lookup-1.0.6.tgz#dc170ff2d4f5a0b1ff2f6ed8d07912192a52b20b"
|
||||
integrity sha512-47pdg4h50CEume23HzUs9FwhCqsXGYtXIRRnb0olY62ThifQGVN0eETRenY4YaKv4g9jIt1GVKDTSkH//uXXRg==
|
||||
|
||||
react-native-draggable-flatlist@^4.0.3:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/react-native-draggable-flatlist/-/react-native-draggable-flatlist-4.0.3.tgz#eb0bb3149059f48855b53aeb9728ab2eb361e4db"
|
||||
|
||||
Reference in New Issue
Block a user