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

RTC-512 Add Room.State module and peer disconnected timeout #178

Merged
merged 13 commits into from
Apr 17, 2024

Conversation

Rados13
Copy link
Contributor

@Rados13 Rados13 commented Apr 10, 2024

This PR introduces two changes:

  • extracts room state as a separate module and moves part of the logic related to modifying this state to that separate module
  • adds support for peer disconnected timeout, after which, if peer doesn't connect, the peer will be automatically removed from the room
  • add logs about WebSocket disconnects

Acknowledging the stipulations set forth:

  • I hereby confirm that a Pull Request involving updates to the Software Development Kit (SDK) has been smoothly merged, currently awaits processing, or is otherwise deemed unnecessary in this context.
  • I also affirm that another Pull Request, specifically addressing updates to the documentation body (commonly referred to as 'docs'), has either been successfully incorporated, is in the process of review, or is considered superfluous under the prevailing circumstances.

PR to docs
PR to elixir SDK
PR to Python SDK

@Rados13 Rados13 self-assigned this Apr 10, 2024
@Rados13 Rados13 force-pushed the feature/RTC-512/timeout_remove_peer branch from 5e41254 to c318a8d Compare April 10, 2024 11:37
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

Merging #178 (1e308e6) into main (67bf454) will increase coverage by 0.36%.
The diff coverage is 87.61%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   86.88%   87.24%   +0.36%     
==========================================
  Files          73       74       +1     
  Lines        1433     1482      +49     
==========================================
+ Hits         1245     1293      +48     
- Misses        188      189       +1     
Files Coverage Δ
lib/jellyfish/peer.ex 85.71% <ø> (ø)
lib/jellyfish/room/config.ex 96.42% <100.00%> (+0.27%) ⬆️
lib/jellyfish/room_service.ex 87.01% <100.00%> (ø)
lib/jellyfish_web/api_spec/room.ex 100.00% <ø> (ø)
lib/jellyfish_web/controllers/room_controller.ex 100.00% <100.00%> (ø)
lib/jellyfish_web/peer_socket.ex 82.00% <71.42%> (-2.10%) ⬇️
lib/jellyfish/room.ex 83.10% <86.27%> (-0.17%) ⬇️
lib/jellyfish/room/state.ex 88.07% <88.07%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67bf454...1e308e6. Read the comment docs.

@Rados13 Rados13 force-pushed the feature/RTC-512/timeout_remove_peer branch 2 times, most recently from 98519d6 to e006de3 Compare April 15, 2024 08:00
@Rados13 Rados13 requested review from roznawsk and sgfn April 16, 2024 06:34
@Rados13 Rados13 marked this pull request as ready for review April 16, 2024 06:34
@Rados13 Rados13 changed the title Add Room.State module RTC-512 Add Room.State module and peer disconnected timeout Apr 16, 2024
Copy link
Member

Choose a reason for hiding this comment

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

I find the peerlessPurgeTimeout and peerDisconnectedTimeout a bit simmilar. How about renaming the peerlessPurgeTimeout to roomIdleTimeout?

Copy link
Member

Choose a reason for hiding this comment

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

The room doesn't have to be idle for the purge to happen, though -- there can be components present...

@@ -32,7 +39,8 @@ defmodule Jellyfish.Peer do
socket_pid: pid() | nil,
engine_endpoint: Membrane.ChildrenSpec.child_definition(),
tracks: %{Track.id() => Track.t()},
metadata: any()
metadata: any(),
last_time_connected: non_neg_integer() | nil
Copy link
Member

Choose a reason for hiding this comment

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

[nitpick] monotonic_time returns integer()

Copy link
Member

Choose a reason for hiding this comment

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

I'm really unsure about the changes introduced here. I see why we're choosing to extract the state to a separate module, but as it stands, the implementation is "uneven", the abstraction level fluctuates -- e.g. notifications are sometimes emitted by the functions in state, sometimes by the functions here; calls to State can update a single key in the struct, or do a lot of additional logic as well.

IMO the State module should mainly be considered with, well, keeping track of the room state -- any and all additional tasks, such as emitting telemetry events and notifications, should be performed by Room. However, ensuring this distinction in the code could potentially diminish the benefits we achieved from splitting the state in the first place...

Discussion is welcome

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that the abstraction level fluctuates.I thought about how to better handle situations like broadcasting events, but it is pretty hard because many events require a lot of information e.g :track_removed event the API of the remove_track would look terryifing to return all needed information. As I see currently I could move the last two events from Room to State, but I am not sure if this will help a lot.

Copy link
Member

Choose a reason for hiding this comment

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

In my opinion it's a good thing that we moved some of the logic to the State.
It is true however that it is sometimes unclear what actions take place in the State and which withing the Room.

I think we can clear this up a bit.

First, we can move sending all Events to State.
Maybe it would be nice to send them from Room . But since all of them but two are emitted from State we can just make it a convention.

We can also get rid of any changes to state struct within the Room and move it to the State.

@Rados13 Rados13 force-pushed the feature/RTC-512/timeout_remove_peer branch from 4f2d3c6 to 55e364d Compare April 16, 2024 12:58
@Rados13 Rados13 requested review from roznawsk and sgfn April 16, 2024 13:05
Copy link
Member

@roznawsk roznawsk left a comment

Choose a reason for hiding this comment

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

LGTM 🎸

@Rados13 Rados13 force-pushed the feature/RTC-512/timeout_remove_peer branch from 55e364d to ecba4d5 Compare April 17, 2024 07:32
@Rados13 Rados13 merged commit 9cfc3e0 into main Apr 17, 2024
7 checks passed
@Rados13 Rados13 deleted the feature/RTC-512/timeout_remove_peer branch April 17, 2024 08:09
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