user_socket.ex 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. defmodule OpenpodWeb.UserSocket do
  2. use Phoenix.Socket
  3. ## Channels
  4. # channel "room:*", OpenpodWeb.RoomChannel
  5. # Socket params are passed from the client and can
  6. # be used to verify and authenticate a user. After
  7. # verification, you can put default assigns into
  8. # the socket that will be set for all channels, ie
  9. #
  10. # {:ok, assign(socket, :user_id, verified_user_id)}
  11. #
  12. # To deny connection, return `:error`.
  13. #
  14. # See `Phoenix.Token` documentation for examples in
  15. # performing token verification on connect.
  16. @impl true
  17. def connect(_params, socket, _connect_info) do
  18. {:ok, socket}
  19. end
  20. # Socket id's are topics that allow you to identify all sockets for a given user:
  21. #
  22. # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
  23. #
  24. # Would allow you to broadcast a "disconnect" event and terminate
  25. # all active sockets and channels for a given user:
  26. #
  27. # OpenpodWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
  28. #
  29. # Returning `nil` makes this socket anonymous.
  30. @impl true
  31. def id(_socket), do: nil
  32. end