Pushest v0.2.2 Pushest.Socket.Utils View Source

Various Socket-scoped utilities.

Link to this section Summary

Functions

Returns auth token needed to authorize our client against Pusher server when subscribing to private or presence channel. Token is generated only for those two channel types as it’s not needed for public channels subscriptions

Generates Url struct with domain, path and port parts needed to build Pusher Server URL for given Pusher app key and configuration. String values are converted to charlist since that is the accepted format for underlying :gun lib

Checks whether user_data map contains mandatory element user_id and its content is valid. Used when subscribing to presence channel as user_id is necessary there

Link to this section Functions

Link to this function auth(state, channel, user_data) View Source
auth(
  %Pushest.Socket.Data.State{
    callback_module: term(),
    channels: term(),
    conn_pid: term(),
    init_channels: term(),
    options: term(),
    presence: term(),
    socket_info: term(),
    url: term()
  },
  String.t(),
  map()
) :: nil | String.t()

Returns auth token needed to authorize our client against Pusher server when subscribing to private or presence channel. Token is generated only for those two channel types as it’s not needed for public channels subscriptions.

Link to this function url(map) View Source
url(map()) :: %Pushest.Socket.Data.Url{
  domain: term(),
  path: term(),
  port: term()
}

Generates Url struct with domain, path and port parts needed to build Pusher Server URL for given Pusher app key and configuration. String values are converted to charlist since that is the accepted format for underlying :gun lib.

Link to this function validate_user_data(user_data) View Source
validate_user_data(map()) :: {:ok, map()} | {:error, map()}

Checks whether user_data map contains mandatory element user_id and its content is valid. Used when subscribing to presence channel as user_id is necessary there.

Examples

iex> Pushest.Socket.Utils.validate_user_data(%{user_id: 1})
{:ok, %{user_id: 1}}

iex> Pushest.Socket.Utils.validate_user_data(%{user_id: "1"})
{:ok, %{user_id: "1"}}

iex> Pushest.Socket.Utils.validate_user_data(%{user_id: ""})
{:error, %{user_id: ""}}

iex> Pushest.Socket.Utils.validate_user_data(%{user_id: nil})
{:error, %{user_id: nil}}

iex> Pushest.Socket.Utils.validate_user_data(%{})
{:error, %{}}