Skip to content

Reactive Swift library that simplifies interacting with Sonos Devices

License

Notifications You must be signed in to change notification settings

vityevato/RxSonosLib

 
 

Repository files navigation

RxSonosLib

Swift 5.0 Travis Badge Test Coverage Maintainability CocoaPods Version Badge License Badge Platform

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.

Background Info

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.

Cocoapods

pod 'RxSonosLib', '~> 0.14'

Usage

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)

Framework entry point

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]>
}

Observable chain methods

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
}

Modify settings

Inspect SonosSettings.swift, this class contains all customizable settings.

More demos?

Clone the repository, open xcworkspace and build the demo project

Development Info

Please document code changes in unit tests and make sure all tests are green.

License

This project is released under the Apache-2.0 license.

About

Reactive Swift library that simplifies interacting with Sonos Devices

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.2%
  • Other 0.8%