Swift library that simplifies interacting with Sonos Devices
Features:
- GET SSDP devices on the current network
- MAP SSDP devices into Sonos Rooms
- MAP Sonos Rooms into Sonos Groups + renew
- GET now playing track per room (supports Spotify, Tunein, Library & TV) + renew
- DOWNLOAD track image
- GET group progress + renew
- GET group queue
- ADD tracks to the group queue
- DELETE tracks from the group queue
- SET previous/next group queue track
- SET play/pause/stop current track
- GET group volume
- SET group volume
- Cache household
Platform:
- iOS
- MacOS
- tvOS
- WatchOS
This library requires Swift 5.0 & RxSwift.
The first version of this project started as a way to understand Sonos better. This version is here to help me improve my RxSwift knowledge.
pod 'RxSonosLib', '~> 0.14'
Inspect SonosInteractor.swift this class is your entry to the library.
From here, continue by chaining observerable functions specified in the matching models Group.swift, Room.swift & Track.swift
Example:
SonosInteractor
.getActiveGroup()
.getQueue()
.subscribe(onNext: { (queue) in
print("queue: onNext")
}, onError: { (error) in
print("queue: \(error.localizedDescription)")
}, onCompleted: {
print("queue: onCompleted")
}).disposed(by: disposeBag)
Start with a static function in the SonosInteractor
open class SonosInteractor {
static func setActive(group: Group)
static func getActiveGroup() -> Observable<Group>
static func getAllGroups() -> Observable<[Group]>
static func getAllMusicProviders() -> Single<[MusicProvider]>
}
The continue with one or multiple chain methods.
Methods for an Observable Group:
extension ObservableType where E == Group {
func getRooms() -> Observable<[Room]>
func getTrack() -> Observable<Track?>
func getImage() -> Observable<Data?>
func getProgress() -> Observable<GroupProgress>
func getQueue() -> Observable<[Track]>
func getTransportState() -> Observable<(TransportState, MusicService)>
func set(transportState: TransportState) -> Observable<TransportState>
func getVolume() -> Observable<Int>
func set(volume: Int) -> Completable
func setNextTrack() -> Completable
func setPreviousTrack() -> Completable
func getMute() -> Observable<[Bool]>
func set(mute enabled: Bool) -> Completable
}
Methods for an Observable Track:
extension ObservableType where E == Track {
func getImage() -> Observable<Data?>
}
Methods for an Observable array with Room's:
extension ObservableType where E == [Room] {
func getMute() -> Observable<[Bool]>
func set(mute enabled: Bool) -> Completable
}
Methods for an Observable Room:
extension ObservableType where E == Room {
func getMute() -> Observable<Bool>
func set(mute enabled: Bool) -> Completable
}
Inspect SonosSettings.swift, this class contains all customizable settings.
Clone the repository, open xcworkspace
and build the demo project
Please document code changes in unit tests and make sure all tests are green.
This project is released under the Apache-2.0 license.