PS2.ESS behaviour (PlanetSide 2 API v1.0.0)

View Source

An Event Streaming Service (ESS) client behaviour.

Below is an example of an ESS client implementation:

defmodule MyApp.EventHandler do
  @behaviour PS2.ESS

  @impl PS2.ESS
  def handle_event(%{"event_name" => "PlayerLogin"} = event) do
    IO.puts "PlayerLogin: #{event["character_id"]}"
  end

  # Catch-all callback
  @impl PS2.ESS
  def handle_event(event) do
    IO.puts "Unhandled event: #{event["event_name"]}"
  end
end

You can then add it to your supervision tree:

defmodule MyApp.Application do
  use Application

  @impl Application
  def start(_type, _args) do
    subscription = PS2.ESS.Subscription.new(
      events: [PS2.player_login()],
      worlds: [PS2.connery(), PS2.miller(), PS2.soltech()],
      characters: :all
    )

    ess_opts = [
      subscription: subscription,
      callback_mod: MyApp.EventHandler,
      service_id: "YOUR_SERVICE_ID_HERE",
      # optional name to register the client process under
      name: MyApp.EventHandler
    ]

    children = [
      # ...
      {PS2.ESS, ess_opts},
      # ...
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

For more information about events and their payloads, see the Census documentation

Summary

Types

A map of fields that make up the ESS event, e.g. %{"event_name" => "Death", "attacker_character_id" => "5428812948092239617", ... }

Functions

Returns a specification to start this module under a supervisor.

Adds a new subscription, or resubscribes if no subscription is provided. Raises a KeyError if subscription is not formatted correctly.

Types

event()

@type event() :: PS2.ESS.Conn.event()

A map of fields that make up the ESS event, e.g. %{"event_name" => "Death", "attacker_character_id" => "5428812948092239617", ... }

Callbacks

handle_event(event)

@callback handle_event(event()) :: any()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

subscribe(ess_server)

Adds a new subscription, or resubscribes if no subscription is provided. Raises a KeyError if subscription is not formatted correctly.

subscription should be a keyword list similar to the one passed in the options to PS2.Socket.

subscribe(ess_server, sub)