livebook/lib/livebook_web/channels/socket.ex
Jonatan Kłosko 19baf013d5
Introduce a dedicated channel for JS widget communication (#843)
* Introduce a dedicated channel for JS widget communication

* Handle payload serialization errors

* Tie channel lifetime to the session

* Catch serialization errors instead of encoding twice

* Merge JS static and dynamic outputs

* Authenticate socket connection from session

* Update JS output format

* Remove unused helper

* Apply review comments
2022-01-06 16:31:26 +01:00

26 lines
608 B
Elixir

defmodule LivebookWeb.Socket do
use Phoenix.Socket
# App channels
channel "js_output", LivebookWeb.JSOutputChannel
# LiveView channels
channel "lvu:*", Phoenix.LiveView.UploadChannel
channel "lv:*", Phoenix.LiveView.Channel
@impl true
def connect(params, socket, info) do
auth_mode = Livebook.Config.auth_mode()
if LivebookWeb.AuthPlug.authenticated?(info.session || %{}, info.uri.port, auth_mode) do
Phoenix.LiveView.Socket.connect(params, socket, info)
else
:error
end
end
@impl true
def id(socket) do
Phoenix.LiveView.Socket.id(socket)
end
end