-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: React Native SSE Support #1012
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6d5d2d3
feat: add file
jonathannorris c4866c0
feat: update ReactNativeSSEConnection with connection bool and logs
jonathannorris 7c0ecca
chore: react native SSE connection working
jonathannorris 00130df
feat: add SSETypes file
jonathannorris 8322f21
fix: add sse class to options type
jonathannorris 99ca602
chore: cleanup
jonathannorris c647b5e
chore: cleanup log
jonathannorris f59c768
feat: update debug options
jonathannorris 8b30b91
fix: add @devcycle/types to react-native package.json
jonathannorris 6f1dc74
fix: @devcycle/types in react-native package
jonathannorris 2fbe431
fix: test failing from distribution % (#1013)
jonathannorris 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 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,16 @@ | ||
import type { DVCLogger } from '../logger' | ||
|
||
export interface SSEConnectionInterface { | ||
updateURL(url: string): void | ||
isConnected(): boolean | ||
reopen(): void | ||
close(): void | ||
} | ||
|
||
export interface SSEConnectionConstructor { | ||
new ( | ||
url: string, | ||
onMessage: (message: unknown) => void, | ||
logger: DVCLogger, | ||
): SSEConnectionInterface | ||
} |
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,70 @@ | ||
import EventSource from 'react-native-sse' | ||
import type { DVCLogger, SSEConnectionInterface } from '@devcycle/types' | ||
|
||
export class ReactNativeSSEConnection implements SSEConnectionInterface { | ||
private connection?: EventSource | ||
private isConnectionOpen = false | ||
|
||
constructor( | ||
private url: string, | ||
private onMessage: (message: unknown) => void, | ||
private logger: DVCLogger, | ||
) { | ||
this.openConnection() | ||
} | ||
|
||
public updateURL(url: string): void { | ||
this.close() | ||
this.url = url | ||
this.openConnection() | ||
} | ||
|
||
private openConnection() { | ||
this.connection = new EventSource(this.url, { | ||
debug: false, | ||
// start connection immediately | ||
timeoutBeforeConnection: 0, | ||
// disable request timeout so connections are kept open | ||
timeout: 0, | ||
// enable withCredentials so we can send cookies | ||
withCredentials: true, | ||
}) | ||
|
||
this.connection.addEventListener('message', (event) => { | ||
this.logger.debug(`ReactNativeSSEConnection message. ${event.data}`) | ||
this.onMessage(event.data) | ||
}) | ||
|
||
this.connection.addEventListener('error', (error) => { | ||
this.logger.error( | ||
`ReactNativeSSEConnection error. ${ | ||
(error as any)?.message || JSON.stringify(error) | ||
}`, | ||
) | ||
}) | ||
|
||
this.connection.addEventListener('open', () => { | ||
this.logger.debug('ReactNativeSSEConnection opened') | ||
this.isConnectionOpen = true | ||
}) | ||
this.connection.addEventListener('close', () => { | ||
this.logger.debug('ReactNativeSSEConnection closed') | ||
this.isConnectionOpen = false | ||
}) | ||
} | ||
|
||
isConnected(): boolean { | ||
return this.isConnectionOpen | ||
} | ||
|
||
reopen(): void { | ||
if (!this.isConnected()) { | ||
this.close() | ||
this.openConnection() | ||
} | ||
} | ||
|
||
close(): void { | ||
this.connection?.close() | ||
} | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this will require docs update as we need to install the other packages separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't it be installed from the dependency? seems to work in the E2E test app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not 100 percent sure, but we have that explicit in the docs and in the past when i have tried to install, required me to add those dependencies have not tested recently tbh