Pixie.Extension behaviour
Used to implement Bayeux extensions, which can be used to filter or change incoming messages and the responses sent back to the client.
For example:
defmodule AuthenticationExtension do
use Pixie.Extension
def incoming %Event{message: %{ext: %{username: u, password: p}=message}}=event do
case User.authenticate username, password do
:ok ->
%{event | message: %{message | ext: nil}}
:error ->
%{event | response: %{response | error: "Authentication Failed"}}
end
end
def incoming %Event{}=event do
%{event | response: %{response | error: "Authentication Failed"}}
end
Note that you must always provide a "catch all" function head that matches all other events and returns them - otherwise the runtime will start raising exceptions and generally make you feel sad.
You can dynamically add your extension to the extension stack at runtime using YourExtension.register
and YourExtension.unregister