fix tests
parent
bdd7b3d555
commit
f1a421af8d
|
@ -16,7 +16,8 @@ defmodule Farmbot.Configurator do
|
|||
def init([]) do
|
||||
Logger.debug ">> Configurator init!"
|
||||
children = [
|
||||
Plug.Adapters.Cowboy.child_spec(:http, Router, [], port: @port, dispatch: [dispatch()]),
|
||||
Plug.Adapters.Cowboy.child_spec(:http, Router, [], port: @port,
|
||||
dispatch: [dispatch()]),
|
||||
Plug.Adapters.Cowboy.child_spec(:http, Streamer, [], port: @streamer_port)
|
||||
]
|
||||
opts = [strategy: :one_for_one]
|
|
@ -17,13 +17,14 @@ defmodule Farmbot.Configurator.Router do
|
|||
|
||||
get "/image/latest" do
|
||||
list_images = fn() ->
|
||||
File.ls!("/tmp/images")
|
||||
"/tmp/images"
|
||||
|> File.ls!
|
||||
|> Enum.reduce("", fn(image, acc) ->
|
||||
acc <> "<img src=\"/image/#{image}\">"
|
||||
end)
|
||||
end
|
||||
html =
|
||||
"""
|
||||
~s"""
|
||||
<html>
|
||||
<body>
|
||||
<form action=/image/capture>
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Farmbot.Configurator.SocketHandler do
|
|||
alias Farmbot.Transport.WebSocket, as: WSTransport
|
||||
# alias Farmbot.Transport.Serialized, as: Ser
|
||||
|
||||
@timeout 60000 # terminate if no activity for one minute
|
||||
@timeout 60_000 # terminate if no activity for one minute
|
||||
@ping "\"ping\""
|
||||
@pong "\"pong\""
|
||||
@timer 2000
|
||||
|
@ -39,7 +39,7 @@ defmodule Farmbot.Configurator.SocketHandler do
|
|||
# i guess instead of running a timer i could just use this to send teh next
|
||||
# ping, but that sounds like it could suck up some bandwidth.
|
||||
def websocket_handle({:text, @pong}, req, stage), do: {:ok, req, stage}
|
||||
|
||||
|
||||
# messages from the browser.
|
||||
def websocket_handle({:text, m}, req, stage) do
|
||||
Logger.debug ">> can't handle data from websocket: #{inspect m}"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
defmodule Plug.Streamer do
|
||||
@moduledoc """
|
||||
Plug for streaming an image
|
||||
"""
|
||||
alias Plug.Conn
|
||||
import Conn
|
||||
@behaviour Plug
|
||||
|
@ -7,10 +10,10 @@ defmodule Plug.Streamer do
|
|||
def init(opts), do: opts
|
||||
|
||||
def call(conn, _opts) do
|
||||
conn = put_resp_header(conn, "content-type", "multipart/x-mixed-replace; boundary=#{@boundry}")
|
||||
conn = send_chunked(conn, 200)
|
||||
send_picture(conn)
|
||||
conn
|
||||
conn |>
|
||||
put_resp_header("content-type", "multipart/x-mixed-replace; boundary=#{@boundry}")
|
||||
|> send_chunked(200)
|
||||
|> send_picture
|
||||
end
|
||||
|
||||
defp send_picture(conn) do
|
||||
|
|
|
@ -45,7 +45,7 @@ defmodule Farmbot.Transport.GenMqtt do
|
|||
{:ok, pid} = start_client(t)
|
||||
{:noreply, [], {pid, t}}
|
||||
end
|
||||
|
||||
|
||||
def handle_info({:authorization, %Token{} = new_t}, {client, _})
|
||||
when is_pid(client) do
|
||||
# Probably a good idea to restart mqtt here.
|
||||
|
|
Loading…
Reference in New Issue