-
Notifications
You must be signed in to change notification settings - Fork 1
2.How it works
GAPS heavily relies on async bidirectional communication between the client and the server. This is done via websockets, with each request carrying an id, and the server referring to that id when sending a response or a notification. Some responses (i.e. connection established, or closed) may not necessarily belong to any specific requests, and in this case their callback_id will be 0.
The client contains an AngularJS controller (gapscontroller), which in its turn communicates with an Angular factory (WebsocketService). When a request is sent, the controller maps the parameters and composes the request, which it then forwards to the factory, to be sent to the server.
The factory, in its turn, logs the request, gives it a callback_id, and sends it forward for processing, returning a promise. When the server responds, the factory receives the response, associates it with the callback_id previously saved (if any), and forwards it to the controller, which updates the model / renders the view.
On the server side, the websocket controller is the one receiving the messages. Upon receiving a message, the controller passes on the message to MessageDispatcherFactory, which decides what to do about the message. Note that the controller has no idea, and nor should it, about the message contents, what kind of message is, or what it should do with it. This is the factory's job.
The MessageDispatcherFactory in its turn, decides what to do with the message, and calls an appropriate MessageDispatcher, sets the additional parameters (if needed), and then calls its process() method. While the MessageDispatcher keeps processing, it occasionally returns updates, which are forwarded to the controller, and in turn to the client. When the dispatcher is done, it sends a final message, and the request is considered as processed.
Putting the two-and-two together, the whole flow would look like this: