Back to the idea of making the session/websocket/foundset piece a discrete API so can plug Servoy’s realtime web in any type of web app.
Servoy’s code for this piece is here: https://github.com/Servoy/sablo. No license listed.
It turns out that the core functionality is implemented agnostic to any client-side framework and NG Client just consumes the functionality with some not-so-elegant client-side code. It gets the job done but some API-esque wiring would help clean up this code.
A weekend of poking and prodding later…
Basic mechanics
Server-side Servoy forms function to set up a model/foundset. Form has a datasource, the fields you put on the form are the allowable data fields the client can see.
Form items provide additional meta information to the client such as data formatters, calculations, i18n keys, tagging, UI parameters, etc.
Forms also provide services such as when a button is pushed, code on the server is run and a response is sent to the client. Foundset functions are automatically mirrored on the client. So something as simple as foundset.setSelectedIndex(foundset.getSelectedIndex() + 1); automatically returns the data for the next record for the fields you have on the form without you having to return the record yourself.
When an NG Client connects, a session is created and (all?) forms in your app have a state per session. Data broadcasting happens between sessions where the foundsets share the same visible foundset index(es). I assume all CRUD operations but edit is the only one I’ve tested so far.
All of this communication goes back and forth from clients and server via websockets as JSON. If a field is edited, only the data for that field is sent over the wire, not the whole record. Quite compact for most operations from what I’ve seen (initial connection response sends a lot of unnecessary Angular stuff is one exception).
[attachment=1]websockets.png[/attachment]
Solution
Figured out the basic wiring to establish websocket connections, send messages to the server, and receive server responses. Servoy’s JSON objects are consistent and easy to grok so mapping to client-side models of any particular framework will be easy.
Triggering form methods is straight forward. My guess is that only public methods are exposed on the client but on my list to test.
If a solution requires login, websocket endpoints are not created until you login.
A neat trick is that you can return any JS object from a form method (serialization to JSON happens automatically) and the client websocket.onmessage handler picks it right up. So not only can you trigger foundset methods but you return your own data structures over the pipe. (Note to self, test sending arguments to form methods.)
So there you have it — it is all possible to hook into Servoy’s realtime web special sauce without having to go through NG Client.
And yes, we are available for hire!
Cheers - David
[attachment=0]servoy_socket_test.png[/attachment]

