From: liangzhenying <867174124@qq.com> Date: Tue, 18 Mar 2025 02:24:11 +0000 (+0800) Subject: 改了voicechat重连流程 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=673a65b5c9484077fce24da2a8869ac3124f67bd;p=mirrors%2FIOTBluetooth-iOS.git 改了voicechat重连流程 --- diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift index 1b490cd..d4f7ffb 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift @@ -63,7 +63,7 @@ public class MSVoiceChat { timer = Timer.scheduledTimer(withTimeInterval: MSConfig.wsHeartBeatTime, repeats: true) { [weak self] _ in guard let self = self else {return} if socket?.readyState == .open{ -// self.socket?.ping() + self.socket?.send(text: "") } else{ self.openWebSocket() @@ -101,7 +101,6 @@ public class MSVoiceChat { "status": 0, ], "payload":[ -// "device_id": "test_device_id", // 设备ID/用户ID "device_id": deviceId, // 设备ID/用户ID "user_agent": "python", // 浏览器uset-gaent 自定义 "dialog_id":dialogId, // 继承上轮对话 空新建一个对话 @@ -141,6 +140,8 @@ public class MSVoiceChat { /// 发送内容 /// - Parameter content: 内容 public func send(content:String){ + MixSdk.shared.voiceChat.requestToSpeak() + let params:[String:Any] = [ "header": [ "trace_id": self.taskId, @@ -162,10 +163,11 @@ public class MSVoiceChat { /// 打断,请求说话 public func requestToSpeak(){ if socket?.readyState == .open{ - //self.socket?.ping() sendSpeakCMD() } else{ + //还没连接 + Logger.log("还没连接!!!!!!!!!!!") self.openWebSocket() DispatchQueue.main.asyncAfter(deadline: .now() + 2) { self.sendSpeakCMD() @@ -282,14 +284,6 @@ extension MSVoiceChat:WebSocketDelegate{ currentEvent = model } - -// if model.event == "RespondingEnded"{ -// let tmpModel = MSChatModel() -// tmpModel.type = "end" -// tmpModel.content = nil -// lastChatModel = tmpModel -// callBack?(tmpModel) -// } if model.event == "RespondingContent",let payload = model.payload,let text = payload.text{ if let finish = payload.finished,finish == false { let tmpModel = MSChatModel() @@ -314,7 +308,7 @@ extension MSVoiceChat:WebSocketDelegate{ } func webSocketPong(){ - //Logger.log("MSVoiceChat Pong") + Logger.log("MSVoiceChat Pong") } func webSocketEnd(_ code: Int, reason: String, wasClean: Bool, error: NSError?){ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift index e569d86..fb00329 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift @@ -235,11 +235,19 @@ public class MixSdk:NSObject { /// - key: key值 public func setPlatform(_ platform:MSPlatform,key:String? = nil){ Logger.log("\nplatform = \(platform) \n key= \(key ?? "")") - aiPlatform = platform - aiKey = key - - if platform != .chatGPT{ - setupWebsoket() + if platform == .chatGPT{ + aiPlatform = platform + aiKey = key + } + else { + if (platform == aiPlatform){ +// setupWebsoket() + } + else{ + aiPlatform = platform + aiKey = key + setupWebsoket() + } } }