Reputation: 992
Im looking for a way to implement custom channels in the phoenix framework I don't want to use the topics but do routing based on payload.
For example i have a json message like this
{
"command":"hello",
"payload": {
"message_id":"001",
"body":"is it me your looking for"
}
}
}
and want to do routing based on the value of "command", and i have no clue where to start. i can not send topics because i want to use a existing api.
Upvotes: 2
Views: 378
Reputation: 8120
You can do this by implementing your own Transport serializer (https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/transports/serializer.ex) and translating your client message format to the %Phoenix.Socket.Message{}
format with topic, event, payload. See the built-in websocket serializer as a starting point for adaptation:
https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/transports/websocket_serializer.ex
Upvotes: 4