| 1 |
-module(ws_h). |
| 2 |
|
| 3 |
-export([init/2]). |
| 4 |
-export([websocket_init/1]). |
| 5 |
-export([websocket_handle/2]). |
| 6 |
-export([websocket_info/2]). |
| 7 |
|
| 8 |
init(Req, Opts) -> |
| 9 |
{cowboy_websocket, Req, Opts}. |
| 10 |
|
| 11 |
websocket_init(State) -> |
| 12 |
erlang:start_timer(1000, self(), <<"Hello!">>), |
| 13 |
{[], State}. |
| 14 |
|
| 15 |
websocket_handle({text, Msg}, State) -> |
| 16 |
{[{text, << "That's what she said! ", Msg/binary >>}], State}; |
| 17 |
websocket_handle(_Data, State) -> |
| 18 |
{[], State}. |
| 19 |
|
| 20 |
websocket_info({timeout, _Ref, Msg}, State) -> |
| 21 |
erlang:start_timer(1000, self(), <<"How' you doin'?">>), |
| 22 |
{[{text, Msg}], State}; |
| 23 |
websocket_info(_Info, State) -> |
| 24 |
{[], State}. |