ws_send_many.erl 693 B

123456789101112131415161718192021222324252627
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(ws_send_many).
  3. -behaviour(cowboy_websocket_handler).
  4. -export([init/3]).
  5. -export([websocket_init/3]).
  6. -export([websocket_handle/3]).
  7. -export([websocket_info/3]).
  8. -export([websocket_terminate/3]).
  9. init(_Any, _Req, _Opts) ->
  10. {upgrade, protocol, cowboy_websocket}.
  11. websocket_init(_TransportName, Req, Sequence) ->
  12. Req2 = cowboy_req:compact(Req),
  13. erlang:send_after(10, self(), send_many),
  14. {ok, Req2, Sequence}.
  15. websocket_handle(_Frame, Req, State) ->
  16. {ok, Req, State}.
  17. websocket_info(send_many, Req, State = [{sequence, Sequence}]) ->
  18. {reply, Sequence, Req, State}.
  19. websocket_terminate(_Reason, _Req, _State) ->
  20. ok.