ws_echo.erl 484 B

12345678910111213141516171819202122
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(ws_echo).
  3. -export([init/2]).
  4. -export([websocket_handle/2]).
  5. -export([websocket_info/2]).
  6. init(Req, _) ->
  7. {cowboy_websocket, Req, undefined, #{
  8. compress => true
  9. }}.
  10. websocket_handle({text, Data}, State) ->
  11. {reply, {text, Data}, State};
  12. websocket_handle({binary, Data}, State) ->
  13. {reply, {binary, Data}, State};
  14. websocket_handle(_Frame, State) ->
  15. {ok, State}.
  16. websocket_info(_Info, State) ->
  17. {ok, State}.