Files
smart-city-digital-twin-mar…/smart-app-city/frontend/node_modules/expo-notifications/build/DevicePushTokenAutoRegistration.fx.js
Eric FELIXINE e30ae8ed09 feat(smart-app): implement complete mobile app MVP
- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
2026-06-01 18:00:35 -04:00

87 lines
3.9 KiB
JavaScript

import 'abort-controller/polyfill';
import { UnavailabilityError } from 'expo-modules-core';
import ServerRegistrationModule from './ServerRegistrationModule';
import { addPushTokenListener } from './TokenEmitter';
import getDevicePushTokenAsync from './getDevicePushTokenAsync';
import { updateDevicePushTokenAsync as updateDevicePushTokenAsyncWithSignal } from './utils/updateDevicePushTokenAsync';
let lastAbortController = null;
async function updatePushTokenAsync(token) {
// Abort current update process
lastAbortController?.abort();
lastAbortController = new AbortController();
return await updateDevicePushTokenAsyncWithSignal(lastAbortController.signal, token);
}
/**
* Sets the registration information so that the device push token gets pushed
* to the given registration endpoint
* @param enabled
*/
export async function setAutoServerRegistrationEnabledAsync(enabled) {
// We are overwriting registration, so we shouldn't let
// any pending request complete.
lastAbortController?.abort();
if (!ServerRegistrationModule.setRegistrationInfoAsync) {
throw new UnavailabilityError('ServerRegistrationModule', 'setRegistrationInfoAsync');
}
await ServerRegistrationModule.setRegistrationInfoAsync(enabled ? JSON.stringify({ isEnabled: enabled }) : null);
}
// note(Chmiela): This function is exported only for testing purposes.
export async function __handlePersistedRegistrationInfoAsync(registrationInfo) {
if (!registrationInfo) {
// No registration info, nothing to do
return;
}
let registration = null;
try {
registration = JSON.parse(registrationInfo);
}
catch (e) {
console.warn('[expo-notifications] Error encountered while fetching registration information for auto token updates.', e);
}
if (!registration?.isEnabled) {
// Registration is invalid or not enabled, nothing more to do
return;
}
try {
// Since the registration is enabled, fetching a "new" device token
// shouldn't be a problem.
const latestDevicePushToken = await getDevicePushTokenAsync();
await updatePushTokenAsync(latestDevicePushToken);
}
catch (e) {
console.warn('[expo-notifications] Error encountered while updating server registration with latest device push token.', e);
}
}
if (ServerRegistrationModule.getRegistrationInfoAsync) {
// A global scope (to get all the updates) device push token
// subscription, never cleared.
addPushTokenListener(async (token) => {
try {
// Before updating the push token on server we always check if we should
// Since modules can't change their method availability while running, we
// can assert it's defined.
const registrationInfo = await ServerRegistrationModule.getRegistrationInfoAsync();
if (!registrationInfo) {
// Registration is not enabled
return;
}
const registration = JSON.parse(registrationInfo);
if (registration?.isEnabled) {
// Dispatch an abortable task to update
// registration with new token.
await updatePushTokenAsync(token);
}
}
catch (e) {
console.warn('[expo-notifications] Error encountered while updating server registration with latest device push token.', e);
}
});
// Verify if persisted registration
// has successfully uploaded last known
// device push token. If not, retry.
ServerRegistrationModule.getRegistrationInfoAsync().then(__handlePersistedRegistrationInfoAsync);
}
else {
console.warn(`[expo-notifications] Error encountered while fetching auto-registration state, new tokens will not be automatically registered on server.`, new UnavailabilityError('ServerRegistrationModule', 'getRegistrationInfoAsync'));
}
//# sourceMappingURL=DevicePushTokenAutoRegistration.fx.js.map