diff options
author | Loïc Hoguin <[email protected]> | 2016-08-24 17:25:33 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-08-24 17:25:33 +0200 |
commit | 7839f1367194813c70d7e223a476f96a62b298ae (patch) | |
tree | d5f7be7d443c47dfc67856e9c10474232cb79686 /doc/src/guide/ws_handlers.asciidoc | |
parent | b9ad02d3057e78ff82dacbd38042e33073c4bc75 (diff) | |
download | cowboy-7839f1367194813c70d7e223a476f96a62b298ae.tar.gz cowboy-7839f1367194813c70d7e223a476f96a62b298ae.tar.bz2 cowboy-7839f1367194813c70d7e223a476f96a62b298ae.zip |
More 2.0 documentation updates
Still incomplete.
Diffstat (limited to 'doc/src/guide/ws_handlers.asciidoc')
-rw-r--r-- | doc/src/guide/ws_handlers.asciidoc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/doc/src/guide/ws_handlers.asciidoc b/doc/src/guide/ws_handlers.asciidoc index 9ddddf4..b280fd8 100644 --- a/doc/src/guide/ws_handlers.asciidoc +++ b/doc/src/guide/ws_handlers.asciidoc @@ -18,8 +18,8 @@ must return a `ws` tuple. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_websocket, Req, #state{}}. +init(Req, State) -> + {cowboy_websocket, Req, State}. ---- Upon receiving this tuple, Cowboy will switch to the code @@ -34,18 +34,18 @@ the connection, assuming no correct subprotocol was found. [source,erlang] ---- -init(Req, _Opts) -> +init(Req, State) -> case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of undefined -> - {ok, Req, #state{}}; + {ok, Req, State}; Subprotocols -> case lists:keymember(<<"mychat2">>, 1, Subprotocols) of true -> Req2 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, <<"mychat2">>, Req), - {ok, Req2, #state{}}; + {ok, Req2, State}; false -> - {stop, Req, undefined} + {stop, Req, State} end end. ---- @@ -60,12 +60,14 @@ It is also very easy to ensure that this message arrives before any message from other processes by sending it before registering or enabling timers. +// @todo This doesn't even work. + [source,erlang] ---- -init(Req, _Opts) -> +init(Req, State) -> self() ! post_init, %% Register process here... - {cowboy_websocket, Req, #state{}}. + {cowboy_websocket, Req, State}. websocket_info(post_init, Req, State) -> %% Perform post_init initialization here... @@ -169,8 +171,8 @@ A good timeout value is 60 seconds. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_websocket, Req, #state{}, 60000}. +init(Req, State) -> + {cowboy_websocket, Req, State, 60000}. ---- This value cannot be changed once it is set. It defaults to |