Skip to content

Commit bc05282

Browse files
committed
Include time in EOT message
1 parent 7894941 commit bc05282

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/asciinema/streaming/live_stream_server.ex

+5-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ defmodule Asciinema.Streaming.LiveStreamServer do
207207
Logger.info("stream/#{state.stream_id}: terminating (#{inspect(reason)})")
208208
Logger.debug("stream/#{state.stream_id}: state: #{inspect(state)}")
209209

210-
publish(state.stream_id, :end)
210+
time = current_stream_time(state.last_stream_time, state.last_event_time) || 0.0
211+
publish(state.stream_id, :end, %{time: time})
211212
Streaming.update_live_stream(state.stream, online: false)
212213

213214
:ok
@@ -222,7 +223,7 @@ defmodule Asciinema.Streaming.LiveStreamServer do
222223
%{state | last_stream_time: time, last_event_time: Timex.now()}
223224
end
224225

225-
defp publish(stream_id, event, data \\ nil) do
226+
defp publish(stream_id, event, data) do
226227
update = %Update{
227228
stream_id: stream_id,
228229
event: event,
@@ -271,6 +272,8 @@ defmodule Asciinema.Streaming.LiveStreamServer do
271272
%{state | shutdown_timer: timer}
272273
end
273274

275+
defp current_stream_time(nil, nil), do: nil
276+
274277
defp current_stream_time(last_stream_time, last_event_time) do
275278
last_stream_time + Timex.diff(Timex.now(), last_event_time, :microseconds)
276279
end

lib/asciinema_web/live_stream_consumer_socket.ex

+8-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ defmodule AsciinemaWeb.LiveStreamConsumerSocket do
128128
{:reply, marker_message(time, label), state}
129129
end
130130

131-
def websocket_info(%LiveStreamServer.Update{event: :end}, state) do
132-
{:reply, eot_message(), state}
131+
def websocket_info(%LiveStreamServer.Update{event: :end} = update, state) do
132+
%{time: time} = update.data
133+
134+
{:reply, eot_message(time), state}
133135
end
134136

135137
def websocket_info(:client_ping, state) do
@@ -310,10 +312,12 @@ defmodule AsciinemaWeb.LiveStreamConsumerSocket do
310312
{:binary, msg}
311313
end
312314

313-
defp eot_message do
315+
defp eot_message(time) do
314316
msg = <<
315317
# message type: EOT
316-
0x04::8
318+
0x04::8,
319+
# current stream time
320+
time::little-64
317321
>>
318322

319323
{:binary, msg}

0 commit comments

Comments
 (0)