littlelines / littlechat

A peer-to-peer video chat application made using Phoenix, LiveView, and WebRTC. Want to know how it's made? Read the blog post: https://littlelines.com/blog/2020/07/06/building-a-video-chat-app-in-phoenix-liveview
https://littlechat.app
MIT License
190 stars 21 forks source link

:ets.lookup argument error #4

Closed SlowburnAZ closed 4 years ago

SlowburnAZ commented 4 years ago

Sorry if this isn't the place to ask this, but while following along with your blog post, after adding the tracking of a user, I'm getting the following error:

[error] #PID<0.531.0> running LittlechatWeb.Endpoint (connection #PID<0.501.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /room/test-room-1
** (exit) an exception was raised:
    ** (ArgumentError) argument error
        (stdlib 3.13) :ets.lookup(LittlechatWeb.Presence, :pool_size)
        (phoenix_pubsub 2.0.0) lib/phoenix/tracker.ex:311: Phoenix.Tracker.pool_size/1
        (phoenix_pubsub 2.0.0) lib/phoenix/tracker.ex:165: Phoenix.Tracker.track/5
        (littlechat 0.1.0) lib/littlechat_web/live/room/show_live.ex:23: LittlechatWeb.Room.ShowLive.mount/3
        (phoenix_live_view 0.13.3) lib/phoenix_live_view/utils.ex:256: Phoenix.LiveView.Utils.maybe_call_mount!/3
        (phoenix_live_view 0.13.3) lib/phoenix_live_view/static.ex:302: Phoenix.LiveView.Static.call_mount_and_handle_params!/5
        (phoenix_live_view 0.13.3) lib/phoenix_live_view/static.ex:127: Phoenix.LiveView.Static.render/3
        (phoenix_live_view 0.13.3) lib/phoenix_live_view/controller.ex:35: Phoenix.LiveView.Controller.live_render/3
        (phoenix 1.5.3) lib/phoenix/router.ex:352: Phoenix.Router.__call__/2
        (littlechat 0.1.0) lib/littlechat_web/endpoint.ex:1: LittlechatWeb.Endpoint.plug_builder_call/2
        (littlechat 0.1.0) lib/plug/debugger.ex:132: LittlechatWeb.Endpoint."call (overridable 3)"/2
        (littlechat 0.1.0) lib/littlechat_web/endpoint.ex:1: LittlechatWeb.Endpoint.call/2
        (phoenix 1.5.3) lib/phoenix/endpoint/cowboy2_handler.ex:65: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.8.0) /mnt/c/Users/Chris/projects/littlechat/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.8.0) /mnt/c/Users/Chris/projects/littlechat/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
        (cowboy 2.8.0) /mnt/c/Users/Chris/projects/littlechat/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
        (stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

The specific line is {:ok, _} = Presence.track(self(), "room:" <> slug, user.uuid, %{})

It seems the code is correct, but I can't find anything about what might cause this.

SlowburnAZ commented 4 years ago

In case it's relevant, I'm running this all in WSL (Ubuntu) on Windows 10

JesseHerrick commented 4 years ago

Hey @SlowburnAZ, no worries, this is the perfect place to ask - and thanks for bringing this to my attention.

Do you have LittlechatWeb.Presence in your supervision tree in application.ex under the PubSub line? Looking at the article again, it looks like I missed mentioning that. You can use this file for reference: https://github.com/littlelines/littlechat/blob/master/lib/littlechat/application.ex.

SlowburnAZ commented 4 years ago

Thanks, @JesseHerrick ... that mostly worked. I also had to update the assign in the handle_info function from

def handle_info(%Broadcast{event: "presence_diff"}, socket) do
  {:noreply,
     socket
     |> assign(:connected_users, Presence.list("room:" <> socket.assigns.slug))}
end

to

def handle_info(%Broadcast{event: "presence_diff"}, socket) do
  {:noreply,
     socket
     |> assign(:connected_users, list_present(socket)}
end

image

JesseHerrick commented 4 years ago

@SlowburnAZ glad you got it working! Sometimes keeping track of the changes made to the code in the article and the codebase can be tricky when writing up something like this.

It looks like I missed updating that codeblock from an older version of the codebase as I was working out the details 😄. Let me know if you run into anything else!

Cryde commented 4 years ago

Notes for futurs people who will read this : I had the same issue as mention here, I just had to abort + relaunch the server and it worked ! :D