-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate lifecycle manager into existing room operations
Replace the existing temporary implementations of room attach / detach / status with those provided by the room lifecycle manager. Part of #47.
- Loading branch information
1 parent
a1703dc
commit ac92127
Showing
12 changed files
with
302 additions
and
187 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Ably | ||
|
||
internal actor DefaultRoomLifecycleContributor: RoomLifecycleContributor { | ||
internal let channel: DefaultRoomLifecycleContributorChannel | ||
internal let feature: RoomFeature | ||
|
||
internal init(channel: DefaultRoomLifecycleContributorChannel, feature: RoomFeature) { | ||
self.channel = channel | ||
self.feature = feature | ||
} | ||
|
||
// MARK: - Discontinuities | ||
|
||
internal func emitDiscontinuity(_: ARTErrorInfo) { | ||
// TODO: https://github.com/ably-labs/ably-chat-swift/issues/47 | ||
} | ||
} | ||
|
||
internal final class DefaultRoomLifecycleContributorChannel: RoomLifecycleContributorChannel { | ||
private let underlyingChannel: any RealtimeChannelProtocol | ||
|
||
internal init(underlyingChannel: any RealtimeChannelProtocol) { | ||
self.underlyingChannel = underlyingChannel | ||
} | ||
|
||
internal func attach() async throws(ARTErrorInfo) { | ||
try await underlyingChannel.attachAsync() | ||
} | ||
|
||
internal func detach() async throws(ARTErrorInfo) { | ||
try await underlyingChannel.detachAsync() | ||
} | ||
|
||
internal var state: ARTRealtimeChannelState { | ||
underlyingChannel.state | ||
} | ||
|
||
internal var errorReason: ARTErrorInfo? { | ||
underlyingChannel.errorReason | ||
} | ||
|
||
internal func subscribeToState() async -> Subscription<ARTChannelStateChange> { | ||
// TODO: clean up old subscriptions (https://github.com/ably-labs/ably-chat-swift/issues/36) | ||
let subscription = Subscription<ARTChannelStateChange>(bufferingPolicy: .unbounded) | ||
underlyingChannel.on { subscription.emit($0) } | ||
return subscription | ||
} | ||
} |
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
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
Oops, something went wrong.