23 lines
629 B
Elixir
23 lines
629 B
Elixir
defmodule AugieWeb.CameraController do
|
|
alias Augie.Sensor.Camera
|
|
alias AugieWeb.CameraStream
|
|
use AugieWeb, :controller
|
|
|
|
def stream(conn, _params) do
|
|
{:ok, pid} = CameraStream.start_link()
|
|
CameraStream.stream(pid, conn)
|
|
end
|
|
|
|
def static(conn, _params) do
|
|
frame = Camera.last_frame(Camera)
|
|
size = byte_size(frame)
|
|
|
|
conn
|
|
|> put_resp_header("Age", "0")
|
|
|> put_resp_header("Cache-Control", "no-cache, private")
|
|
|> put_resp_header("Pragma", "no-cache")
|
|
|> put_resp_header("Content-Type", "image/jpeg")
|
|
|> put_resp_header("Content-Length", "#{size}")
|
|
|> resp(200, frame)
|
|
end
|
|
end
|