WebsockexNova.Gun.Helpers.BehaviorHelpers (WebsockexNova v0.1.0)

View Source

Helper functions for calling behavior callbacks consistently.

This module provides a standardized way to call behavior callbacks, handle their responses, and update state accordingly. It ensures proper error handling and consistent behavior throughout the application.

Summary

Functions

Calls the connection handler's handle_connect callback.

Calls the connection handler's handle_disconnect callback.

Calls the connection handler's handle_frame callback.

Calls the connection handler's handle_timeout callback.

Functions

call_handle_connect(state, extra_info \\ %{})

Calls the connection handler's handle_connect callback.

Assembles a connection info map from the state, calls the handler, and processes the response.

Parameters

  • state - The current connection state
  • extra_info - Optional extra information to include in the conn_info map

Returns

{:ok, updated_state} or error tuple

call_handle_disconnect(state, reason)

Calls the connection handler's handle_disconnect callback.

Parameters

  • state - The current connection state
  • reason - The disconnect reason

Returns

{:ok, updated_state}, {:reconnect, updated_state}, or {:stop, reason, updated_state}

call_handle_frame(state, frame_type, frame_data, stream_ref)

Calls the connection handler's handle_frame callback.

Parameters

  • state - The current connection state
  • frame_type - Type of the frame (:text, :binary, etc.)
  • frame_data - Data contained in the frame
  • stream_ref - Reference to the stream that received the frame

Returns

{:ok, updated_state} or other handler return value with updated state

call_handle_timeout(state)

Calls the connection handler's handle_timeout callback.

Parameters

  • state - The current connection state

Returns

{:ok, updated_state}, {:reconnect, updated_state}, or {:stop, reason, updated_state}