-
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.
Merge remote-tracking branch 'origin/main' into uts-chat-adapter
- Loading branch information
Showing
32 changed files
with
960 additions
and
305 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Ably | ||
|
||
internal actor DefaultRoomLifecycleContributor: RoomLifecycleContributor, EmitsDiscontinuities { | ||
internal let channel: DefaultRoomLifecycleContributorChannel | ||
internal let feature: RoomFeature | ||
private var discontinuitySubscriptions: [Subscription<ARTErrorInfo>] = [] | ||
|
||
internal init(channel: DefaultRoomLifecycleContributorChannel, feature: RoomFeature) { | ||
self.channel = channel | ||
self.feature = feature | ||
} | ||
|
||
// MARK: - Discontinuities | ||
|
||
internal func emitDiscontinuity(_ error: ARTErrorInfo) { | ||
for subscription in discontinuitySubscriptions { | ||
subscription.emit(error) | ||
} | ||
} | ||
|
||
internal func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo> { | ||
let subscription = Subscription<ARTErrorInfo>(bufferingPolicy: .unbounded) | ||
// TODO: clean up old subscriptions (https://github.com/ably-labs/ably-chat-swift/issues/36) | ||
discontinuitySubscriptions.append(subscription) | ||
return subscription | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} |
Oops, something went wrong.