Use MessagePack via Msgpax to serialize data sent over a Phoenix Socket.
Add Phoenix.Socket.V2.MsgpaxSerializer
as the serializer for the websocket in endpoint.ex
.
socket "/triple-cream-brie-socket", CheeseFactoryWeb.TripleCreamBrieSocket,
websocket: [serializer: [{Phoenix.Socket.V2.MsgpaxSerializer, "~> 2.0.0"}]],
longpoll: false
The fourth arg to GenSocketClient.start_link
is the socket_opts
, where you set serialzer: Phoenix.Channels.GenSocketClient.Serializer.Msgpax
.
GenSocketClient.start_link(
__MODULE__,
Phoenix.Channels.GenSocketClient.Transport.WebSocketClient,
Keyword.put(opts, :url, "ws://cheese.factory/triple-cream-brie-socket/websocket"),
[serializer: Phoenix.Channels.GenSocketClient.Serializer.Msgpax],
name: __MODULE__
)