chazsconi/elm-phoenix-ports/1.1.2

NOTE: the latest version is 2.1.0

Phoenix.PortsAPI

Defines the API for the ports that are required to interface with JS.

This is just an internal implementation, but exposed so the types are available via the implementation of the ports in PhoenixPorts (which must be installed via NPM). See README.md for details.

External Ports API

This is the API that the ports module must implement.

type alias Ports msg =
{ channelMessage :
(( Topic, String, Value ) -> Msg msg) -> Sub (Msg msg)
, pushReply : (PushReply -> Msg msg) -> Sub (Msg msg)
, channelsCreated :
(List ( Topic, ChannelObj ) -> Msg msg) -> Sub (Msg msg)
, channelError : (Topic -> Msg msg) -> Sub (Msg msg)
, socketOpened : (() -> Msg msg) -> Sub (Msg msg)
, socketClosed : (SocketCloseParams -> Msg msg) -> Sub (Msg msg)
, presenceUpdated : (PresenceUpdate -> Msg msg) -> Sub (Msg msg)
, connectSocket : ConnectParams -> Cmd (Msg msg)
, joinChannels : List JoinParams -> Cmd (Msg msg)
, leaveChannel : ChannelObj -> Cmd (Msg msg)
, pushChannel : PushParams -> Cmd (Msg msg)
}

Functions that need to implemented by Ports

Internal types

These types are used internally to communicate between Elm and the JS ports code.

type alias ChannelMsg =
( Topic, Event, Value )

Message from a channel

type alias OnHandlers =
{ onOk : Bool
, onError : Bool
, onTimeout : Bool
}

Handlers to invoke on a push

type alias JoinParams =
{ topic : Topic
, payload : Value
, onHandlers : OnHandlers
, presence : Bool
}

Channel join params

type alias PushParams =
{ ref : Int
, channel : ChannelObj
, event : Event
, payload : Value
, onHandlers : OnHandlers
}

Push params

type alias PushReply =
{ eventName : String
, topic : Topic
, pushType : String
, ref : Maybe Int
, payload : Value
}

Push reply params

type alias ConnectParams =
{ endpoint : String
, params : Value
}

Socket connect params

type alias SocketCloseParams =
{ code : Int
, reason : String
, wasClean : Bool
}

Socket closed params

type alias PresenceUpdate =
{ eventName : String
, topic : Topic
, presences : List ( String, List Value )
}

Presence update reply params