Initial commit: there's still tons of base Phoenix boilerplate to remove, but the...
[tech-radar-editor.git] / web / channels / user_socket.ex
1 defmodule TechRadarEditor.UserSocket do
2 use Phoenix.Socket
3
4 ## Channels
5 # channel "room:*", TechRadarEditor.RoomChannel
6
7 ## Transports
8 transport :websocket, Phoenix.Transports.WebSocket
9 # transport :longpoll, Phoenix.Transports.LongPoll
10
11 # Socket params are passed from the client and can
12 # be used to verify and authenticate a user. After
13 # verification, you can put default assigns into
14 # the socket that will be set for all channels, ie
15 #
16 # {:ok, assign(socket, :user_id, verified_user_id)}
17 #
18 # To deny connection, return `:error`.
19 #
20 # See `Phoenix.Token` documentation for examples in
21 # performing token verification on connect.
22 def connect(_params, socket) do
23 {:ok, socket}
24 end
25
26 # Socket id's are topics that allow you to identify all sockets for a given user:
27 #
28 # def id(socket), do: "users_socket:#{socket.assigns.user_id}"
29 #
30 # Would allow you to broadcast a "disconnect" event and terminate
31 # all active sockets and channels for a given user:
32 #
33 # TechRadarEditor.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{})
34 #
35 # Returning `nil` makes this socket anonymous.
36 def id(_socket), do: nil
37 end