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