Implement RPC over WebSocket
Abstract away the web socket so we can access the backend in request/response fashion (basically, implement RPC over WebSockets)
Node.sharedInstance().call('nameOfMethod') { response in
// Response handler
}
If we implement a unique ID for each call (unique per run of the app will suffice), we can also:
- cancel calls
- disambiguate returns from multiple calls to the same method
Socket protocol:
uniqueID:methodName:any:number:of:arguments
Or, since we‘re not animals here, we could JSON.stringify it:
{
id:…,
method:…,
arguments: []
}