Current section

Files

Jump to
pixie lib pixie messages handshake.ex
Raw

lib/pixie/messages/handshake.ex

defmodule Pixie.Message.Handshake do
defstruct channel: nil, version: nil, supported_connection_types: nil, minimum_version: nil, ext: nil, id: nil
@moduledoc """
Convert an incomikng handshake message into a struct.
Request
MUST include: * channel
* version
* supportedConnectionTypes
MAY include: * minimumVersion
* ext
* id
This struct contains the following keys:
- `:channel` always `"/meta/disconnect"`.
- `:version` the Bayeux version the client requires.
- `:supported_connection_types` the connection types (transports) that the
client is capable of negotiating.
- `:minimum_version` the minimum Bayeux version the client requires. Optional.
- `:ext` an arbitrary map of data the client sent for use in extensions
(usually authentication information, etc). Optional.
- `:id` a message ID generated by the client. Optional.
"""
def init %{}=message do
%Pixie.Message.Handshake{}
|> get(message, :channel)
|> get(message, :version)
|> get(message, :supported_connection_types)
|> get(message, :minimum_version)
|> get(message, :ext)
|> get(message, :id)
end
def get handshake, message, :supported_connection_types=field do
case Map.get message, field do
ct when is_list(ct) ->
Map.put handshake, field, Enum.into(ct, HashSet.new)
_ ->
handshake
end
end
def get(h,m,f), do: Pixie.Utils.Message.get(h,m,f)
end