davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
511 stars 147 forks source link

Configure client to be compatible with v2_json_serializer.ex #163

Closed richard-ash closed 4 years ago

richard-ash commented 4 years ago

Is there a way to configure Socket to be compatible with the Phoenix v2 json serializer?

Seems like the diff between v1 & v2 is that v2 uses arrays to encode the message instead of a dictionary, but seems like Socket will always send a dictionary

dsrees commented 4 years ago

You can override the encode and decode closures of the Socket to provide custom behavior

https://github.com/davidstump/SwiftPhoenixClient/blob/master/Sources/Socket.swift#L86

let socket = Socket(...)
socket.encode = { jsonDictionary in
  // convert json dictionary to array data
}

socket.decode = { jsonData in
  // convert array data to json dictionary
}
richard-ash commented 4 years ago

Awesome thanks! 😄