Firebase Configuration
The live result feed is served from Cloud Firestore. Initialise the Firebase app with the configuration below.
src/firebase.js
import { initializeApp } from "firebase/app";
const firebaseConfig = {
apiKey: "AIzaSyDy4qAKyW32ih06EbcCildkM1mv4Yz_Nks",
authDomain: "dnum-firestore-5c21e.firebaseapp.com",
projectId: "dnum-firestore-5c21e",
storageBucket: "dnum-firestore-5c21e.appspot.com",
messagingSenderId: "999037735902",
appId: "1:999037735902:web:d40fb04d73121a5131434f"
};
const app = initializeApp(firebaseConfig);
Firebase Service
The integration uses the Firestore database service.
| Value | |
|---|---|
| Collection | 4dResult |
| Document | NewResult |
Full path: 4dResult/NewResult
Reading the document
One-off read
import { getFirestore, doc, getDoc } from "firebase/firestore";
const db = getFirestore(app);
const snap = await getDoc(doc(db, "4dResult", "NewResult"));
if (snap.exists()) {
console.log(snap.data());
}
Live subscription
Results are pushed into this document as draws open, so a listener is the normal way to consume it.
import { getFirestore, doc, onSnapshot } from "firebase/firestore";
const db = getFirestore(app);
const unsubscribe = onSnapshot(doc(db, "4dResult", "NewResult"), (snap) => {
if (!snap.exists()) return;
render(snap.data());
});
// call unsubscribe() when the view unmounts
Response shape
The document payload is described in Result Fields. The same shape is returned by Pass Result, MYSGPrev, MYSGNext, OtherPrev and OtherNext.