/* * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as admin from 'firebase-admin' const serviceAccount = require('../service-account.json') admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: `https://${serviceAccount.project_id}.firebaseio.com` }) ;(async () => { await chat('pizzachat', 'Fear', "What the heck is that?!") await chat('pizzachat', 'Joy', "Who puts broccoli on pizza?!") await chat('pizzachat', 'Disgust', "That's it. I'm done.") await chat('pizzachat', 'Anger', "Congratulations, San Francisco! You've ruined pizza!") process.exit(0) })() .catch(err => { console.error(err) }) async function chat(room: string, name: string, text: string) { const messagesRef = admin.database().ref('rooms').child(room).child('messages') await messagesRef.push({ name, text }) console.log(`${name}: ${text}`) await sleep(1500) } function sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); }