Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
add missing change_callback implementation
  • Loading branch information
janl committed Apr 17, 2016
1 parent f9cd1d9 commit 47651e4cd2fa9b97498fa20ed29b7720e480b0e6
Showing 1 changed file with 28 additions and 0 deletions.
@@ -127,6 +127,34 @@ changes_callback({stop, EndSeq, _Pending}, #acc{feed="continuous"}=Acc) ->
[?JSON_ENCODE({[{<<"last_seq">>, EndSeq}]}) | "\n"]),
chttpd:end_delayed_json_response(Resp1);

% callbacks for eventsource feed (newline-delimited eventsource Objects)
changes_callback(start, #acc{feed = "eventsource"} = Acc) ->
#acc{resp = Req} = Acc,
Headers = [
{"Content-Type", "text/event-stream"},
{"Cache-Control", "no-cache"}
],
{ok, Resp} = chttpd:start_delayed_json_response(Req, 200, Headers),
{ok, Acc#acc{resp = Resp, last_data_sent_time=os:timestamp()}};
changes_callback({change, {ChangeProp}=Change}, #acc{resp = Resp, feed = "eventsource"} = Acc) ->
Seq = proplists:get_value(seq, ChangeProp),
Chunk = [
"data: ", ?JSON_ENCODE(Change),
"\n", "id: ", ?JSON_ENCODE(Seq),
"\n\n"
],
{ok, Resp1} = chttpd:send_delayed_chunk(Resp, Chunk),
maybe_finish(Acc#acc{resp = Resp1});
changes_callback(timeout, #acc{feed = "eventsource"} = Acc) ->
#acc{resp = Resp} = Acc,
Chunk = "event: heartbeat\ndata: \n\n",
{ok, Resp1} = chttpd:send_delayed_chunk(Resp, Chunk),
{ok, {"eventsource", Resp1}};
changes_callback({stop, _EndSeq}, #acc{feed = "eventsource"} = Acc) ->
#acc{resp = Resp} = Acc,
% {ok, Resp1} = chttpd:send_delayed_chunk(Resp, Buf),
chttpd:end_delayed_json_response(Resp);

% callbacks for longpoll and normal (single JSON Object)
changes_callback(start, #acc{feed="normal", etag=Etag}=Acc)
when Etag =/= undefined ->

0 comments on commit 47651e4

Please sign in to comment.