Skip to content

Commit

Permalink
Register and deregister to subscriber events only once
Browse files Browse the repository at this point in the history
Fixes an issue where subscriber events are registered multiple times on network reconnection
  • Loading branch information
aravind-raveendran committed Aug 20, 2024
1 parent bba147d commit 551e406
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ public actor SubscriptionManager {
public init() {
// Configure the AVAudioSession with our settings.
AVAudioSession.configure()
}

public func subscribe(streamName: String, accountID: String, token: String? = nil, configuration: SubscriptionConfiguration = SubscriptionConfiguration()) async throws {

logHandler.setLogFilePath(filePath: configuration.sdkLogPath)


Task(priority: .userInitiated) { [weak self] in
guard let self else { return }
await self.registerToSubscriberEvents()
}
}

deinit {
deregisterToSubscriberEvents()
}

public func subscribe(streamName: String, accountID: String, token: String? = nil, configuration: SubscriptionConfiguration = SubscriptionConfiguration()) async throws {
logHandler.setLogFilePath(filePath: configuration.sdkLogPath)

let subscribeTask = Task(priority: .high) { [weak subscriber] in
guard let subscriber else { return }
Expand Down Expand Up @@ -106,7 +109,6 @@ public actor SubscriptionManager {

private func reset() {
state = .disconnected
deregisterToSubscriberEvents()
sourceBuilder.reset()
logHandler.setLogFilePath(filePath: nil)
}
Expand Down

0 comments on commit 551e406

Please sign in to comment.