%% vim: ts=4 sw=4 et -module(simple_bridge_handler_sample). -behaviour(simple_bridge_handler). -export([run/1, ws_init/1, ws_message/3, ws_info/3, ws_terminate/3]). run(Bridge) -> try Bridge2 = sbw:set_response_data(body(Bridge), Bridge), sbw:build_response(Bridge2) catch E:T:S -> error_logger:error_msg("~p:~p: ~p",[E, T, S]), exit("Error building response") end. ws_init(_Bridge) -> %erlang:send_after(1000, self(), "START"), ok. ws_message({text, <<"frag">>}, _State, _Bridge) -> Reply = [{text, [Msg," "]} || Msg <- ["A","spoon","full","of","sugar"]], {reply, Reply}; ws_message({text, Data}, _Bridge, _State) -> %Reply = io_lib:format("~s", [Data]), {reply, {text, Data}}; ws_message({binary, Data}, _Bridge, _State) -> {reply, {binary, Data}}. ws_info(Data, _Bridge, _State) -> Reply = {text, io_lib:format("~s", [Data])}, {reply, Reply}. ws_terminate(_Reason, _Bridge, _State) -> ok. %%% HTML BODY AND DRAWING TESTING THE BRIDGE CAPABILITIES body(Bridge) -> [ <<"
~p