mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-10 17:08:29 +08:00
19baf013d5
* 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
26 lines
608 B
Elixir
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
|