Created
September 7, 2014 19:17
Revisions
-
Jason S. revised this gist
Sep 7, 2014 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,4 +5,14 @@ def index(conn, %{"event" => "true"}) do {:ok, conn} = chunk(conn, ["data: ", JSON.encode!(Thermostat.Data.get()), "\n\n"]) Phoenix.Topic.subscribe self, "data" data_updated(conn) end defp data_updated(conn) do receive do { :update, data } -> IO.puts "GOT DATA" {:ok, conn} = chunk(conn, ["data: ", JSON.encode!(data), "\n\n"]) _ -> end data_updated(conn) end -
Jason S. created this gist
Sep 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ def index(conn, %{"event" => "true"}) do conn = conn |> put_resp_content_type("text/event-stream") |> send_chunked(200) {:ok, conn} = chunk(conn, ["data: ", JSON.encode!(Thermostat.Data.get()), "\n\n"]) Phoenix.Topic.subscribe self, "data" data_updated(conn) end