Skip to content
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

Reconnect camera streams #96

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Conversation

njooma
Copy link
Member

@njooma njooma commented Aug 7, 2023

Camera streams now automatically reestablish after a loss and regain of connection.

@njooma njooma requested a review from jckras August 7, 2023 22:13
@njooma njooma requested a review from a team as a code owner August 7, 2023 22:13
@njooma njooma requested a review from cheukt August 7, 2023 22:13
_channel = channel;
_channel.rtcPeerConnection.onTrack = (event) {
_errorHandler?.cancel(); // Cancel the error handler -- clearly we're connected if we're receiving this event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(q) why are we doing this twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first time happens whenever we change the channel.

This one is on a callback -- so it's possible it gets called out of order/after the error handler exists again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one happens whenever the channel changes. This one is happening on a callback which could be called out of order/delayed (after the _errorHandler exists again). The one that happens a bit further down is in another callback, where we want to cancel if the returned state is not an error state.

@@ -75,7 +80,10 @@ class RobotClient {
/// Refresh the resources of this robot
Future<void> refresh() async {
final ResourceNamesResponse response = await _client.resourceNames(ResourceNamesRequest());
if (response.resources == resourceNames) {
if (setEquals(response.resources.toSet(), resourceNames.toSet())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(q) why if(setEquals(response.resources.toSet(),....... as opposed to if (response.resources == resourceNames) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because the second way wasn't working. I didn't dive too deep into it but converting both to lists, sorting those lists, making everything lowercase strings, nothing actually make things equal except converting these to sets and using setEquals

Copy link
Member

@jckras jckras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left questions for my own understanding but LGTM

@njooma njooma merged commit cc61dcd into viamrobotics:main Aug 8, 2023
1 check passed
@njooma njooma deleted the reconnection branch August 8, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants