aboutsummaryrefslogtreecommitdiffstats
path: root/test/ws_send_many_handler.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-10-11 21:46:43 +0200
committerLoïc Hoguin <[email protected]>2012-10-11 21:46:43 +0200
commit09914c4693562bfde644b73a2ed5e6bac7362b4c (patch)
tree557c15cb4f6c41b94a6de4811be9f0c1e58499c6 /test/ws_send_many_handler.erl
parent160063497cade2c5334cc06859a43afec7183e78 (diff)
downloadcowboy-09914c4693562bfde644b73a2ed5e6bac7362b4c.tar.gz
cowboy-09914c4693562bfde644b73a2ed5e6bac7362b4c.tar.bz2
cowboy-09914c4693562bfde644b73a2ed5e6bac7362b4c.zip
Allow websocket handlers to reply more than one frame
Instead of returning {text, Data}, you can now return [{text, Data}, {text, Data2}, ...].
Diffstat (limited to 'test/ws_send_many_handler.erl')
-rw-r--r--test/ws_send_many_handler.erl31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/ws_send_many_handler.erl b/test/ws_send_many_handler.erl
new file mode 100644
index 0000000..ee386ba
--- /dev/null
+++ b/test/ws_send_many_handler.erl
@@ -0,0 +1,31 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(ws_send_many_handler).
+-behaviour(cowboy_websocket_handler).
+
+-export([init/3]).
+-export([websocket_init/3]).
+-export([websocket_handle/3]).
+-export([websocket_info/3]).
+-export([websocket_terminate/3]).
+
+init(_Any, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_websocket}.
+
+websocket_init(_TransportName, Req, _Opts) ->
+ Req2 = cowboy_req:compact(Req),
+ erlang:send_after(10, self(), send_many),
+ {ok, Req2, undefined}.
+
+websocket_handle(_Frame, Req, State) ->
+ {ok, Req, State}.
+
+websocket_info(send_many, Req, State) ->
+ {reply, [
+ {text, <<"one">>},
+ {text, <<"two">>},
+ {text, <<"seven!">>}
+ ], Req, State}.
+
+websocket_terminate(_Reason, _Req, _State) ->
+ ok.