Connect your frontend to an event-driven WebSockets gateway to subscribe to database modifications, track online status rosters, and broadcast custom events instantly.
// Connect manually to the WebSocket gateway (e.g. after login)
baas.realtime.connect();
// Reconnect automatically when the access token updates
baas.http.onTokenRefresh(async (newToken) => {
console.log("Token rotated, reconnecting socket...");
await baas.realtime.reconnect();
});