%% vim: ts=4 sw=4 et -module(simple_bridge_handler_sample). -behaviour(simple_bridge_handler). %% This next line is only because of the erlang:get_stacktrace call below. %% As the try/catch semantics changed in Erlang 21, this is kept for backwards %% compatibility. Feel free to remove this parse transform, if you wish. -compile({parse_transform, stacktrace_transform}). -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:C -> error_logger:error_msg("~p:~p: ~p",[E, C, erlang:get_stacktrace()]), 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