Skip to content

Instantly share code, notes, and snippets.

@xadhoom
Created October 5, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadhoom/b095db939cdf3c9d3add to your computer and use it in GitHub Desktop.
Save xadhoom/b095db939cdf3c9d3add to your computer and use it in GitHub Desktop.
diff --git a/lib/elixir_mod_event/connection.ex b/lib/elixir_mod_event/connection.ex
index 26dc043..43bb486 100644
--- a/lib/elixir_mod_event/connection.ex
+++ b/lib/elixir_mod_event/connection.ex
@@ -296,7 +296,7 @@ defmodule FSModEvent.Connection do
Logger.info "Starting FS connection"
{:ok, socket} = :gen_tcp.connect(
to_char_list(options[:host]), options[:port], [
- packet: 0, active: :once, mode: :list
+ packet: 0, active: :once, mode: :binary
]
)
{:ok, %FSModEvent.Connection{
diff --git a/lib/elixir_mod_event/content.ex b/lib/elixir_mod_event/content.ex
index e9aa64a..8d65c2e 100644
--- a/lib/elixir_mod_event/content.ex
+++ b/lib/elixir_mod_event/content.ex
@@ -25,6 +25,10 @@ defmodule FSModEvent.Content do
event_plain data, %{}
end
+ def parse("text/event-json", data) do
+ event_json data
+ end
+
def parse(_, data), do: {data, nil}
defp event_plain(data, acc) do
@@ -40,4 +44,9 @@ defmodule FSModEvent.Content do
_error -> nil
end
end
-end
\ No newline at end of file
+
+ defp event_json(data) do
+ {:jiffy.decode(data, [:return_maps]), ""}
+ end
+
+end
diff --git a/mix.exs b/mix.exs
index d46b464..202fe30 100644
--- a/mix.exs
+++ b/mix.exs
@@ -46,7 +46,8 @@ Find the user guide in the github repo at: https://github.com/marcelog/elixir_mo
{:earmark, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.7", only: :dev},
{:coverex, "~> 1.4.1", only: :test},
- {:uuid, "~> 1.0"}
+ {:uuid, "~> 1.0"},
+ {:jiffy, git: "https://github.com/davisp/jiffy.git", tag: "0.14.3"}
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment