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

Add subscription #47

Merged
merged 5 commits into from Jul 12, 2023
Merged

Add subscription #47

merged 5 commits into from Jul 12, 2023

Conversation

roznawsk
Copy link
Member

@roznawsk roznawsk commented Jul 5, 2023

Receiving notifications requires subscribing to the topic first.
Ref:

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #47 (ab115fe) into main (9046a4d) will decrease coverage by 0.75%.
The diff coverage is 56.00%.

@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
- Coverage   89.22%   88.48%   -0.75%     
==========================================
  Files          32       32              
  Lines         399      408       +9     
==========================================
+ Hits          356      361       +5     
- Misses         43       47       +4     
Impacted Files Coverage Δ
lib/jellyfish/room.ex 80.80% <0.00%> (-0.83%) ⬇️
lib/jellyfish_web/peer_socket.ex 88.88% <ø> (ø)
lib/jellyfish_web/server_socket.ex 78.33% <59.09%> (-2.44%) ⬇️
lib/jellyfish/room_service.ex 94.44% <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 9046a4d...ab115fe. Read the comment docs.

@roznawsk roznawsk marked this pull request as ready for review July 7, 2023 08:51
@roznawsk roznawsk requested review from LVala and mickel8 July 7, 2023 08:53
.gitmodules Outdated
@@ -1,5 +1,5 @@
[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.

Don't forget to revert this 🙏

Comment on lines 114 to 118
room_state = get_room_state(option)

%ServerMessage{content: room_state}
|> ServerMessage.encode()
|> then(&{:ok, &1})
Copy link
Member

Choose a reason for hiding this comment

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

I think that this is more readable (although its like 60% for this, 40% for what you wrote, it's up to you to decide):

Suggested change
room_state = get_room_state(option)
%ServerMessage{content: room_state}
|> ServerMessage.encode()
|> then(&{:ok, &1})
room_state = get_room_state(option)
msg =
%ServerMessage{content: room_state}
|> ServerMessage.encode()
{:ok, msg}

That's a nitpick tho.

Comment on lines 132 to 133
defp handle_request(request), do: request

Copy link
Member

Choose a reason for hiding this comment

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

I would remove the default case all together, or at least rise, we don't expect any other messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do raise, in the handle_in callback.

In this clause we return request instead of {:ok, mesage} so we raise in the with.
However this isn't explicit really.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @LVala on this -- I'd say either remove the default case, explicitly raise, or return something like {:error, :unknown_request} (and maybe log an error); either of these solutions is fine by me

Comment on lines 256 to 259
fn ->
conn = delete(conn, ~p"/room/#{room_id}/")
assert response(conn, :no_content)
end
Copy link
Member

Choose a reason for hiding this comment

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

This seems hacky, maybe let's create on_exit callback in setup block for the whole file which simply deletes all of the rooms. I considered doing this before but it wasn't necessary back then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do

@LVala
Copy link
Member

LVala commented Jul 10, 2023

I think the logic in elixir_server_sdk requirest some changes, see PR there.

@@ -83,13 +84,7 @@ defmodule JellyfishWeb.ServerSocket do

def handle_in({encoded_message, [opcode: :binary]}, state) 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 handle_in({encoded_message, [opcode: :binary]}, state) do
@impl true
def handle_in({encoded_message, [opcode: :binary]}, state) do

Copy link
Member

Choose a reason for hiding this comment

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

Nitpick; might as well annotate the handle_in callback from line 102.

Copy link
Member Author

Choose a reason for hiding this comment

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

tbh, I prefer to make the annotations only once - above the first callback clause, but if everyone prefers adding annotations before each callback I will change this

Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be clearer this way, GPT4 seems to agree, but ultimately it's your decision

Comment on lines 132 to 133
defp handle_request(request), do: request

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @LVala on this -- I'd say either remove the default case, explicitly raise, or return something like {:error, :unknown_request} (and maybe log an error); either of these solutions is fine by me

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

@sgfn sgfn left a comment

Choose a reason for hiding this comment

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

LGTM -- please wait for other reviews, though

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.

👍, just little nitpicks

{:ok, msg}
end

defp handle_subscribe(request), do: request
Copy link
Member

Choose a reason for hiding this comment

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

😠, pls remove

rooms
|> Enum.each(fn %{"id" => id} ->
conn = delete(conn, ~p"/room/#{id}")
response(conn, 204)
Copy link
Member

Choose a reason for hiding this comment

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

assert response()?

@roznawsk roznawsk merged commit 3b049c3 into main Jul 12, 2023
5 checks passed
@roznawsk roznawsk deleted the RTC-299-add-subscription branch July 12, 2023 12:05
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

3 participants