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

Subscribing for events #19

Merged
merged 5 commits into from
Jul 12, 2023
Merged

Subscribing for events #19

merged 5 commits into from
Jul 12, 2023

Conversation

roznawsk
Copy link
Member

@roznawsk roznawsk commented Jul 7, 2023

Copy link
Member

@LVala LVala left a comment

Choose a reason for hiding this comment

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

I'll wait with the rest of the review because the reasons stated in comments.

Comment on lines 21 to 25
iex> {:ok, notifier} = Jellyfish.Notifier.start(events: [:server_notifications])
{:ok, #PID<0.301.0>}
iex> {:ok, _rooms} = Jellyfish.Notifier.subscribe(notifier, :all)

# Subscribe current process to all server notifications.
iex> {:ok, _rooms} = Jellyfish.Notifier.subscribe(notifier, :server_notifications, :all)
Copy link
Member

Choose a reason for hiding this comment

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

The fact that you have to specify that it's :server_notifications seems very redundant, this needs to be changed IMO. I think the SubscribeRequest message should be send with subscribe, and the response would be the state of the rooms (or something else if the type of notifications is metrics etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the current solution. We only send SubscribeRequest once, immediately after starting the notifier. For now I see a scenario, in which we define Notifier inside Application and pass the events we want to receive inside start options.
I don't see a scenario, when we would need to subscribe for some new event late after starting the notifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whether specyfing :server_notifications is redundant - if Notifier is receiving more than one type of event, we have to specify what kind of events we want the calling process to subscribe to. I think the current way to do it (passing an atom representing certain event type) is the easiest from the user perspective.

Copy link
Member

Choose a reason for hiding this comment

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

From what I understand, right now starting the Notifier automatically subscribes us to the events passed as the options -- if we keep it this way, we should include a comment about it

At the moment, I feel like it's easy to confuse 1) sending a subscribe request to Jellyfish with 2) subscribing to receive events from the Notifier -- I think we should be more explicit about the distinction.

Copy link
Member Author

Choose a reason for hiding this comment

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

As per Łukasz comment, it has been unified now - calling Notifier.subscribe will every time cause sending a SubscribeRequest message to Jellyfish.

Comment on lines 119 to 120
def subscribe(notifier, event_type, room_id) do
with true <- event_type in @valid_events do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def subscribe(notifier, event_type, room_id) do
with true <- event_type in @valid_events do
def subscribe(notifier, event_type, room_id) when event_type in @valid_types do

@doc """
Starts the Notifier process and connects to Jellyfish.

Acts like `start/1` but links to the calling process.

See `start/1` for more information.
"""
@spec start_link(Client.connection_options()) :: {:ok, pid()} | {:error, term()}
@spec start_link(options()) :: {:ok, pid()} | {:error, term()}
Copy link
Member

Choose a reason for hiding this comment

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

Like I said, I think that this function shouldn't need to specify the events.

lib/jellyfish/notifier.ex Outdated Show resolved Hide resolved
lib/jellyfish/notifier.ex Outdated Show resolved Hide resolved
lib/jellyfish/notifier.ex Outdated Show resolved Hide resolved
test/test_helper.exs Outdated Show resolved Hide resolved
Comment on lines 117 to 119
@spec subscribe(notifier(), :server_notification, Room.id() | :all) ::
{:ok, Room.t() | [Room.t()]} | {:error, atom()}
def subscribe(notifier, event_type, room_id) do
Copy link
Member

Choose a reason for hiding this comment

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

Since we'll use this function to subscribe to other event types as well, and since the different requests may or may not contain different options, I'd say we might want to implement a solution like in Jellyfish.Room.add_component -- define separate modules with structs for different event types, as in Jellyfish.Component.{HLS, RTSP}, and allow the user to either pass the struct name (which means we'll use default options) or the struct with custom configuration.

Comment on lines 21 to 25
iex> {:ok, notifier} = Jellyfish.Notifier.start(events: [:server_notifications])
{:ok, #PID<0.301.0>}
iex> {:ok, _rooms} = Jellyfish.Notifier.subscribe(notifier, :all)

# Subscribe current process to all server notifications.
iex> {:ok, _rooms} = Jellyfish.Notifier.subscribe(notifier, :server_notifications, :all)
Copy link
Member

Choose a reason for hiding this comment

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

From what I understand, right now starting the Notifier automatically subscribes us to the events passed as the options -- if we keep it this way, we should include a comment about it

At the moment, I feel like it's easy to confuse 1) sending a subscribe request to Jellyfish with 2) subscribing to receive events from the Notifier -- I think we should be more explicit about the distinction.

@roznawsk roznawsk requested review from sgfn and LVala July 11, 2023 13:53
Copy link
Member

@LVala LVala left a comment

Choose a reason for hiding this comment

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

👍 besides these small issues

lib/jellyfish/notifier.ex Outdated Show resolved Hide resolved
lib/jellyfish/notifier.ex Show resolved Hide resolved
.gitmodules Outdated
@@ -1,4 +1,4 @@
[submodule "protos"]
path = protos
url = https://github.com/jellyfish-dev/protos.git
branch = master
branch = actually-subscribe-for-notifications
Copy link
Member

Choose a reason for hiding this comment

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

just a friendly reminder

@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #19 (d09ba36) into master (3565522) will decrease coverage by 0.86%.
The diff coverage is 84.00%.

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
- Coverage   80.12%   79.26%   -0.86%     
==========================================
  Files           9        9              
  Lines         166      164       -2     
==========================================
- Hits          133      130       -3     
- Misses         33       34       +1     
Impacted Files Coverage Δ
lib/jellyfish/room.ex 74.19% <ø> (ø)
lib/jellyfish/component.ex 58.33% <50.00%> (ø)
lib/jellyfish/notifier.ex 83.01% <85.00%> (-2.44%) ⬇️
lib/jellyfish/peer.ex 83.33% <100.00%> (ø)

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 3565522...d09ba36. Read the comment docs.

@roznawsk roznawsk requested a review from LVala July 12, 2023 13:09
Copy link
Member

@LVala LVala left a comment

Choose a reason for hiding this comment

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

👍

@roznawsk roznawsk merged commit d1e267a into master Jul 12, 2023
5 checks passed
@roznawsk roznawsk deleted the RTC-299-subscribe-for-events branch July 12, 2023 13:59
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.

None yet

4 participants