Bingex.Socket behaviour (Bingex v0.1.9)

Provides an abstraction over WebSocket connections for BingX.

Summary

Functions

Sends a synchronous message.

Sends an asynchronous message.

Sends a message to the process to the specified PID.

Starts a WebSocket process.

Starts a WebSocket process linked to the current process.

Returns the pid of a Socket process, nil otherwise.

Types

event()

@type event() :: term()

message()

@type message() :: binary()

state()

@type state() :: term()

Callbacks

handle_call(message, from, state)

(optional)
@callback handle_call(message(), from :: pid(), state()) ::
  {:reply, message :: term(), state()} | {:ok, state()} | {:disconnect, state()}

handle_cast(message, state)

(optional)
@callback handle_cast(message(), state()) ::
  {:send, message(), state()} | {:ok, state()} | {:disconnect, state()}

handle_connect(state)

(optional)
@callback handle_connect(state()) :: {:ok, state()}

handle_disconnect(details, state)

(optional)
@callback handle_disconnect(
  details :: WebSockex.connection_status_map(),
  state()
) :: {:stop, state()} | {:reconnect, state()}

handle_event(event, state)

@callback handle_event(event(), state()) :: {:ok, state()} | {:disconnect, state()}

handle_info(message, state)

(optional)
@callback handle_info(
  message(),
  state()
) :: {:send, message(), state()} | {:ok, state()} | {:disconnect, state()}

Functions

call(dest, message, timeout \\ 5000)

Sends a synchronous message.

cast(dest, message)

Sends an asynchronous message.

send(dest, message)

Sends a message to the process to the specified PID.

start(url, module, state, options \\ [])

Starts a WebSocket process.

start_link(url, module, state, options \\ [])

Starts a WebSocket process linked to the current process.

whereis(dest)

@spec whereis(dest :: atom() | pid()) :: pid() | nil

Returns the pid of a Socket process, nil otherwise.