| 1 |
%% This module sends an empty ping to the client and |
| 2 |
%% waits for a pong before sending a text frame. It |
| 3 |
%% is used to confirm server-initiated pings work. |
| 4 |
|
| 5 |
-module(ws_ping_h). |
| 6 |
-behavior(cowboy_websocket). |
| 7 |
|
| 8 |
-export([init/2]). |
| 9 |
-export([websocket_init/1]). |
| 10 |
-export([websocket_handle/2]). |
| 11 |
-export([websocket_info/2]). |
| 12 |
|
| 13 |
init(Req, _) -> |
| 14 |
{cowboy_websocket, Req, undefined}. |
| 15 |
|
| 16 |
websocket_init(State) -> |
| 17 |
{[{ping, <<>>}], State}. |
| 18 |
|
| 19 |
websocket_handle(pong, State) -> |
| 20 |
{[{text, <<"OK!!">>}], State}. |
| 21 |
|
| 22 |
websocket_info(_, State) -> |
| 23 |
{[], State}. |