# NPC Audio Intercom — Firebase setup

This pilot supports telephone-style, one-to-one audio calls across Silang, Pampanga, Cebu, Davao and Pagadian. It uses Firebase Authentication, Realtime Database for signaling/presence, and WebRTC for audio. No camera or audio recording is used. It is not yet connected to an NPC Firebase project.

## 1. Create a separate project

Create a new project in https://console.firebase.google.com/ using the Spark plan. Keep this separate from the Faculty Evaluation System. Register a Web app. Copy its configuration; include the databaseURL from the next step. Do not share account passwords or service-account keys.

## 2. Configure the database and rules

Create a Realtime Database in locked mode, preferably in the Singapore location if available. Copy its database URL into your web configuration. Deploy database.rules.json from the source package using the Firebase CLI, or paste its rules into the Realtime Database Rules tab and publish. Do not use public/test-mode rules.

## 3. Create office accounts

In Authentication, enable Email/Password. Create one account per office station. Use a unique office email and a strong password. Copy each account UID.

In Realtime Database, use the administrator console to create entries under profiles, using the real UIDs as keys:

```json
{
  "REAL_IT_ACCOUNT_UID": {"office": "IT Office", "campus": "Silang"},
  "REAL_RAAD_ACCOUNT_UID": {"office": "RAAD", "campus": "Silang"},
  "REAL_PAMPANGA_ACCOUNT_UID": {"office": "Campus Administration", "campus": "Pampanga"},
  "REAL_CEBU_ACCOUNT_UID": {"office": "Campus Administration", "campus": "Cebu"},
  "REAL_DAVAO_ACCOUNT_UID": {"office": "Campus Administration", "campus": "Davao"},
  "REAL_PAGADIAN_ACCOUNT_UID": {"office": "Campus Administration", "campus": "Pagadian"}
}
```

Add Library, Registrar, NAAO, MCDRM and other offices as needed. Only the administrator console can edit profiles. Existing authenticated, provisioned stations can read the office directory and presence; only participants can read their calls.

## 4. Connect and test

Open Connection settings in the intercom. Paste strict JSON (quoted property names, no `const firebaseConfig =` wrapper) containing apiKey, authDomain, databaseURL, projectId and appId. Configuration is stored in this browser. Repeat on each device, or embed the public Firebase configuration in app.js before your final Firebase deployment. Firebase web configuration is not an administrator credential.

Sign in to two different office accounts on two devices. Click Test microphone, allow microphone access, then call the other office. Test Answer, Decline, Mute, End call, a missed call, and an office going offline. Use a headset to reduce feedback. Use one active browser tab/device per office account; simultaneous sessions for the same account are not supported in this pilot.

The private Sites preview is for the owner to inspect. For office deployment, deploy the source package to Firebase Hosting over HTTPS so staff can open the Firebase URL without a ChatGPT account. In Authentication settings, add your hosting hostname to Authorized domains if required.

## 5. Deploy to Firebase Hosting

Install Node.js and the Firebase CLI on your computer. Extract the source package and run from that directory:

```sh
npm install -g firebase-tools
firebase login
firebase use --add
firebase deploy --only hosting,database
```

Select the NEW intercom Firebase project, not the faculty evaluation project. The free Firebase hosting address requires no custom domain purchase.

## Free pilot limits

No TURN relay is configured. Calls across restrictive networks may ring but have no audio, or time out. Test all campus pairs. Adding campuses does not itself incur a fee; Firebase usage and network connectivity determine feasibility. Monitor Spark quotas in the console; the system cannot guarantee unlimited usage or connectivity on every network. Signaling records and ICE candidates remain in Realtime Database after calls; periodically delete old terminal calls through the administrator console to manage storage. Local history is limited to 30 records on each device. There is no central audit log, transfer, group call, offline calling or background-mobile ringing guarantee.

Keep the page open and the device awake. Browser audio restrictions can prevent an audible ringtone until a user interacts with the page. Online presence uses a 30-second heartbeat and can take up to 90 seconds to mark a stale device offline. Busy detection is a pilot safeguard, not a transactionally reserved switchboard; simultaneous calls may be declined as busy. Do not use this pilot as an emergency communications system.

## Verification before rollout

Actual audio and Firebase rules must be tested against your project. Verify an unprovisioned account cannot read the directory; station A cannot read a call between B and C; a station cannot overwrite another station's presence; and calls reach all participating campus networks. The source package has static syntax checks, but live two-device audio verification requires your Firebase configuration and office accounts.


## Install on a desktop

After deploying to Firebase Hosting, open the Firebase URL in Chrome or Edge. Click Install desktop app when available, or choose the browser menu’s install/app option. If the app is already installed, the installation button is hidden in its standalone window. Windows may offer a desktop shortcut during installation; otherwise find NPC Intercom in the Start menu or the browser’s app manager and create a shortcut. It opens in its own window. There is no EXE installer and no separate app subscription.

Browser installation availability depends on the browser and hosting environment. Use Create shortcut and Open as window if full installation is unavailable. Installation through an embedded ChatGPT preview may be unavailable; open the final Firebase URL in a normal browser. Keep the window open and computer awake to receive calls. Closing the window stops call reception; installation does not provide background telephone service. Internet is still needed. The service worker never caches office data, passwords, call records, or audio. It only displays an offline explanation when navigation cannot reach the server.


## IT office management

The catalog contains the 13 specified Silang offices and NPC Pampanga, NPC Cebu, NPC Davao and NPC Pagadian. Catalog entries are placeholders before sign-in; actual stations come from provisioned Firebase profiles.

To enable Manage offices for the initial IT account, use Firebase Realtime Database Console to set profiles/D3tb8FihdFTBQcipO5oe6mrvzmW2/office to "Office of the Chief, IT" and add profiles/D3tb8FihdFTBQcipO5oe6mrvzmW2/role as the string "admin". Publish the updated database.rules.json and sign out/in.

Manage offices lets IT add or edit a directory station by its existing Authentication User UID, office name, and campus. Create office accounts and passwords separately in Firebase Authentication first. The browser app cannot assign or modify administrator roles, and normal stations cannot edit the directory. Profile deletion is not offered.


## v6 Emergency siren

Deploy both the updated rules and app from the extracted v6 directory:

```
firebase deploy --only hosting,database --project npc-audio-intercom
```

Each signed-in office clicks **Enable emergency sound** once per open session.
Chief IT opens **Emergency siren**, selects configured offices, chooses 10 or 15 seconds, and clicks **Activate emergency siren**. **Stop siren now** stops the current broadcast early.
Use **Test on this device** to check audio locally without broadcasting.
Only profiles with role `admin` may write emergency alerts; Firebase rules enforce this.
Keep devices awake and the app open. Browser audio restrictions, suspended tabs, network loss, and offline stations can prevent or delay reception. The visual alert still appears on a selected connected station when sound has not been enabled. Emergency audio stops at its deadline locally, including after sender disconnection. This is a supplementary web alert, not a replacement for official emergency systems.
The database timestamp controls expiry; expired alerts do not replay on reconnect.


## v7 Guard stations, Personnel chat and paging

Campus label: NPC Silang. Three new catalog entries: Main Gate Guard, Admin Guard, Exit Gate Guard. These are templates; create their Firebase Authentication accounts first, then add their UIDs through Manage offices.
Chief IT can assign **Office**, **Guard**, or **Personnel** permissions when adding/editing non-admin stations. Existing administrator roles cannot be downgraded or granted through the client. Guard names and the original Personnel Section name are recognized for existing profiles; set the corresponding permissions to retain access if renamed.

Guard and Chief IT accounts may activate or stop emergency sirens. Regular offices cannot.

All provisioned offices have **Personnel chat**. Each office has a private thread with its chosen Personnel station; Personnel may reply and view its own inbox. Other offices cannot access that conversation. **Page this request** copies the request to the paging notes, not to automatic speech. Messages are saved to Firebase; the view shows the most recent 50 messages per conversation.

Personnel may record up to 20 seconds of voice, stop, preview, discard, then broadcast to all configured offices. This is a recorded announcement, not a live microphone broadcast. Recordings are capped at 150 KB binary / 200 KB encoded and replace the current announcement; no permanent audio archive is created. Notes are manual, not automatically transcribed. New announcements play automatically on connected sound-enabled stations. The announcement is available for manual replay for 60 seconds; older announcements do not autoplay when an office signs in. Incoming calls stop Personnel recording. An emergency siren takes priority over announcement playback.

Each office must click **Enable sirens & paging** and remain open, awake and connected. Browser/background restrictions can prevent receipt.

Deploy updated database rules and hosting:

```
firebase deploy --only hosting,database --project npc-audio-intercom
```

Test two separate office accounts on two devices: send a private request, reply from Personnel, record and preview a page, broadcast, then test a guard siren. Source-level checks do not replace this real-device test.
