Slide 1

Slide 1 text

Peter-John Welcome GDE Firebase @pjapplez Developing locally with the Firebase UI Emulator An Introduction to the Firebase UI Emulator

Slide 2

Slide 2 text

Half screen photo slide if text is necessary Who I am Freelance Mobile Engineer Google Developer Expert for Firebase

Slide 3

Slide 3 text

Quick Firebase History Lesson

Slide 4

Slide 4 text

Syncing data in real time

Slide 5

Slide 5 text

● Always had to be online ● Felt a little like you were developing in Prod. ● Teammates would be sad if you broke database ● Using up your free quota for development ● Etc. Dev Environment Cons

Slide 6

Slide 6 text

● Creating dev and prod. projects ● Create separate database (RTDB) ● Using different BundleID’s and package names Some hacky solutions

Slide 7

Slide 7 text

Firebase Emulator

Slide 8

Slide 8 text

Emulator has been around for a while https://www.youtube.com/watch?v=tResEeK6P5I

Slide 9

Slide 9 text

Firebase UI Emulator

Slide 10

Slide 10 text

Firebase UI Emulator

Slide 11

Slide 11 text

● Accessing databases offline ● Can now run end to end tests on CI ● Easily import and export data ● Increase in development productivity ● Unit Testing security rules ● Testing does not contribute to your quota Benefits of UI Emulator

Slide 12

Slide 12 text

● Does not support all products ( Auth, Storage ) ● All triggers in cloud functions are not supported. Limitations of UI Emulator

Slide 13

Slide 13 text

UI Emulator You should not try and host the emulator as a prod environment yourself instead of using the Firebase Console.

Slide 14

Slide 14 text

Getting Started with the Emulator

Slide 15

Slide 15 text

● Node install version 8 or greater ● JDK version 1.8 or greater ● Firebase CLI UI Emulator

Slide 16

Slide 16 text

UI Emulator $ npm install -g firebase-tools $ firebase login $ firebase init $ firebase init emulators $ firebase emulators:start

Slide 17

Slide 17 text

UI Emulator ( Firebase.json ) { "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" }, "storage": { "rules": "storage.rules" }, "emulators": { "firestore": { "port": "8090" }, "ui": { "enabled": true, "host": "localhost", "port": 4001 }, "functions": { "port": "5001" }, "database": { "port": "9000" }, "pubsub": { "port": "8085" } } }

Slide 18

Slide 18 text

UI Emulator

Slide 19

Slide 19 text

UI Emulator http://Localhost:4001

Slide 20

Slide 20 text

How do we interact with the Emulator

Slide 21

Slide 21 text

Interacting with UI Emulator

Slide 22

Slide 22 text

Interacting with UI Emulator Dependencies implementation platform('com.google.firebase:firebase-bom:25.11.0') implementation 'com.google.firebase:firebase-firestore-ktx' implementation 'com.google.firebase:firebase-functions'

Slide 23

Slide 23 text

Interacting with UI Emulator Firestore private fun setUpFirebaseEmulators() { val host = "10.0.2.2" // Android Emulator localhost Firebase.firestore.useEmulator(host, 8080) Firebase.firestore.firestoreSettings = FirebaseFirestoreSettings.Builder() .setPersistenceEnabled(false) .build() }

Slide 24

Slide 24 text

Demo Firestore

Slide 25

Slide 25 text

Interacting with UI Emulator const functions = require('firebase-functions'); const admin = require("firebase-admin"); admin.initializeApp() exports.sayHello = functions.https.onCall ((data, context) => { const text = data.text; var db = admin.firestore(); const webDetection = JSON.parse('{"webEntities": [ {"entityId": "1", "score": 1.44225, "description": "Carnival in Rio de Janeiro" }]}'); let imageRef = db.collection('images').doc(text); imageRef.set(webDetection); }); Cloud functions js

Slide 26

Slide 26 text

Interacting with UI Emulator Cloud functions Android private fun setUpFirebaseEmulators() { var functions: FirebaseFunctions = FirebaseFunctions.getInstance() functions.useEmulator(host, 5001) } fun addMessage(text: String): Task { val data = hashMapOf(...) return functions .getHttpsCallable("sayHello") .call(data) .continueWith { task -> val result = task.result?.data as String } } addMessage("polls") //Invoking the cloud function

Slide 27

Slide 27 text

Interacting with UI Emulator Android 9 & above: Network security config 10.0.2.2 //In your Android manifest file

Slide 28

Slide 28 text

Demo Cloud Functions

Slide 29

Slide 29 text

UI Emulator There's more ● Firebase Web Hosting can be tested locally. ● Running containerized Emulator images with CLI on CI ● Emulating Pub/Sub interactions with Cloud Functions ● Realtime Database interaction ● Still able to connect to external services through emulator

Slide 30

Slide 30 text

References ● https://firebase.google.com/docs/emulator-suite ● https://github.com/pjwelcome/JetExample (Android Sample) ● https://github.com/pjwelcome/GDGCloudVision (iOS Sample) ● https://github.com/firebase ● https://www.youtube.com/user/Firebase ● https://www.youtube.com/watch?v=8CR86yFmY2I&feature=emb_logo ● https://www.youtube.com/watch?v=sl_8OGI68g4&feature=emb_logo ● https://firebaseonair.withgoogle.com/events/firebase-live20

Slide 31

Slide 31 text

Peter-John Welcome GDE Firebase @pjapplez Thank You!