From 659975d6146f4bf4f1bd00d3125c9330bfbf1007 Mon Sep 17 00:00:00 2001 From: jayce1116 Date: Tue, 30 Apr 2024 09:27:33 +0900 Subject: [PATCH] =?UTF-8?q?ASR.NotifyResult=20directive=EB=A5=BC=20?= =?UTF-8?q?=EC=88=98=EC=8B=A0=ED=95=98=EB=A9=B4=20=EA=B7=B8=20=EC=9D=B4?= =?UTF-8?q?=ED=9B=84=EC=9D=98=20=EB=8B=A4=EB=A5=B8=20dialogRequestId?= =?UTF-8?q?=EB=A5=BC=20=EC=88=98=EC=8B=A0=ED=95=98=EA=B8=B0=20=EC=A0=84?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20focus=20=EC=9C=A0=EC=A7=80=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#1157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description - ASR.NotifyResult와 다음 directive 사이에 BackgroundFocusHolder가 focus를 가지고 있도록 변경 --- .../Business/BackgroundFocusHolder.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/NuguClientKit/Sources/Business/BackgroundFocusHolder.swift b/NuguClientKit/Sources/Business/BackgroundFocusHolder.swift index 9adc2078..4578eacb 100644 --- a/NuguClientKit/Sources/Business/BackgroundFocusHolder.swift +++ b/NuguClientKit/Sources/Business/BackgroundFocusHolder.swift @@ -34,8 +34,13 @@ class BackgroundFocusHolder { "MediaPlayer.PlaySuspended" ] + private let pendingTargets = [ + "ASR.NotifyResult" + ] + private var handlingEvents = Set() private var handlingSoundDirectives = Set() + private var handlingPendingDirectives = Set() private var dialogState: DialogState = .idle // Observers @@ -43,6 +48,7 @@ class BackgroundFocusHolder { private var eventWillSendObserver: Any? private var eventDidSendObserver: Any? private var dialogStateObserver: Any? + private var directiveReceiveObserver: Any? private var directivePrefetchObserver: Any? private var directiveCompleteObserver: Any? @@ -82,6 +88,10 @@ class BackgroundFocusHolder { if let directiveCompleteObserver = directiveCompleteObserver { notificationCenter.removeObserver(directiveCompleteObserver) } + + if let directiveReceiveObserver = directiveReceiveObserver { + notificationCenter.removeObserver(directiveReceiveObserver) + } } } @@ -107,6 +117,7 @@ private extension BackgroundFocusHolder { func tryReleaseFocus() { guard handlingEvents.isEmpty, handlingSoundDirectives.isEmpty, + handlingPendingDirectives.isEmpty, dialogState == .idle else { return } focusManager.releaseFocus(channelDelegate: self) @@ -137,6 +148,22 @@ private extension BackgroundFocusHolder { } } } + + directiveReceiveObserver = object.observe(NuguCoreNotification.StreamDataRoute.ReceivedDirective.self, queue: nil) { [weak self] notification in + self?.queue.async { [weak self] in + guard let self else { return } + let dialogRequestId = notification.directive.header.dialogRequestId + if pendingTargets.contains(notification.directive.header.type) { + handlingPendingDirectives.insert(dialogRequestId) + requestFocus() + } else if handlingPendingDirectives.contains(dialogRequestId) { + // PendingTarget과 동일한 dialogRequestId를 수신할 경우 focus를 유지 + } else { + handlingPendingDirectives.removeAll() + tryReleaseFocus() + } + } + } } func addDialogStateObserver(_ object: DialogStateAggregator) {