mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-23 14:27:15 +08:00
* 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
21 lines
577 B
Elixir
21 lines
577 B
Elixir
defmodule LivebookWeb.Output.JSComponent do
|
|
use LivebookWeb, :live_component
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<div id={"js-output-#{@id}"}
|
|
phx-hook="JSOutput"
|
|
phx-update="ignore"
|
|
data-ref={@info.ref}
|
|
data-assets-base-url={Routes.session_url(@socket, :show_asset, @session_id, @info.assets.hash, [])}
|
|
data-js-path={@info.assets.js_path}
|
|
data-session-token={session_token(@info.pid)}>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
defp session_token(pid) do
|
|
Phoenix.Token.sign(LivebookWeb.Endpoint, "js output", %{pid: pid})
|
|
end
|
|
end
|