ws_subprotocol.erl 505 B

1234567891011121314151617181920
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(ws_subprotocol).
  3. -export([init/2]).
  4. -export([websocket_handle/2]).
  5. -export([websocket_info/2]).
  6. init(Req, Opts) ->
  7. [Protocol | _] = cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req),
  8. Req2 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, Protocol, Req),
  9. {cowboy_websocket, Req2, Opts, #{
  10. idle_timeout => 1000
  11. }}.
  12. websocket_handle(_Frame, State) ->
  13. {ok, State}.
  14. websocket_info(_Info, State) ->
  15. {ok, State}.