Skip to content

API and Contracts

DRomothewriter edited this page Nov 26, 2026 · 1 revision

API and Contracts

Rutas de Angular, guardias, servicios core y contratos REST/Socket.IO que Orbit-Frontend consume de Orbit-Backend.


1. Rutas y Guards (src/app/app.routes.ts)

flowchart LR
    ROOT["/"] -->|redirect| LOGIN["/login"]
    LOGIN --> REG["/register"]
    REG --> VER["/verify-email"]
    LOGIN --> FORGOT["/forgot-password"]
    FORGOT --> RESET["/reset-password"]
    LOGIN -->|"JWT en sessionStorage"| GUARD{"authGuard (token.hasToken)"}
    GUARD -->|false| LOGIN
    GUARD -->|true| HOME["/home (HomeComponent)"]
    HOME --> FRIENDS["/home/friends (list, add-friend, pending)"]
    HOME --> DM["/home/:id (ChatComponent)"]
    HOME --> CCHAT["/home/community/:communityId/group/:id (ChatComponent)"]
Loading
Ruta Componente Carga Guard
'' Redirect → login — —
login, register LoginComponent, RegisterComponent Eager Pública
verify-email, forgot-password, reset-password Componentes de auth Lazy Pública
home HomeComponent Lazy authGuard
home/friends ('', add-friend, pending) FriendsPanelComponent + hijos Lazy Hereda authGuard
home/:id ChatComponent Lazy Hereda authGuard
home/community/:communityId/group/:id ChatComponent Lazy Hereda authGuard

2. Servicios Core y Estado Reactivo

Note

El manejo de estado en servicios utiliza BehaviorSubject de RxJS (no Angular Signals). La autenticación se inyecta por servicio mediante Authorization: Bearer <token> desde TokenService (sessionStorage).

Servicio Estado Expuesto (BehaviorSubject) Responsabilidad Principal
TokenService sessionStorage['token'] Guardar, leer, validar y limpiar JWT
AuthService — Registro, login, verificación y reset de contraseña
UserService currentUser$ Perfil actual, userStatus, búsqueda y amistades
CommunityService communitySummary, myCommunities$ Comunidades del usuario y membresías
GroupService groupSummary, myGroups$ Grupos directos, de comunidad, roles y administración
MessageService — Historial de mensajes, envío de texto e imágenes
NotificationsService currentNotifications$ Notificaciones no vistas, historial y marcado como visto
SocketService socketReady + listeners Observable Conexión Socket.IO y teardown seguro (socket.off)
CallService localStream, peers, isInCall Ciclo de vida mediasoup-client y toggles A/V
ModalsService 7 observables open*$ Apertura/cierre de modales globales
EventsService CalendarEvent[] (memoria local) Eventos locales para calendario (oculto en v1)

3. Contratos REST Consumidos (environment.apiUrl)

Servicio Endpoints Consumidos
AuthService + Login/Register POST auth/signup, POST auth/login, POST auth/google, POST auth/verify-email, POST auth/resend-verification, POST auth/forgot-password, POST auth/reset-password
UserService GET users/my-user, GET users/, GET users/friends, GET users/received-requests, GET users/search?username=..., PUT users/edit-profile-image, PUT users/change-user-status/:status, PUT users/edit-username, POST users/friend-request, PUT users/accept-friend, DELETE users/delete-friendship
CommunityService POST communities/, POST communities/add-communityMembers, GET communities/my-communities, GET communities/community-members/:communityId
GroupService GET groups/:groupId, GET groups/my-groups, GET groups/all-my-groups, GET groups/my-community-groups/:communityId, GET groups/my-group-member/:groupId, GET groups/group-members/:groupId, POST groups/, POST groups/add-groupmembers, PUT groups/edit-group-image/:groupId, PUT groups/edit-topic/:groupId, PUT groups/:groupId/make-admin/:groupMemberId, DELETE groups/:groupId/remove-member/:groupMemberId, DELETE groups/:groupId, DELETE groups/:groupIdleave-group
MessageService POST messages/, POST messages/image, GET messages/groupMessages/:groupId
NotificationsService GET notifications/my-unseen, GET notifications/all, PUT notifications/seen

Warning

En GroupService.leaveGroup(), la ruta construida en código es ${environment.apiUrl}groups/${groupId}leave-group (sin / antes de leave-group), mientras el backend define DELETE /groups/:groupId/leave-group. Tenlo presente al tocar esa funcionalidad.


4. Contrato Socket.IO y WebRTC

Conexión (SocketService.connectWithGroups())

  • Obtiene getMyUser() y getAllMyGroups(), luego conecta:
    io(environment.apiUrl, {
      auth: { token },
      query: { groupIds: JSON.stringify(groupIds), user: JSON.stringify(user) }
    })

Eventos Emitidos y Escuchados

Dirección Eventos Consumidor / Emisor
Client → Server status-change SocketService.emitStatusChange()
Client → Server (WebRTC) joinCallRoom, leaveCallRoom, createWebRtcTransport, connectTransport, produce, consume, resumeConsumer VideoCallComponent / CallService
Server → Client friend-status-change, message, notification, call-starting SocketService (con teardown socket.off)
Server → Client (WebRTC) callRoomJoined, newPeerInCall, newProducer, peerLeftCall, callError VideoCallComponent