-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatting changes to better follow recommended/common ways to format Swift. For example avoid ";" and "()" when not needed, usage of "self" when not needed for clarity, and some other things. Also removes some redundant whitespace/new-lines.
- Loading branch information
Showing
7 changed files
with
67 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import Foundation | ||
|
||
internal class AptabaseClient { | ||
private static let sdkVersion = "[email protected]"; | ||
class AptabaseClient { | ||
private static let sdkVersion = "[email protected]" | ||
// Session expires after 1 hour of inactivity | ||
private static let sessionTimeout: TimeInterval = 1 * 60 * 60 | ||
|
||
private var sessionId = UUID() | ||
private var lastTouched = Date() | ||
private var flushTimer: Timer? | ||
private let dispatcher: EventDispatcher | ||
private let env: EnvironmentInfo | ||
private let flushInterval: Double | ||
|
||
init(appKey: String, baseUrl: String, env: EnvironmentInfo, options: InitOptions?) { | ||
self.flushInterval = options?.flushInterval ?? (env.isDebug ? 2.0 : 60.0) | ||
flushInterval = options?.flushInterval ?? (env.isDebug ? 2.0 : 60.0) | ||
self.env = env | ||
self.dispatcher = EventDispatcher(appKey: appKey, baseUrl: baseUrl, env: env) | ||
|
||
dispatcher = EventDispatcher(appKey: appKey, baseUrl: baseUrl, env: env) | ||
} | ||
|
||
public func trackEvent(_ eventName: String, with props: [String: AnyCodableValue] = [:]) { | ||
let now = Date() | ||
if lastTouched.distance(to: now) > AptabaseClient.sessionTimeout { | ||
sessionId = UUID() | ||
} | ||
lastTouched = now | ||
|
||
let evt = Event(timestamp: Date(), | ||
sessionId: sessionId, | ||
eventName: eventName, | ||
|
@@ -41,24 +41,24 @@ internal class AptabaseClient { | |
props: props) | ||
dispatcher.enqueue(evt) | ||
} | ||
|
||
public func startPolling() { | ||
stopPolling(); | ||
flushTimer = Timer.scheduledTimer(timeInterval: self.flushInterval, target: self, selector: #selector(flushSync), userInfo: nil, repeats: true) | ||
stopPolling() | ||
|
||
flushTimer = Timer.scheduledTimer(timeInterval: flushInterval, target: self, selector: #selector(flushSync), userInfo: nil, repeats: true) | ||
} | ||
|
||
public func stopPolling() { | ||
flushTimer?.invalidate() | ||
flushTimer = nil | ||
|
||
flushSync() | ||
} | ||
|
||
public func flush() async { | ||
await dispatcher.flush() | ||
} | ||
|
||
@objc private func flushSync() { | ||
let semaphore = DispatchSemaphore(value: 0) | ||
Task { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters