mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Document the commands based Websocket interface
The old interface with ok|reply|stop tuples is deprecated.
This commit is contained in:
parent
2b38526351
commit
3977f2b96f
13 changed files with 108 additions and 81 deletions
|
@ -12,11 +12,11 @@ init(Req, _) ->
|
|||
}}.
|
||||
|
||||
websocket_handle({text, Data}, State) ->
|
||||
{reply, {text, Data}, State};
|
||||
{[{text, Data}], State};
|
||||
websocket_handle({binary, Data}, State) ->
|
||||
{reply, {binary, Data}, State};
|
||||
{[{binary, Data}], State};
|
||||
websocket_handle(_Frame, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_info(_Info, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
|
|
@ -12,17 +12,17 @@ init(Req, _) ->
|
|||
|
||||
websocket_init(State) ->
|
||||
erlang:start_timer(1000, self(), <<"websocket_init">>),
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_handle({text, Data}, State) ->
|
||||
{reply, {text, Data}, State};
|
||||
{[{text, Data}], State};
|
||||
websocket_handle({binary, Data}, State) ->
|
||||
{reply, {binary, Data}, State};
|
||||
{[{binary, Data}], State};
|
||||
websocket_handle(_Frame, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_info({timeout, _Ref, Msg}, State) ->
|
||||
erlang:start_timer(1000, self(), <<"websocket_handle">>),
|
||||
{reply, {text, Msg}, State};
|
||||
{[{text, Msg}], State};
|
||||
websocket_info(_Info, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
-module(ws_max_frame_size).
|
||||
|
||||
-export([init/2]).
|
||||
-export([websocket_init/1]).
|
||||
-export([websocket_handle/2]).
|
||||
-export([websocket_info/2]).
|
||||
|
||||
init(Req, State) ->
|
||||
{cowboy_websocket, Req, State, #{max_frame_size => 8}}.
|
||||
|
||||
websocket_init(State) ->
|
||||
{ok, State}.
|
||||
|
||||
websocket_handle({text, Data}, State) ->
|
||||
{reply, {text, Data}, State};
|
||||
{[{text, Data}], State};
|
||||
websocket_handle({binary, Data}, State) ->
|
||||
{reply, {binary, Data}, State};
|
||||
{[{binary, Data}], State};
|
||||
websocket_handle(_Frame, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_info(_Info, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
|
|
@ -12,10 +12,10 @@ init(Req, Opts) ->
|
|||
|
||||
websocket_init(State) ->
|
||||
erlang:send_after(10, self(), send_many),
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_handle(_Frame, State) ->
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
||||
websocket_info(send_many, State = [{sequence, Sequence}]) ->
|
||||
{reply, Sequence, State}.
|
||||
{Sequence, State}.
|
||||
|
|
|
@ -13,10 +13,10 @@ init(Req, _) ->
|
|||
}}.
|
||||
|
||||
websocket_handle({text, Data}, State) ->
|
||||
{reply, {text, Data}, State};
|
||||
{[{text, Data}], State};
|
||||
websocket_handle({binary, Data}, State) ->
|
||||
{reply, {binary, Data}, State}.
|
||||
{[{binary, Data}], State}.
|
||||
|
||||
websocket_info(_Info, State) ->
|
||||
erlang:start_timer(500, self(), should_not_cancel_timer),
|
||||
{ok, State}.
|
||||
{[], State}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue