-
Notifications
You must be signed in to change notification settings - Fork 27
feat: In-App SSE #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: In-App SSE #975
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e3fdba
chore: Detect SSE flag and switch between polling and SSE connection …
mahmoud-elmorabea 4a45943
chore: Implement SSE connection (#966)
mahmoud-elmorabea 64de9ad
chore: SSE Heartbeat handling (#967)
mahmoud-elmorabea 35cca39
chore: SSE error handling and retry (#969)
mahmoud-elmorabea bac486a
chore: Add unit tests for SSE implementation (#970)
mahmoud-elmorabea 1bb0ffe
chore: Implement SSE lifecycle management (#972)
mahmoud-elmorabea 2d878f0
chore: Enable SSE only for authenticated users (#973)
mahmoud-elmorabea 30306d5
chore: Ensure multiple messages are processed when SSE is enabled (#976)
mahmoud-elmorabea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
55 changes: 55 additions & 0 deletions
55
Sources/MessagingInApp/Gist/Network/SSE/AsyncStreamBackport.swift
This file contains hidden or 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,55 @@ | ||
| import Foundation | ||
|
|
||
| /// Backport of `AsyncStream.makeStream()` for iOS 13+. | ||
| /// | ||
| /// `AsyncStream.makeStream()` was introduced in iOS 17 and provides a way to create | ||
| /// an AsyncStream and access its continuation separately. This is useful when you need | ||
| /// to set up resources that require the continuation before returning the stream. | ||
| /// | ||
| /// This backport provides the same functionality for older iOS versions. | ||
| enum AsyncStreamBackport { | ||
| /// Creates an AsyncStream and returns both the stream and its continuation separately. | ||
| /// | ||
| /// This allows setup code to access the continuation before the stream is consumed, | ||
| /// enabling synchronous setup patterns that avoid race conditions. | ||
| /// | ||
| /// Example: | ||
| /// ```swift | ||
| /// func connect() -> AsyncStream<Event> { | ||
| /// let (stream, continuation) = AsyncStreamBackport.makeStream(of: Event.self) | ||
| /// | ||
| /// // Use continuation immediately for setup | ||
| /// let handler = EventHandler(continuation: continuation) | ||
| /// self.connection = Connection(handler: handler) | ||
| /// self.connection.start() | ||
| /// | ||
| /// return stream | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// - Parameters: | ||
| /// - elementType: The type of elements in the stream. | ||
| /// - bufferingPolicy: The buffering policy for the stream. Defaults to `.unbounded`. | ||
| /// - Returns: A tuple containing the stream and its continuation. | ||
| static func makeStream<Element>( | ||
| of elementType: Element.Type = Element.self, | ||
| bufferingPolicy: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded | ||
| ) -> (stream: AsyncStream<Element>, continuation: AsyncStream<Element>.Continuation) { | ||
| // Capture the continuation from the closure using an optional variable | ||
| var continuation: AsyncStream<Element>.Continuation? | ||
|
|
||
| let stream = AsyncStream<Element>(bufferingPolicy: bufferingPolicy) { cont in | ||
| // This closure is called synchronously during AsyncStream initialization | ||
| continuation = cont | ||
| } | ||
|
|
||
| // By the time AsyncStream's init returns, the closure has executed | ||
| // and continuation is guaranteed to be set | ||
| guard let continuation = continuation else { | ||
| // This should never happen - the closure is called synchronously | ||
| fatalError("AsyncStream continuation was not set during initialization") | ||
| } | ||
|
|
||
| return (stream, continuation) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.