Skip to content

Commit

Permalink
✨ Wait for all startup to finish to call rwStartedSuccessfully delega…
Browse files Browse the repository at this point in the history
…te (roundware#33)

* 🎉 Wait for all startup to finish to call delegate

* 🔥 Revert unneeded ios version change
  • Loading branch information
loafofpiecrust authored Jul 28, 2019
1 parent e55444c commit 6dc45a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
23 changes: 14 additions & 9 deletions RWFramework/RWFramework/Playlist/Playlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ extension Playlist {
}

/// Grab the list of `AudioTrack`s for the current project.
private func initTracks() {
private func initTracks() -> Promise<Void> {
let rw = RWFramework.sharedInstance

rw.apiGetAudioTracks([
return rw.apiGetAudioTracks([
"project_id": String(project.id)
]).then { data in
]).then { data -> () in
print("assets: using " + data.count.description + " tracks")
for it in data {
// TODO: Try to remove playlist dependency. Maybe pass into method?
Expand Down Expand Up @@ -359,8 +359,8 @@ extension Playlist {
}

/// Periodically check for newly published assets
internal func refreshAssetPool() {
self.updateAssets().then {
internal func refreshAssetPool() -> Promise<Void> {
return self.updateAssets().then {
// Update filtered assets given any newly uploaded assets
self.updateParams()

Expand Down Expand Up @@ -403,16 +403,21 @@ extension Playlist {
startTime = Date()

// Start playing background music from speakers.
initSpeakers()
let speakerUpdate = initSpeakers()

// Retrieve the list of tracks
initTracks()
let trackUpdate = initTracks()

// Initial grab of assets and speakers.
let assetsUpdate = refreshAssetPool()

all(speakerUpdate, trackUpdate, assetsUpdate).then { _ in
RWFramework.sharedInstance.rwStartedSuccessfully()
}

updateTimer = .every(.seconds(project.asset_refresh_interval)) { _ in
self.refreshAssetPool()
}
// Initial grab of assets and speakers.
updateTimer?.fire()
}

func pause() {
Expand Down
9 changes: 9 additions & 0 deletions RWFramework/RWFramework/RWFrameworkProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import CoreLocation
// MARK: RWFrameworkProtocol
@objc public protocol RWFrameworkProtocol: class {

/// Sent when the framework CSM components are initialized and ready
@objc optional func rwStartedSuccessfully()

// API success/failure delegate methods

/// Sent when a token and username are returned from the server
Expand Down Expand Up @@ -245,6 +248,12 @@ extension RWFramework {

// MARK: callers

func rwStartedSuccessfully() {
protocaller { (rwfp, _) -> Void in
self.dam { rwfp.rwStartedSuccessfully?() }
}
}

func rwPostUsersSuccess(_ data: Data) {
protocaller { (rwfp, _) -> Void in
self.dam { rwfp.rwPostUsersSuccess?(data) }
Expand Down
2 changes: 1 addition & 1 deletion Roundware.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Roundware'
s.version = '0.2.0'
s.version = '0.2.1'
s.summary = 'Audio framework'

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit 6dc45a1

Please sign in to comment.