From 9ef853c5d0e9968bce98e4b915445a5a4bae7222 Mon Sep 17 00:00:00 2001 From: Sokiwar Date: Tue, 9 Apr 2024 11:02:36 +0900 Subject: [PATCH] =?UTF-8?q?AudioPlayerAgent=201.9=20->=201.10=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20(#1153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - AudioPlayerAgent 버전 1.9 -> 1.10 업데이트 - BadgeButton관련 템플릿 값 추가 - BadgeButton관련 이벤트 값 추가 --- .../AudioPlayer/AudioPlayerAgent.swift | 27 +++++++- .../AudioPlayerAgentProtocol.swift | 3 + .../Display/Models/AudioPlayer1Template.swift | 23 +++++++ .../AudioPlayerAgent+BadgeButtonEvent.swift | 62 +++++++++++++++++++ nugu-ios.xcodeproj/project.pbxproj | 4 ++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 NuguAgents/Sources/CapabilityAgents/AudioPlayer/Event/AudioPlayerAgent+BadgeButtonEvent.swift diff --git a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgent.swift b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgent.swift index ea241aedb..27518c549 100644 --- a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgent.swift +++ b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgent.swift @@ -27,7 +27,7 @@ import RxSwift public final class AudioPlayerAgent: AudioPlayerAgentProtocol { // CapabilityAgentable - public var capabilityAgentProperty: CapabilityAgentProperty = CapabilityAgentProperty(category: .audioPlayer, version: "1.9") + public var capabilityAgentProperty: CapabilityAgentProperty = CapabilityAgentProperty(category: .audioPlayer, version: "1.10") private let playSyncProperty = PlaySyncProperty(layerType: .media, contextType: .sound) // AudioPlayerAgentProtocol @@ -317,6 +317,10 @@ public extension AudioPlayerAgent { sendFullContextEvent(playlistEvent(typeInfo: .modifyPlaylist(deletedTokens: deletedTokens, tokens: tokens))) } + func requestBadgeButtonSelected(with token: String, postback: [String: AnyHashable]) { + sendFullContextEvent(badgeButtonEvent(typeInfo: .badgeButtonSelected(token: token, postback: postback))) + } + func notifyUserInteraction() { switch audioPlayerState { case .stopped, .finished: @@ -880,6 +884,27 @@ private extension AudioPlayerAgent { }.subscribe(on: audioPlayerScheduler) } + func badgeButtonEvent(typeInfo: BadgeButtonEvent.TypeInfo) -> Single { + return Single.create { [weak self] (observer) -> Disposable in + guard let self, let player = self.latestPlayer else { + observer(.failure(NuguAgentError.invalidState)) + return Disposables.create() + } + + do { + let badgeButtonEvent = BadgeButtonEvent( + typeInfo: typeInfo, + playServiceId: player.payload.playServiceId + ) + observer(.success(badgeButtonEvent)) + } catch { + observer(.failure(NuguAgentError.invalidState)) + } + + return Disposables.create() + }.subscribe(on: audioPlayerScheduler) + } + private func makePlaylistEvent(typeInfo: PlaylistEvent.TypeInfo) throws -> PlaylistEvent { if ignoreLatestPlayer == true { return PlaylistEvent( diff --git a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgentProtocol.swift b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgentProtocol.swift index 40426bd9e..a5b9ac124 100644 --- a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgentProtocol.swift +++ b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/AudioPlayerAgentProtocol.swift @@ -87,6 +87,9 @@ public protocol AudioPlayerAgentProtocol: CapabilityAgentable, TypedNotifyable { /// Change current playlist information by sending deletedTokens and playlist tokens func requestPlaylistModified(deletedTokens: [String], tokens: [String]) + /// Request directive by selecting badge button. + func requestBadgeButtonSelected(with token: String, postback: [String: AnyHashable]) + /// Sets the current playback time to the specified time. /// /// - Parameter offset: The time(seconds) to which to seek. diff --git a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Display/Models/AudioPlayer1Template.swift b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Display/Models/AudioPlayer1Template.swift index 499c233c3..7b080f142 100644 --- a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Display/Models/AudioPlayer1Template.swift +++ b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Display/Models/AudioPlayer1Template.swift @@ -45,8 +45,31 @@ public struct AudioPlayer1Template: Decodable { public let backgroundColor: String? public let badgeImageUrl: String? public let badgeMessage: String? + public let badgeButton: BadgeButton? public let lyrics: AudioPlayerLyricsTemplate? public let settings: AudioPlayerSettingsTemplate? + + public struct BadgeButton: Decodable { + private enum CodingKeys: CodingKey { + case token + case text + case backgroundColor + case postback + } + + public let token: String + public let text: String + public let backgroundColor: String? + public let postback: [String: AnyHashable]? + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + token = try container.decode(String.self, forKey: .token) + text = try container.decode(String.self, forKey: .text) + backgroundColor = try container.decodeIfPresent(String.self, forKey: .backgroundColor) + postback = try container.decodeIfPresent([String: AnyHashable].self, forKey: .postback) + } + } } } } diff --git a/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Event/AudioPlayerAgent+BadgeButtonEvent.swift b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Event/AudioPlayerAgent+BadgeButtonEvent.swift new file mode 100644 index 000000000..8251d8429 --- /dev/null +++ b/NuguAgents/Sources/CapabilityAgents/AudioPlayer/Event/AudioPlayerAgent+BadgeButtonEvent.swift @@ -0,0 +1,62 @@ +// +// AudioPlayerAgent+BadgeButtonEvent.swift +// NuguAgents +// +// Copyright © 2024 SK Telecom Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +// MARK: - Event + +extension AudioPlayerAgent { + struct BadgeButtonEvent { + let typeInfo: TypeInfo + let playServiceId: String? + + enum TypeInfo { + case badgeButtonSelected(token: String, postback: [String: AnyHashable]) + } + } +} + +// MARK: - Eventable + +extension AudioPlayerAgent.BadgeButtonEvent: Eventable { + var payload: [String: AnyHashable] { + var eventPayload: [String: AnyHashable] = [ + "playServiceId": playServiceId + ] + + switch typeInfo { + case .badgeButtonSelected(token: let playlistItemToken, postback: let postback): + eventPayload["token"] = playlistItemToken + eventPayload["postback"] = postback + + if playServiceId == nil { + eventPayload["playServiceId"] = postback["playServiceId"] + } + } + + return eventPayload + } + + var name: String { + switch typeInfo { + case .badgeButtonSelected: + return "ElementSelected" + } + } +} diff --git a/nugu-ios.xcodeproj/project.pbxproj b/nugu-ios.xcodeproj/project.pbxproj index dc20e48b7..52382c871 100644 --- a/nugu-ios.xcodeproj/project.pbxproj +++ b/nugu-ios.xcodeproj/project.pbxproj @@ -536,6 +536,7 @@ E6F3DCBD2B4CB9D800298A20 /* ASRAgentDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F3DCBC2B4CB9D800298A20 /* ASRAgentDelegate.swift */; }; E6FBA02B2A1379C500AF8B05 /* MessengerAgentProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FBA02A2A1379C400AF8B05 /* MessengerAgentProtocol.swift */; }; E6FBA02D2A137A9700AF8B05 /* ImageAgentProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FBA02C2A137A9700AF8B05 /* ImageAgentProtocol.swift */; }; + F685625A2BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68562592BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift */; }; F6A6B0842AAEFDD900D41DEC /* AudioPlayer2Template.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A6B0832AAEFDD900D41DEC /* AudioPlayer2Template.swift */; }; F6D49D0D296BAD3500510498 /* AudioPlayerPlaylist.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D49D0C296BAD3500510498 /* AudioPlayerPlaylist.swift */; }; F6D49D0F296BAE9600510498 /* AudioPlayerAgent+PlaylistEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D49D0E296BAE9600510498 /* AudioPlayerAgent+PlaylistEvent.swift */; }; @@ -1343,6 +1344,7 @@ E6F3DCBC2B4CB9D800298A20 /* ASRAgentDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASRAgentDelegate.swift; sourceTree = ""; }; E6FBA02A2A1379C400AF8B05 /* MessengerAgentProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessengerAgentProtocol.swift; sourceTree = ""; }; E6FBA02C2A137A9700AF8B05 /* ImageAgentProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageAgentProtocol.swift; sourceTree = ""; }; + F68562592BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AudioPlayerAgent+BadgeButtonEvent.swift"; sourceTree = ""; }; F6A6B0832AAEFDD900D41DEC /* AudioPlayer2Template.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer2Template.swift; sourceTree = ""; }; F6D49D0C296BAD3500510498 /* AudioPlayerPlaylist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerPlaylist.swift; sourceTree = ""; }; F6D49D0E296BAE9600510498 /* AudioPlayerAgent+PlaylistEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AudioPlayerAgent+PlaylistEvent.swift"; sourceTree = ""; }; @@ -1574,6 +1576,7 @@ 06CF291D2547F8B600CEC3EC /* Event */ = { isa = PBXGroup; children = ( + F68562592BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift */, 1FFFF3392375707000C9A177 /* AudioPlayerAgent+PlayEvent.swift */, A135E6942428B6C8006F82E5 /* AudioPlayerAgent+RequestPlayEvent.swift */, A135E662241F1925006F82E5 /* AudioPlayerAgent+SettingsEvent.swift */, @@ -4358,6 +4361,7 @@ E649868628336CED001AD733 /* DisplayRedirectTriggerChildPayload.swift in Sources */, 73152FB523E0413F00F843C3 /* AudioPlayerAgent+PlayEvent.swift in Sources */, 7373891A24A46CC20018DDD2 /* LocationAgentDelegate.swift in Sources */, + F685625A2BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift in Sources */, 737388E724A46C5D0018DDD2 /* AudioPlayerState.swift in Sources */, 1F9337AD25BF265200CEBF66 /* MessageAgent+Event.swift in Sources */, 06FE563F253E9EC0002FAC9B /* TTSPlayer.swift in Sources */,