In the iOS SimpleChatbot, fix @MainActor-related warnings (which would be errors in Swift 6). The delegate methods aren't contractually guaranteed to run on the main thread, so we can't mark them as @MainActor.
This commit is contained in:
@@ -127,55 +127,73 @@ extension CallContainerModel:RTVIClientDelegate, LLMHelperDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func onTransportStateChanged(state: TransportState) {
|
func onTransportStateChanged(state: TransportState) {
|
||||||
self.handleEvent(eventName: "onTransportStateChanged", eventValue: state)
|
Task { @MainActor in
|
||||||
self.voiceClientStatus = state.description
|
self.handleEvent(eventName: "onTransportStateChanged", eventValue: state)
|
||||||
self.isInCall = ( state == .connecting || state == .connected || state == .ready || state == .authenticating )
|
self.voiceClientStatus = state.description
|
||||||
}
|
self.isInCall = ( state == .connecting || state == .connected || state == .ready || state == .authenticating )
|
||||||
|
}
|
||||||
@MainActor
|
}
|
||||||
func onBotReady(botReadyData: BotReadyData) {
|
|
||||||
self.handleEvent(eventName: "onBotReady.")
|
func onBotReady(botReadyData: BotReadyData) {
|
||||||
self.isBotReady = true
|
Task { @MainActor in
|
||||||
if let expirationTime = self.rtviClientIOS?.expiry() {
|
self.handleEvent(eventName: "onBotReady.")
|
||||||
self.startTimer(withExpirationTime: expirationTime)
|
self.isBotReady = true
|
||||||
|
if let expirationTime = self.rtviClientIOS?.expiry() {
|
||||||
|
self.startTimer(withExpirationTime: expirationTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
|
||||||
func onConnected() {
|
func onConnected() {
|
||||||
self.isMicEnabled = self.rtviClientIOS?.isMicEnabled ?? false
|
Task { @MainActor in
|
||||||
|
self.isMicEnabled = self.rtviClientIOS?.isMicEnabled ?? false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDisconnected() {
|
func onDisconnected() {
|
||||||
self.stopTimer()
|
Task { @MainActor in
|
||||||
self.isBotReady = false
|
self.stopTimer()
|
||||||
|
self.isBotReady = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onRemoteAudioLevel(level: Float, participant: Participant) {
|
func onRemoteAudioLevel(level: Float, participant: Participant) {
|
||||||
self.remoteAudioLevel = level
|
Task { @MainActor in
|
||||||
|
self.remoteAudioLevel = level
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onUserAudioLevel(level: Float) {
|
func onUserAudioLevel(level: Float) {
|
||||||
self.localAudioLevel = level
|
Task { @MainActor in
|
||||||
|
self.localAudioLevel = level
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onUserTranscript(data: Transcript) {
|
func onUserTranscript(data: Transcript) {
|
||||||
if (data.final ?? false) {
|
Task { @MainActor in
|
||||||
self.handleEvent(eventName: "onUserTranscript", eventValue: data.text)
|
if (data.final ?? false) {
|
||||||
|
self.handleEvent(eventName: "onUserTranscript", eventValue: data.text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onBotTranscript(data: String) {
|
func onBotTranscript(data: String) {
|
||||||
self.handleEvent(eventName: "onBotTranscript", eventValue: data)
|
Task { @MainActor in
|
||||||
|
self.handleEvent(eventName: "onBotTranscript", eventValue: data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onError(message: String) {
|
func onError(message: String) {
|
||||||
self.handleEvent(eventName: "onError", eventValue: message)
|
Task { @MainActor in
|
||||||
self.showError(message: message)
|
self.handleEvent(eventName: "onError", eventValue: message)
|
||||||
|
self.showError(message: message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onTracksUpdated(tracks: Tracks) {
|
func onTracksUpdated(tracks: Tracks) {
|
||||||
self.handleEvent(eventName: "onTracksUpdated", eventValue: tracks)
|
Task { @MainActor in
|
||||||
|
self.handleEvent(eventName: "onTracksUpdated", eventValue: tracks)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user