The service layer isolates all network communication behind class boundaries.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car_front/llms.txt
Use this file to discover all available pages before exploring further.
SocketService establishes the Socket.IO connection and defines the lifecycle hooks that subclasses override. TreeService extends it with the full event contract for the AVLTree namespace — the only socket channel used in production. ObstacleService is a REST-only stub for a planned coordinate validation endpoint.
All socket URLs are assembled from the configs.json file located at src/app/assets/json/configs.json:
SocketService
File:src/app/services/Socket.service.js
SocketService is the base class for every socket-enabled service. It constructs the full socket URL from configs.urlSOCKET, calls io() to establish the Socket.IO connection, and registers a connect_error handler. Subclasses receive the live this.socketio reference and override the stub lifecycle methods to attach their own event handlers.
Constructor
The Socket.IO namespace to connect to. When
'/' (default), connects to ${configs.urlSOCKET}/. For any other value the URL becomes ${configs.urlSOCKET}/${channel}. Defaults to '/'.this.on_connect_error().
Properties
| Property | Type | Description |
|---|---|---|
socketURL | string | The fully assembled socket endpoint URL. |
socketio | Socket | The Socket.IO client instance returned by io(). |
Methods
on_connect() (stub)
Empty method. Intended to be overridden by subclasses to register a handler for the connected event.
on_disconnect() (stub)
Empty method. Intended to be overridden by subclasses to register a handler for the disconnected event.
on_connect_error()
Registers a connect_error handler on this.socketio. When the socket is inactive (permanent failure) the error message is logged to the console. When the socket is active (temporary failure) the error is silently ignored — Socket.IO will automatically reconnect.
TreeService
File:src/app/services/Tree.service.jsExtends:
SocketService
TreeService connects to the AVLTree Socket.IO namespace and registers every event handler the application needs. Incoming socket events are translated into DOM CustomEvent dispatches so that controllers can listen with document.addEventListener() without holding a direct reference to the service. Outgoing operations are exposed as explicit emit_* methods.
Constructor
super('AVLTree'), which connects to http://localhost:4500/AVLTree. Then immediately calls each event-registration method in sequence:
Event Listener Methods
on_connect()
Registers the connected socket event. Logs 'Socket is Connected! (AVLTree)' to the console when the backend confirms the connection.
on_disconnect()
Registers the disconnected socket event. Logs 'Socket is Disconnected! (AVLTree)' to the console when the backend signals a disconnect.
on_obstacle_inserted()
Registers the obstacles_inserted socket event. The handler body is currently a no-op (commented out debug log) — the event is received but no DOM event is dispatched. Future implementations can use this hook to confirm individual obstacle insertions.
on_road_preorder()
Registers the preorder socket event. Dispatches a pre-order CustomEvent on document with detail set to ev.data (the ordered array of node IDs from the backend traversal).
on_road_inorder()
Registers the inorder socket event. Dispatches an in-order CustomEvent on document with detail set to ev.data.
on_road_posorder()
Registers the posorder socket event. Dispatches a pos-order CustomEvent on document with detail set to ev.data.
on_avl_tree_balanced()
Registers the avl_tree_balanced socket event — the most important event in the application. When the backend sends the rebalanced tree, this handler extracts ev.data (defaulting to {} if absent) and dispatches an avl_tree_balanced CustomEvent on document.
AVLController.listenGetTreeFromBackend() listens for this DOM event and calls initDataTree() to update the AVL model and re-render the D3.js tree.
on_avl_reseted()
Registers the avl_reseted socket event. Dispatches an avl_reseted CustomEvent on document with detail set to ev.data ?? {} to signal that the backend tree has been cleared.
Emit Methods
emit_insert_obstacle(data)
Emits the insert_obstacle socket event to request that the backend insert a new obstacle into the AVL tree.
The obstacle object to insert. Should contain at minimum
x, y, and type fields.emit_get_road(road_name, data?)
Emits a traversal request. The event name is dynamically constructed as `road_${road_name}`.
The traversal type to request. Valid values are
'preorder', 'inorder', and 'posorder'. The emitted socket event will be road_preorder, road_inorder, or road_posorder respectively.Optional payload sent alongside the event. Defaults to
{}.emit_get_tree(data?)
Emits get_tree_avl to request the full current tree from the backend.
Optional payload. Defaults to
{}.avl_tree_balanced, which on_avl_tree_balanced() converts into the avl_tree_balanced DOM event.
emit_reset_avl(data?)
Emits reset_avl to instruct the backend to clear its AVL tree.
Optional payload. Defaults to
{}.emit_reset_avl() is called in three distinct places: HomeController.init() on first load, RoadController when the user confirms a new road, and LoadJSONController before sending a bulk JSON import. This ensures no stale tree state persists across sessions.emit_remove_obstacle(data?)
Emits remove_obstacle to instruct the backend to delete an obstacle from the AVL tree.
Optional payload identifying the obstacle to remove. Defaults to
{}.ObstacleService
File:src/app/services/Obstacles.service.js
ObstacleService is a REST-only stub class. It was intended to validate obstacle coordinates against the backend before insertion, but the validation call is not used in the current production flow — ObstaclesController bypasses it with a hardcoded { ok: true } response.
validateCoordinates(cooridates)
Makes a POST /obstacles/validateCoordinates request with the supplied coordinates as the body.
The coordinate object to validate. Expected to contain
x and y fields.