This module can be used to talk directly to PhoenixJS without needing to add anything to your Model. You can send and receive messages to and from your Channels from anywhere in your Elm program. That is all it does and all it is intended to do.
If you want more functionality, the top level Phoenix module takes care of a lot of the low level stuff such as automatically joining to your Channels.
A type alias representing an event sent to, or received from a Channel.
A type alias representing data that is sent to, or received from, a Channel.
A type alias representing the config for joining a Channel.
topic - The Channel topic id, for example: "topic:subtopic".
events - A list of events to receive on the Channel.
payload - Data to be sent to the Channel when joining. If no data is
required, set this to
Json.Encode.null.
timeout - Optional timeout, in ms, before retrying to join if the previous
attempt failed.
A helper function for creating a JoinConfig.
import Phoenix.Channel exposing (joinConfig)
{ joinConfig
| topic = "topic:subTopic"
, events = [ "event1", "event2" ]
}A type alias representing the port function required to send messages out
to the accompanying JS.
You will find this port function in the
Port
module.
Join a Channel.
import Json.Encode as JE
import Phoenix.Channel as Channel
import Ports.Phoenix as Ports
Channel.join
{ topic = "topic:subtopic"
, payload = JE.null
, events = []
, timeout = Nothing
}
Ports.phoenixSendA type alias representing the config for leaving a Channel.
topic - The Channel topic id, for example: "topic:subtopic".
timeout - Optional timeout, in ms, before retrying to leave if the
previous attempt failed.
Leave a Channel.
import Phoenix.Channel as Channel
import Ports.Phoenix as Ports
Channel.leave
{ topic = "topic:subtopic"
, timeout = Nothing
}
Ports.phoenixSendPush to a Channel.
The optional ref is returned with the response to the Push so that you can
use it to identify the response later on if needed.
import Json.Encode as JE
import Phoenix.Channel as Channel
import Ports.Phoenix as Port
Channel.push
{ topic = "topic:subtopic"
, event = "new_msg"
, payload =
JE.object
[("msg", JE.string "Hello World")]
, timeout = Nothing
, ref = Nothing
}
Port.pheonixSendAn InternalError should never happen, but if it does, it is because the
JS is out of sync with this package.
If you ever receive this message, please raise an issue.
Subscribe to receive incoming Channel Msgs.
import Phoenix.Channel as Channel
import Ports.Phoenix as Port
type Msg
= ChannelMsg Channel.Msg
| ...
subscriptions : Model -> Sub Msg
subscriptions _ =
Channel.subscriptions
ChannelMsg
Port.channelReceiverThese are events that are pushed or broadcast from your Elixir Channels. It
is necessary to set up the JS event listeners so that the events can be
captured and sent on to Elm. These functions turn those event listeners on and
off.
Switch an incoming event on.
Switch a list of incoming events on.
Switch an incoming event off.
Switch a list of incoming events off.
A type alias representing the Channel topic id. For example
"topic:subTopic".