133 lines
3.2 KiB
Plaintext
133 lines
3.2 KiB
Plaintext
/* eslint-disable */
|
|
// @ts-nocheck
|
|
// @ts-ignore-start
|
|
|
|
import { Result } from '../interface.uts'
|
|
|
|
export const startServiceFunction = async function (
|
|
appKey: string,
|
|
appSecret: string,
|
|
productId: string,
|
|
deviceName: string,
|
|
xp2pInfo: string
|
|
): Promise<Result> {
|
|
return new Promise<Result>((resolve, reject) => {
|
|
try {
|
|
const config = app_config_t()
|
|
config.server = UnsafePointer(strdup('')!)
|
|
config.ip = UnsafePointer(strdup('')!)
|
|
config.port = 20002
|
|
config.type = XP2P_PROTOCOL_AUTO
|
|
config.cross = false
|
|
|
|
const result = startService(`${productId}/${deviceName}`, productId, deviceName, config)
|
|
|
|
if (NSNumber(0) === result) {
|
|
const setP2PInfoResult = setDeviceXp2pInfo(`${productId}/${deviceName}`, xp2pInfo)
|
|
|
|
if (NSNumber(0) === setP2PInfoResult) {
|
|
let attempts = 0
|
|
const maxAttempts = 20
|
|
const interval: Int = 100
|
|
|
|
function pollForUrl() {
|
|
if (attempts >= maxAttempts) {
|
|
resolve({ code: -1, data: {}, message: '获取播放URL超时' })
|
|
return
|
|
}
|
|
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()
|
|
} else {
|
|
resolve({ code: -1, data: {}, message: 'setDeviceXp2pInfo 调用失败' })
|
|
}
|
|
} else {
|
|
resolve({ code: -1, data: {}, message: 'startService 调用失败' })
|
|
}
|
|
} catch (error) {
|
|
console.log('startServiceFunction 报错', error)
|
|
resolve({
|
|
code: -1,
|
|
data: {},
|
|
message: error.toString()
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
export const stopServiceFunction = async function (id: string): Promise<Result> {
|
|
try {
|
|
await stopService(id)
|
|
return {
|
|
code: 0,
|
|
data: {},
|
|
message: '成功'
|
|
}
|
|
} catch (error) {
|
|
return {
|
|
code: -1,
|
|
data: {},
|
|
message: error.toString()
|
|
}
|
|
}
|
|
}
|
|
|
|
export const runSendServiceFunction = async function (
|
|
id: string,
|
|
cmd: string,
|
|
crypto: boolean
|
|
): Promise<Result> {
|
|
try {
|
|
// const result = await runSendService(id, cmd, crypto)
|
|
// console.log('开始发送服务', result)
|
|
return {
|
|
code: 0,
|
|
data: {},
|
|
message: '成功'
|
|
}
|
|
} catch (error) {
|
|
return {
|
|
code: -1,
|
|
data: {},
|
|
message: error.toString()
|
|
}
|
|
}
|
|
}
|
|
|
|
export const stopSendServiceFunction = async function (id: string): Promise<Result> {
|
|
try {
|
|
// const nullPointer = P2PPointerHelper.createNullPointer()
|
|
// const result = await stopSendService(id, nullPointer)
|
|
// console.log('停止发送服务', result)
|
|
return {
|
|
code: 0,
|
|
data: {},
|
|
message: '成功'
|
|
}
|
|
} catch (error) {
|
|
return {
|
|
code: -1,
|
|
data: {},
|
|
message: error.toString()
|
|
}
|
|
}
|
|
}
|
|
|
|
// @ts-ignore-end
|