chazsconi / elm-phoenix-ports / 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 : (( Phoenix.Channel.Topic
, String
, Json.Encode.Value ) -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, pushReply : (PushReply -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, channelsCreated : (List ( Phoenix.Channel.Topic
, Phoenix.Internal.ChannelStates.ChannelObj ) -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, channelError : (Phoenix.Channel.Topic -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, socketOpened : (() -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, socketClosed : (SocketCloseParams -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, presenceUpdated : (PresenceUpdate -> Phoenix.Internal.Types.Msg msg) -> Platform.Sub.Sub (Phoenix.Internal.Types.Msg msg)
, connectSocket : ConnectParams -> Platform.Cmd.Cmd (Phoenix.Internal.Types.Msg msg)
, joinChannels : List JoinParams -> Platform.Cmd.Cmd (Phoenix.Internal.Types.Msg msg)
, leaveChannel : Phoenix.Internal.ChannelStates.ChannelObj -> Platform.Cmd.Cmd (Phoenix.Internal.Types.Msg msg)
, pushChannel : PushParams -> Platform.Cmd.Cmd (Phoenix.Internal.Types.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 =
( Phoenix.Channel.Topic
, Phoenix.Internal.Types.Event
, Json.Encode.Value 
)

Message from a channel


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

Handlers to invoke on a push


type alias JoinParams =
{ topic : Phoenix.Channel.Topic
, payload : Json.Encode.Value
, onHandlers : OnHandlers
, presence : Basics.Bool 
}

Channel join params


type alias PushParams =
{ ref : Basics.Int
, channel : Phoenix.Internal.ChannelStates.ChannelObj
, event : Phoenix.Internal.Types.Event
, payload : Json.Encode.Value
, onHandlers : OnHandlers 
}

Push params


type alias PushReply =
{ eventName : String
, topic : Phoenix.Channel.Topic
, pushType : String
, ref : Maybe Basics.Int
, payload : Json.Encode.Value 
}

Push reply params


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

Socket connect params


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

Socket closed params


type alias PresenceUpdate =
{ eventName : String
, topic : Phoenix.Channel.Topic
, presences : List ( String
, List Json.Encode.Value ) 
}

Presence update reply params