feat: 修改获取url逻辑
This commit is contained in:
parent
5859f78b36
commit
b38e82907a
13
Info.plist
Normal file
13
Info.plist
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
<key>NSAllowsArbitraryLoadsInWebContent</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@ -2,9 +2,12 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>cydia</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
<key>NSAllowsArbitraryLoadsInWebContent</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@ -4,26 +4,41 @@
|
||||
|
||||
import { Result } from '../interface.uts'
|
||||
|
||||
const resolverMap = new Map<string, (value: Result) => void>()
|
||||
|
||||
function avRecvHandle(
|
||||
id: Optional<UnsafePointer<Int8>>,
|
||||
recv_buf: Optional<UnsafeMutablePointer<UInt8>>,
|
||||
recv_len: Int
|
||||
) {
|
||||
if (id != null) {
|
||||
const idString = P2PConversionHelper.cStringToString(id)
|
||||
// console.log(`avRecvHandle: ${idString}`)
|
||||
}
|
||||
}
|
||||
) {}
|
||||
|
||||
function msgHandle(
|
||||
id: Optional<UnsafePointer<Int8>>,
|
||||
type: XP2PType,
|
||||
msg: Optional<UnsafePointer<Int8>>
|
||||
): Optional<UnsafePointer<Int8>> {
|
||||
const idString = id != null ? P2PConversionHelper.cStringToString(id) : ''
|
||||
const msgString = msg != null ? P2PConversionHelper.cStringToString(msg) : ''
|
||||
if (type == XP2PTypeLog) {
|
||||
console.log(`${msgString}`)
|
||||
if (type.rawValue == 1004) {
|
||||
const idString = id != null ? P2PConversionHelper.cStringToString(id) : null
|
||||
if (idString != null) {
|
||||
const resolver = resolverMap.get(idString!)
|
||||
if (resolver != null) {
|
||||
const urlResult = delegateHttpFlv(idString!)
|
||||
if (urlResult != null) {
|
||||
const urlString = P2PConversionHelper.cStringToString(urlResult)
|
||||
if (urlString != null && urlString != '') {
|
||||
resolver!({
|
||||
code: 0,
|
||||
data: { url: urlString },
|
||||
message: '成功'
|
||||
})
|
||||
resolverMap.delete(idString!)
|
||||
return null
|
||||
}
|
||||
}
|
||||
resolver!({ code: -1, data: {}, message: '获取播放URL失败' })
|
||||
resolverMap.delete(idString!)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@ -33,10 +48,10 @@ function deviceDataHandle(
|
||||
recv_buf: Optional<UnsafeMutablePointer<UInt8>>,
|
||||
recv_len: Int
|
||||
): Optional<UnsafeMutablePointer<Int8>> {
|
||||
if (id != null) {
|
||||
const idString = P2PConversionHelper.cStringToString(id)
|
||||
// console.log(`deviceDataHandle: ${idString}, len: ${recv_len}`)
|
||||
}
|
||||
// if (id != null) {
|
||||
// const idString = P2PConversionHelper.cStringToString(id)
|
||||
// // console.log(`deviceDataHandle: ${idString}, len: ${recv_len}`)
|
||||
// }
|
||||
return null
|
||||
}
|
||||
|
||||
@ -47,7 +62,9 @@ export const startServiceFunction = async function (
|
||||
deviceName: string,
|
||||
xp2pInfo: string
|
||||
): Promise<Result> {
|
||||
const deviceId = `${productId}/${deviceName}`
|
||||
return new Promise<Result>((resolve, reject) => {
|
||||
resolverMap.set(deviceId, resolve)
|
||||
try {
|
||||
const config = app_config_t()
|
||||
config.server = UnsafePointer(strdup('')!)
|
||||
@ -59,45 +76,25 @@ export const startServiceFunction = async function (
|
||||
// 设置回调
|
||||
setUserCallbackToXp2p(avRecvHandle, msgHandle, deviceDataHandle)
|
||||
|
||||
const result = startService(`${productId}/${deviceName}`, productId, deviceName, config)
|
||||
const result = startService(deviceId, productId, deviceName, config)
|
||||
|
||||
if (NSNumber(0) === result) {
|
||||
const setP2PInfoResult = setDeviceXp2pInfo(`${productId}/${deviceName}`, xp2pInfo)
|
||||
const setP2PInfoResult = setDeviceXp2pInfo(deviceId, xp2pInfo)
|
||||
|
||||
if (NSNumber(0) === setP2PInfoResult) {
|
||||
let attempts = 0
|
||||
const maxAttempts = 20
|
||||
const interval: Int = 100
|
||||
|
||||
function pollForUrl() {
|
||||
if (attempts >= maxAttempts) {
|
||||
setTimeout(() => {
|
||||
if (resolverMap.has(deviceId)) {
|
||||
resolve({ code: -1, data: {}, message: '获取播放URL超时' })
|
||||
return
|
||||
resolverMap.delete(deviceId)
|
||||
}
|
||||
attempts++
|
||||
|
||||
const urlResult = delegateHttpFlv(`${productId}/${deviceName}`)
|
||||
|
||||
if (urlResult != null) {
|
||||
const urlString = P2PConversionHelper.cStringToString(urlResult)
|
||||
|
||||
if (urlString != null && urlString != '') {
|
||||
resolve({
|
||||
code: 0,
|
||||
data: { url: urlString },
|
||||
message: '成功'
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
setTimeout(pollForUrl, interval)
|
||||
}
|
||||
pollForUrl()
|
||||
}, 20000)
|
||||
} else {
|
||||
resolve({ code: -1, data: {}, message: 'setDeviceXp2pInfo 调用失败' })
|
||||
resolverMap.delete(deviceId)
|
||||
}
|
||||
} else {
|
||||
resolve({ code: -1, data: {}, message: 'startService 调用失败' })
|
||||
resolverMap.delete(deviceId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('startServiceFunction 报错', error)
|
||||
@ -106,6 +103,7 @@ export const startServiceFunction = async function (
|
||||
data: {},
|
||||
message: error.toString()
|
||||
})
|
||||
resolverMap.delete(deviceId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user