diff --git a/Info.plist b/Info.plist
new file mode 100644
index 0000000..550e6a4
--- /dev/null
+++ b/Info.plist
@@ -0,0 +1,13 @@
+
+
+
+
+ NSAppTransportSecurity
+
+ NSAllowsArbitraryLoads
+
+ NSAllowsArbitraryLoadsInWebContent
+
+
+
+
diff --git a/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/Info.plist b/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/Info.plist
index 1041b0f..550e6a4 100644
--- a/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/Info.plist
+++ b/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/Info.plist
@@ -2,9 +2,12 @@
- LSApplicationQueriesSchemes
-
- cydia
-
+ NSAppTransportSecurity
+
+ NSAllowsArbitraryLoads
+
+ NSAllowsArbitraryLoadsInWebContent
+
+
diff --git a/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/index.uts b/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/index.uts
index c9e0cbd..71c24a0 100644
--- a/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/index.uts
+++ b/uni_modules/xhj-tencent-xp2p/utssdk/app-ios/index.uts
@@ -4,26 +4,41 @@
import { Result } from '../interface.uts'
+const resolverMap = new Map void>()
+
function avRecvHandle(
id: Optional>,
recv_buf: Optional>,
recv_len: Int
-) {
- if (id != null) {
- const idString = P2PConversionHelper.cStringToString(id)
- // console.log(`avRecvHandle: ${idString}`)
- }
-}
+) {}
function msgHandle(
id: Optional>,
type: XP2PType,
msg: Optional>
): Optional> {
- 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>,
recv_len: Int
): Optional> {
- 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 {
+ const deviceId = `${productId}/${deviceName}`
return new Promise((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)
}
})
}