| name | debug-channel |
| description | Debug WebSocket channel issues |
Debug WebSocket Channel
Guide for diagnosing and fixing WebSocket channel issues in Levee.
Key Files
| File | Purpose |
|---|
lib/levee_web/channels/document_channel.ex | Channel message handlers |
lib/levee_web/channels/user_socket.ex | Socket configuration |
lib/levee/documents/session.ex | Document session GenServer |
test/levee_web/channels/document_channel_test.exs | Channel tests |
test/support/channel_case.ex | Test helpers |
Channel Lifecycle
1. WebSocket Connect → UserSocket.connect/3
2. Join Topic → DocumentChannel.join/3 (validates but doesn't auth)
3. Connect Document → handle_in("connect_document") (authenticates)
4. Operations → handle_in("submitOp"), handle_in("submitSignal")
5. Leave/Disconnect → terminate/2
Common Issues
1. Join Succeeds but Operations Fail
Symptom: Client joins channel but submitOp returns errors.
Cause: Channel join succeeds without auth; connect_document must be called first.
Check:
# In document_channel.ex
def handle_in("submitOp", payload, socket) do
case socket.assigns[:authenticated] do
true -> # proceed
_ -> {:reply, {:error, %{reason: "not_authenticated"}}, socket}
end
end
2. Token Validation Failures
Symptom: returns auth error.