phoenix_socket library

Dart library to interact with Phoenix Channels and Presence over WebSockets.

This library uses web_socket_channel for WebSockets, making the API consistent across web and native environments.

Like other implementation of clients for Phoenix Sockets, this library provides a PhoenixSocket class that can be used to manage connections with remote Phoenix servers. PhoenixChannels can be joined through that PhoenixSocket class, through which Messages can be sent and received. To send a message on a channel, possibly expecting a reply, the Push class can be used.

Classes

Message
Class that encapsulate a message being sent or received on a PhoenixSocket.
MessageSerializer
Default class to serialize Message instances to JSON.
PhoenixChannel
Bi-directional and isolated communication channel shared between differents clients through a common Phoenix server.
PhoenixChannelEvent
Encapsulates constants used in the protocol over PhoenixChannel.
PhoenixPresence
A Phoenix Presence client to interact with a backend Phoenix Channel implementing the Presence module. https://hexdocs.pm/phoenix/presence.html
PhoenixPresenceMeta
Class that encapsulate the various metadata for a Presence event. This class only implements the default metadata field phxRef, all other custom fields are available in the json map data (including the 'phxRef' field). It can be extended with custom field as required, see 'example/flutter_presence_app' for an example on how to implement this in your code.
PhoenixRawSocket
Main class to use when wishing to establish a persistent connection with a Phoenix backend using WebSockets.
PhoenixSocket
Main class to use when wishing to establish a persistent connection with a Phoenix backend using WebSockets.
PhoenixSocketCloseEvent
Close event for a PhoenixSocket.
PhoenixSocketErrorEvent
Error event for a PhoenixSocket.
PhoenixSocketEvent
Base socket event
PhoenixSocketOpenEvent
Open event for a PhoenixSocket.
PhoenixSocketOptions
Options for the open Phoenix socket.
Presence
Class that encapsulate all presence events for a specific key as a list of metadatas events metas.
Push
Object produced by PhoenixChannel.push to encapsulate the message sent and its lifecycle.
PushResponse
Encapsulates the response to a Push.

Enums

PhoenixChannelState
The different states a channel can be.
SocketState
State of a PhoenixSocket.

Constants

statesIgnoringErrors → const Set<PhoenixChannelState>
A set of States where an error triggered by the parent socket do not end up triggering an error on the channel.

Typedefs

JoinHandler = void Function(String key, dynamic current, dynamic joined)
LeaveHandler = void Function(String key, dynamic current, dynamic left)
PayloadGetter = Map<String, dynamic> Function()
Type of function that should return a push payload

Exceptions / Errors

ChannelClosedError
ChannelTimeoutException
Exception thrown when a Push's reply was awaited for, and the allowed delay has passed.
PhoenixException
Exception yield when a PhoenixSocket closes for unexpected reasons.