PS2.ESS behaviour (PlanetSide 2 API v1.0.0)
View SourceAn 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
endYou 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
endFor 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", ... }
Types
@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
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
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.