This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
augie/webapp/lib/augie_web/controllers/camera_controller.ex

24 lines
629 B
Elixir
Raw Normal View History

2020-04-28 21:09:54 +12:00
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