ws_set_options_commands_h.erl 629 B

1234567891011121314151617181920
  1. %% This module sets options based on the frame received.
  2. -module(ws_set_options_commands_h).
  3. -behavior(cowboy_websocket).
  4. -export([init/2]).
  5. -export([websocket_handle/2]).
  6. -export([websocket_info/2]).
  7. init(Req, RunOrHibernate) ->
  8. {cowboy_websocket, Req, RunOrHibernate,
  9. #{idle_timeout => infinity}}.
  10. websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=run) ->
  11. {[{set_options, #{idle_timeout => 500}}, Frame], State};
  12. websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=hibernate) ->
  13. {[{set_options, #{idle_timeout => 500}}, Frame], State, hibernate}.
  14. websocket_info(_Info, State) ->
  15. {[], State}.