Skip to content

Commit

Permalink
Save whole env passed to a stream in recorded asciicast file
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Feb 26, 2025
1 parent dabdcec commit 6025f02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/asciinema/streaming/stream_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,7 @@ defmodule Asciinema.Streaming.StreamServer do
file = File.open!(path, [:write, :utf8])
state = %{state | path: path, file: file}
timestamp = Timex.to_unix(Timex.now())

env =
%{"TERM" => query["term"], "SHELL" => query["shell"]}
|> Enum.filter(fn {_k, v} -> v != nil and v != "" end)
|> Enum.into(%{})
env = drop_empty(query["env"] || %{})

write_asciicast_v2_header(file, cols, rows, timestamp, env, theme)

Expand All @@ -364,16 +360,14 @@ defmodule Asciinema.Streaming.StreamServer do

defp write_asciicast_v2_header(file, cols, rows, timestamp, env, theme) do
header =
%{
drop_empty(%{
version: 2,
width: cols,
height: rows,
timestamp: timestamp,
env: env,
theme: asciicast_theme(theme)
}
|> Enum.filter(fn {_k, v} -> v != nil and v != %{} end)
|> Enum.into(%{})
})

:ok = IO.write(file, Jason.encode!(header) <> "\n")
end
Expand All @@ -387,6 +381,12 @@ defmodule Asciinema.Streaming.StreamServer do
:ok = IO.write(file, event <> "\n")
end

defp drop_empty(map) when is_map(map) do
map
|> Enum.filter(fn {_k, v} -> v != nil and v != "" and v != %{} end)
|> Enum.into(%{})
end

defp in_sync?(state, last_event_id),
do: last_event_id != 0 and last_event_id == state.last_event_id

Expand Down
3 changes: 2 additions & 1 deletion lib/asciinema_web/stream_producer_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule AsciinemaWeb.StreamProducerSocket do
params = %{
token: req.bindings[:producer_token],
user_agent: req.headers["user-agent"],
query: URI.decode_query(req.qs),
query: Plug.Conn.Query.decode(req.qs),
parser: nil
}

Expand All @@ -42,6 +42,7 @@ defmodule AsciinemaWeb.StreamProducerSocket do
@impl true
def websocket_init(params) do
%{token: token, parser: parser, user_agent: user_agent, query: query} = params
Logger.debug("producer: query: #{inspect(query)}")

case Streaming.find_stream_by_producer_token(token) do
nil ->
Expand Down

0 comments on commit 6025f02

Please sign in to comment.