livebook/lib/livebook_web/live/output/js_component.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

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