fix: 视频优化
This commit is contained in:
		
							parent
							
								
									5efb9cd735
								
							
						
					
					
						commit
						17c8d88345
					
				| @ -12,7 +12,7 @@ export const GlobalConfig: GlobalConfigType = { | ||||
|   commonFileWriteAddress: '/mnt/hmdfs/100/account/device_view/local/files/duolun', | ||||
|   picSavePath: '/storage/cloud/100/files/Photo/', | ||||
|   videoSavePath: '/storage/cloud/100/files/Videos/', | ||||
|   host: 'http://172.37.55.192:8082', | ||||
|   host: 'http://192.168.32.105:8089', | ||||
|   modelNo: "3", | ||||
|   version: { | ||||
|     //杭州 | ||||
|  | ||||
| @ -10,9 +10,9 @@ import { JudgeConfigType } from '../model' | ||||
| 
 | ||||
| 
 | ||||
| //考试回放开关 | ||||
| export const JudgeConfig:JudgeConfigType = { | ||||
| export const JudgeConfig: JudgeConfigType = { | ||||
|   //本地目录开关 | ||||
|   isTrajectoryOpen: true, | ||||
|   isTrajectoryOpen: false, | ||||
|   //是否开启拍照 | ||||
|   isPhotoOpen: true, | ||||
|   //扣分语音是否强制开启 | ||||
|  | ||||
| @ -20,6 +20,7 @@ import CardComponent from './Index/Card'; | ||||
| import BottomMessageComponent from './Index/BottomMessage'; | ||||
| import LoadingComponent from './Index/Loading'; | ||||
| import Prompt from '@system.prompt'; | ||||
| import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | ||||
| 
 | ||||
| 
 | ||||
| @Entry | ||||
| @ -64,7 +65,9 @@ struct Index { | ||||
|     this.ratio = AppStorage.get<BaseInfoType>('baseInfo')?.ratio || 1.4 | ||||
|     this.angle = 0 | ||||
|     AppStorage.set('lsh', '1111111111111') | ||||
| 
 | ||||
|     JudgeEmitterInstance.init() | ||||
| 
 | ||||
|     GetSyncData<MASYSSETTableType>("MA_SYSSET").then((res: MASYSSETTableType[]) => { | ||||
|       res.forEach((element) => { | ||||
|         if (element.v_no === "305") { | ||||
| @ -83,6 +86,12 @@ struct Index { | ||||
|     AppStorage.setOrCreate('singlePlay', false) | ||||
|     this.num = 0 | ||||
|     AppStorage.setOrCreate('lsh', '1111111111111') | ||||
|     DifferentialSignal.init(); | ||||
|     DifferentialSignal.sendData() | ||||
|     DifferentialSignal.getData((data: ArrayBuffer) => { | ||||
|       console.log("Received differential signal data:", data.byteLength, "bytes") | ||||
|        | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 联网考试逻辑处理 | ||||
|  | ||||
| @ -96,7 +96,7 @@ struct Index { | ||||
|             this.fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param)) | ||||
|             AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", param) | ||||
|             const host = `http://${param.centerIp}:${param.centerPort}` | ||||
|             console.log("中心host",host) | ||||
|             console.log("中心host", host) | ||||
|             AppStorage.setOrCreate<string>("host", host) | ||||
|             ethernet.setIfaceConfig("eth0", { | ||||
|               mode: ethernet.IPSetMode.STATIC, | ||||
|  | ||||
| @ -10,7 +10,7 @@ export default class TcpClient { | ||||
|   private oppositeIp: string = '' | ||||
|   private oppositeIpPort: string = '' | ||||
|   private tcpSendNum: number = 0 | ||||
|   private tcp: socket.TCPSocket = null | ||||
|   private tcp: socket.TCPSocket = socket.constructTCPSocketInstance() | ||||
|   private events: Array<Function> = [] | ||||
| 
 | ||||
|   constructor() { | ||||
| @ -20,59 +20,102 @@ export default class TcpClient { | ||||
|     return TcpClient.instance | ||||
|   } | ||||
| 
 | ||||
|   init(tcpLocalIp: string, tcpLocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) { | ||||
|   // 初始化tcp连接 | ||||
|   async init(tcpLocalIp: string, tcpLocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) { | ||||
|     this.localIp = tcpLocalIp | ||||
|     this.oppositeIp = tcpOppositeIp | ||||
|     this.localIpPort = tcpLocalIpPort | ||||
|     this.oppositeIpPort = tcpOppositePort | ||||
|     console.log(TCPTag, 'new Tcp', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort) | ||||
|     this.tcp = socket.constructTCPSocketInstance(); | ||||
|     this.bindTcp() | ||||
|     await this.bindTcp() | ||||
|     await this.connectTcp() | ||||
|   } | ||||
| 
 | ||||
|   bindTcp(): Promise<void> { | ||||
|     return this.tcp.bind({ | ||||
|       address: this.localIp, port: parseInt(this.localIpPort), family: 1 | ||||
|     }).then(() => { | ||||
|       return this.tcp.connect({ | ||||
|         address: { | ||||
|           address: this.oppositeIp, port: parseInt(this.oppositeIpPort) | ||||
|         }, | ||||
|         timeout: 6000 | ||||
|   // 绑定tcp | ||||
|   bindTcp(): Promise<Boolean> { | ||||
|     return new Promise((resolve, reject) => { | ||||
|       this.tcp.bind({ | ||||
|         address: this.localIp, | ||||
|         port: Number(this.localIpPort), | ||||
|         family: 1 | ||||
|       }).then(() => { | ||||
|         console.log(TCPTag, 'bindTcp success:', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort) | ||||
|         resolve(true) | ||||
|       }).catch((err: BusinessError) => { | ||||
|         console.log(TCPTag, 'bindTcp error:', JSON.stringify(err), this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort) | ||||
|         reject(err) | ||||
|       }) | ||||
|     }).then(() => { | ||||
|       try { | ||||
|         this.tcp.on("message", value => { | ||||
|           let data = new DataView(value.message) | ||||
|           this.events.forEach(cb => { | ||||
|             cb(value.message.slice(5, data.byteLength)) | ||||
|           }) | ||||
|         }) | ||||
|         return Promise.resolve() | ||||
|       } catch (e) { | ||||
|         return Promise.reject(e) | ||||
|       } | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 连接tcp | ||||
|   connectTcp(): Promise<Boolean> { | ||||
|     return new Promise((resolve, reject) => { | ||||
|       this.tcp.connect({ | ||||
|         address: { | ||||
|           address: this.oppositeIp, port: Number(this.oppositeIpPort), family: 1 | ||||
|         }, timeout: 1000 * 15 | ||||
|       }) | ||||
|         .then(() => { | ||||
|           this.getMessage() | ||||
|           console.log(TCPTag, "tcp connect success") | ||||
|           return this.tcp.setExtraOptions({ | ||||
|             keepAlive: true | ||||
|           }) | ||||
|         }) | ||||
|         .then(() => { | ||||
|           resolve(true) | ||||
|         }) | ||||
|         .catch((err: BusinessError) => { | ||||
|           console.log(TCPTag, "tcp connect or keepAlive error: ", JSON.stringify(err)) | ||||
|           console.log(TCPTag, "tcp 重启服务") | ||||
|           reject(err) | ||||
|         }) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   getMessage() { | ||||
|     this.tcp.on("message", value => { | ||||
|       let data = new DataView(value.message) | ||||
|       this.events.forEach(cb => { | ||||
|         cb(value.message.slice(5, data.byteLength)) | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 重新绑定tcp | ||||
|   async reBind() { | ||||
|     await this.close() | ||||
|     this.tcp = socket.constructTCPSocketInstance(); | ||||
|     await this.bindTcp() | ||||
|     await this.connectTcp() | ||||
|   } | ||||
| 
 | ||||
|   // 监听tcp错误 | ||||
|   onError(callback: Function) { | ||||
|     this.tcp.on('error', err => { | ||||
|       console.log(TCPTag, 'tcp on error: ', JSON.stringify(err)) | ||||
|       callback?.() | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   // 关闭tcp连接 | ||||
|   close(): Promise<void> { | ||||
|     return this.tcp?.close() | ||||
|   } | ||||
| 
 | ||||
|   // 监听tcp消息 | ||||
|   onMsg(callback: Function) { | ||||
|     this.events.push(callback) | ||||
|   } | ||||
| 
 | ||||
|   // 接收tcp消息 | ||||
|   sendMsg(data: string): Promise<void> { | ||||
|     return this.tcp?.send({ | ||||
|       data | ||||
|     }).catch(async (err: BusinessError) => { | ||||
|       console.log(TCPTag, 'sendMsg error:', JSON.stringify(err)) | ||||
|       this.tcpSendNum++ | ||||
|       if (this.tcpSendNum > 10) { | ||||
|         this.tcpSendNum = 0 | ||||
| @ -82,6 +125,7 @@ export default class TcpClient { | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   // 取消监听tcp消息 | ||||
|   offMsg(callback: Function) { | ||||
|     this.events = this.events.filter(cb => cb !== callback) | ||||
|   } | ||||
|  | ||||
| @ -1,9 +1,10 @@ | ||||
| //差分信号 | ||||
| import { TCPTag } from '../../config'; | ||||
| import { EnvironmentConfigurationType } from '../../model'; | ||||
| import TcpClient from '../TcpUtils'; | ||||
| 
 | ||||
| class differentialSignal { | ||||
|   private differentialSignalTcp: TcpClient; | ||||
|   private differentialSignalTcp: TcpClient = new TcpClient() | ||||
|   private timer: number = -1 | ||||
| 
 | ||||
|   constructor() { | ||||
| @ -12,9 +13,19 @@ class differentialSignal { | ||||
|   init() { | ||||
|     this.differentialSignalTcp = new TcpClient(); | ||||
|     let config: EnvironmentConfigurationType = | ||||
|       AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") | ||||
|     this.differentialSignalTcp.init(config.tcplocalIp, config.tcplocalIpPort, config.tcpOppositeIp, | ||||
|       config.tcpOppositePort); | ||||
|       AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || { | ||||
|         tcplocalIp: "", | ||||
|         tcplocalIpPort: "", | ||||
|         tcpOppositeIp: "", | ||||
|         tcpOppositePort: "" | ||||
|       } | ||||
|     console.log(TCPTag, "初始化", JSON.stringify(config)) | ||||
|     if (config.tcplocalIp || config.tcplocalIpPort || config.tcpOppositeIp || config.tcpOppositePort) { | ||||
|       this.differentialSignalTcp.init(config.tcplocalIp || "", config.tcplocalIpPort || "", config.tcpOppositeIp || "", | ||||
|         config.tcpOppositePort || ""); | ||||
|     } else { | ||||
|       console.log(TCPTag, "未配置差分信号TCP信息,请在环境配置中设置") | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // 发送消息 | ||||
| @ -30,6 +41,7 @@ class differentialSignal { | ||||
|   //   获取消息 | ||||
|   getData(callback: (data: ArrayBuffer) => void) { | ||||
|     this.differentialSignalTcp.onMsg((data: ArrayBuffer) => { | ||||
|       console.log(TCPTag, "获取", data); | ||||
|       callback(data); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user