defmodule LivebookWeb.SessionLive.AttachedLive do use LivebookWeb, :live_view import Ecto.Changeset alias Livebook.{Session, Runtime} @impl true def mount( _params, %{"session_pid" => session_pid, "current_runtime" => current_runtime}, socket ) do session = Session.get_by_pid(session_pid) unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do raise "runtime module not allowed" end if connected?(socket) do Session.subscribe(session.id) end {:ok, assign(socket, session: session, current_runtime: current_runtime, error_message: nil, changeset: changeset(current_runtime) )} end defp changeset(runtime, attrs \\ %{}) do data = case runtime do %Runtime.Attached{node: node, cookie: cookie} -> %{name: Atom.to_string(node), cookie: Atom.to_string(cookie)} _ -> %{name: nil, cookie: nil} end types = %{name: :string, cookie: :string} cast({data, types}, attrs, [:name, :cookie]) |> validate_required([:name, :cookie]) end @impl true def render(assigns) do ~H"""
Connect the session to an already running node and evaluate code in the context of that node. The node must run Erlang/OTP <%= :erlang.system_info(:otp_release) %> and Elixir <%= System.version() %> (or later). Make sure to give the node a name and a cookie, for example:
iex --name test@<%= longname %> --cookie mycookie -S mix
<% else %>
iex --sname test --cookie mycookie -S mix
<% end %>
Then enter the connection information below:
<.form :let={f} for={@changeset} as={:data} phx-submit="init" phx-change="validate" autocomplete="off" spellcheck="false" >