WebsockexNova.Behaviors.ClientBehavior behaviour (WebsockexNova v0.1.1)
View SourceBehavior defining the contract for WebSocket client operations.
This behavior ensures a consistent API for WebSocket client operations across different implementations and enables proper mocking in tests.
Summary
Callbacks
Authenticates with the WebSocket server.
Closes the WebSocket connection.
Connects to a WebSocket server using the specified adapter.
Sends a ping message to the WebSocket server.
Registers a process to receive notifications from the connection.
Sends a raw WebSocket frame.
Sends a JSON message.
Sends a text message.
Gets the current connection status.
Subscribes to a channel or topic.
Unregisters a process from receiving notifications.
Unsubscribes from a channel or topic.
Callbacks
@callback authenticate( conn :: WebsockexNova.ClientConn.t(), credentials :: map(), options :: map() | nil ) :: {:ok, WebsockexNova.ClientConn.t(), term()} | {:error, term()} | {:error, term(), WebsockexNova.ClientConn.t()}
Authenticates with the WebSocket server.
@callback close(conn :: WebsockexNova.ClientConn.t()) :: :ok
Closes the WebSocket connection.
@callback connect(adapter :: module(), options :: map()) :: {:ok, WebsockexNova.ClientConn.t()} | {:error, term()}
Connects to a WebSocket server using the specified adapter.
@callback ping(conn :: WebsockexNova.ClientConn.t(), options :: map() | nil) :: {:ok, :pong} | {:error, term()}
Sends a ping message to the WebSocket server.
@callback register_callback(conn :: WebsockexNova.ClientConn.t(), pid :: pid()) :: {:ok, WebsockexNova.ClientConn.t()}
Registers a process to receive notifications from the connection.
@callback send_frame(conn :: WebsockexNova.ClientConn.t(), frame :: term()) :: :ok | {:error, term()}
Sends a raw WebSocket frame.
@callback send_json( conn :: WebsockexNova.ClientConn.t(), data :: map(), options :: map() | nil ) :: {:ok, term()} | {:error, term()}
Sends a JSON message.
@callback send_text( conn :: WebsockexNova.ClientConn.t(), text :: String.t(), options :: map() | nil ) :: {:ok, term()} | {:error, term()}
Sends a text message.
@callback status(conn :: WebsockexNova.ClientConn.t(), options :: map() | nil) :: {:ok, atom()} | {:error, term()}
Gets the current connection status.
@callback subscribe( conn :: WebsockexNova.ClientConn.t(), channel :: String.t(), options :: map() | nil ) :: {:ok, term()} | {:error, term()}
Subscribes to a channel or topic.
@callback unregister_callback(conn :: WebsockexNova.ClientConn.t(), pid :: pid()) :: {:ok, WebsockexNova.ClientConn.t()}
Unregisters a process from receiving notifications.
@callback unsubscribe( conn :: WebsockexNova.ClientConn.t(), channel :: String.t(), options :: map() | nil ) :: {:ok, term()} | {:error, term()}
Unsubscribes from a channel or topic.