I'm trying to connect a simple iOS app to a sails.js API. The iOS app is written in swift. The version of sails is the 0.11
For the web-socket management I use https://github.com/socketio/socket.io-client-swift
class Communicate: UIViewController {
let socket = SocketIOClient(socketURL: "localhost:2000")
override func viewDidLoad() {
super.viewDidLoad()
self.addHandlers()
self.socket.connect()
}
func addHandlers() {
socket.on("connect") {data, ack in
print("socket connected !") // This is working
self.socket.emit("get", ["url": "/device"]) // I get the sails error
}
}
}
On the sails.js console, I get the following error:
verbose: Receiving incoming message from Socket.io: { url: '/device?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=iOS&__sails_io_sdk_language=fr' }
error: Error (SAILS:HOOK:SOCKETS:PARSE_VIRTUAL_REQ):: Failed to parse incoming socket.io request.
details: 'Sails v0.11.x is not compatible with the socket.io/sails.io.js client SDK version you are using (0.9.0). Please see the v0.11 migration guide on http://sailsjs.org for more information.' }
I probably do something wrong to imitate the behaviour of sails.io, but I don't know how to achieve it.
Thank by advance for your help.
Instead of changing the server, you can connect parameters to tell the server that you comply with v0.11.0 semantics with:
self.socket = SocketIOClient(socketURL: baseWebSocketServerURL, options:
[SocketIOClientOption.ConnectParams(["__sails_io_sdk_version":"0.11.0"])])
I think that this is a better solution than hacking the server and breaking semantic version checking for other clients.