hecate_plugin_ws (hecate_sdk v0.6.2)
View SourceWebSocket helper for plugin live UIs.
Provides a base behaviour for plugin WebSocket handlers. Handles JSON encoding/decoding and standard message framing.
Usage in a plugin: -module(my_plugin_ws). -behaviour(cowboy_websocket). -export([init/2, websocket_init/1, websocket_handle/2, websocket_info/2]).
init(Req, State) -> hecate_plugin_ws:upgrade(Req, State).
websocket_handle({text, Data}, State) -> Msg = hecate_plugin_ws:decode(Data), %% handle Msg ... {reply, hecate_plugin_ws:encode(Response), State}.
Summary
Functions
Decode a JSON binary into a map.
Encode a term as a JSON text frame.
Send a JSON error reply.
Send a JSON reply with a type tag.
Upgrade an HTTP request to WebSocket.
Functions
Decode a JSON binary into a map.
Encode a term as a JSON text frame.
Send a JSON error reply.
Send a JSON reply with a type tag.
-spec upgrade(cowboy_req:req(), term()) -> {cowboy_websocket, cowboy_req:req(), term()}.
Upgrade an HTTP request to WebSocket.