Skip to content

Commit

Permalink
AudioPlayerAgent 1.9 -> 1.10 업데이트 (#1153)
Browse files Browse the repository at this point in the history
## Summary
- AudioPlayerAgent 버전 1.9 -> 1.10 업데이트
- BadgeButton관련 템플릿 값 추가
- BadgeButton관련 이벤트 값 추가
  • Loading branch information
ParkJongSang authored Apr 9, 2024
1 parent bd3571f commit 9ef853c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -880,6 +884,27 @@ private extension AudioPlayerAgent {
}.subscribe(on: audioPlayerScheduler)
}

func badgeButtonEvent(typeInfo: BadgeButtonEvent.TypeInfo) -> Single<Eventable> {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
4 changes: 4 additions & 0 deletions nugu-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1343,6 +1344,7 @@
E6F3DCBC2B4CB9D800298A20 /* ASRAgentDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASRAgentDelegate.swift; sourceTree = "<group>"; };
E6FBA02A2A1379C400AF8B05 /* MessengerAgentProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessengerAgentProtocol.swift; sourceTree = "<group>"; };
E6FBA02C2A137A9700AF8B05 /* ImageAgentProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageAgentProtocol.swift; sourceTree = "<group>"; };
F68562592BC3D8E600597762 /* AudioPlayerAgent+BadgeButtonEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AudioPlayerAgent+BadgeButtonEvent.swift"; sourceTree = "<group>"; };
F6A6B0832AAEFDD900D41DEC /* AudioPlayer2Template.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer2Template.swift; sourceTree = "<group>"; };
F6D49D0C296BAD3500510498 /* AudioPlayerPlaylist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerPlaylist.swift; sourceTree = "<group>"; };
F6D49D0E296BAE9600510498 /* AudioPlayerAgent+PlaylistEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AudioPlayerAgent+PlaylistEvent.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 9ef853c

Please sign in to comment.