Supercharge your app with Cloud Functions for Firebase
- 10. tinyurl.com/functions-lab | @bretmcg
Setting Up FriendlyChat
02.
Get the Sample Code
git clone
https://github.com/firebase/f
riendlychat
01.
Create a Firebase project and
Set up your app
From the console, create new
project called FriendlyChat and
enable Google Authentication
Install Firebase CLI and
deploy FriendlyChat
$ npm -g install firebase-tools
$ firebase deploy --except
functions
03.
- 11. tinyurl.com/functions-lab | @bretmcg
Setting Up FriendlyChat
02.
Get the Sample Code
git clone
https://github.com/firebase/f
riendlychat
01.
Create a Firebase project and
Set up your app
From the console, create new
project called FriendlyChat and
enable Google Authentication
Install Firebase CLI and
deploy FriendlyChat
$ npm -g install firebase-tools
$ firebase deploy --except
functions
03.
- 12. tinyurl.com/functions-lab | @bretmcg
Setting Up FriendlyChat
02.
Get the Sample Code
git clone
https://github.com/firebase/f
riendlychat
01.
Create a Firebase project and
Set up your app
From the console, create new
project called FriendlyChat and
enable Google Authentication
Install Firebase CLI and
deploy FriendlyChat
$ npm -g install firebase-tools
$ firebase deploy --except
functions
03.
- 14. tinyurl.com/functions-lab | @bretmcg
Database Structure
messages: {
-K2ib4H77rj0LYewF7dP: {
name: "Jen",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg",
text: "lol that's awesome!"
},
-K2ib5JHRbbL0NrztUfO: {
imageUrl: "gs://friendlychat-833ed.appspot.com/GJHZV...D0A.JPG",
name: "Bret",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg"
},
...
}
- 15. tinyurl.com/functions-lab | @bretmcg
Database Structure
messages: {
-K2ib4H77rj0LYewF7dP: {
name: "Jen",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg",
text: "lol that's awesome!"
},
-K2ib5JHRbbL0NrztUfO: {
imageUrl: "gs://friendlychat-833ed.appspot.com/GJHZV...D0A.JPG",
name: "Bret",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg"
},
...
}
- 16. tinyurl.com/functions-lab | @bretmcg
Database Structure
messages: {
-K2ib4H77rj0LYewF7dP: {
name: "Jen",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg",
text: "lol that's awesome!"
},
-K2ib5JHRbbL0NrztUfO: {
imageUrl: "gs://friendlychat-833ed.appspot.com/GJHZV...D0A.JPG",
name: "Bret",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg"
},
...
}
- 17. tinyurl.com/functions-lab | @bretmcg
Database Structure
messages: {
-K2ib4H77rj0LYewF7dP: {
name: "Jen",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg",
text: "lol that's awesome!"
},
-K2ib5JHRbbL0NrztUfO: {
imageUrl: "gs://friendlychat-833ed.appspot.com/GJHZV...D0A.JPG",
name: "Bret",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg"
},
...
}
- 18. tinyurl.com/functions-lab | @bretmcg
Cloud Functions environment
- Node.js 6.11.1
- Open-source, cross-platform
JavaScript run-time environment for
executing JavaScript code server-side
- Non-blocking - commands execute in
parallel, and use callbacks to signal
completion or failure
- Debian 8 “Jessie”
- Env contains ImageMagick
- 19. tinyurl.com/functions-lab | @bretmcg
// callback-hell.js
doThing1(function(a){
doThing2(a, function(b){
doThing3(b, function(c){
doThing4(c, function(d){
doThing5(d, function(e){
// ...
});
});
});
});
});
- 21. tinyurl.com/functions-lab | @bretmcg
return mkdirp(tmpDir).then(() => {
return file.download({destination: tmpFile});
}).then(() => {
console.log('File downloaded to ', tmpFile);
return spawn(...); //create the thumbnail
}).then(() => {
console.log('Thumbnail: ', tmpThumbFile);
return bucket.upload(tmpFile, {destination: thu});
}).catch(function(error) {
console.log("Argghhh!", error);
});
- 29. tinyurl.com/functions-lab | @bretmcg
Machine learning as an API
Cloud
Vision API
Cloud
Translation API
Cloud
Natural Language
API
Use your own data to train models
Cloud
Speech API
Cloud Video
Intelligence
Cloud Machine
Learning Engine
TensorFlow
Two ways we can help you benefit from ML
- 36. tinyurl.com/functions-lab | @bretmcg
Database Structure
messages: {
-K2ib4H77rj0LYewF7dP: {
name: "Jen",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg",
text: "lol that's awesome!"
},
-K2ib5JHRbbL0NrztUfO: {
imageUrl: "gs://friendlychat-833ed.appspot.com/GJHZV...D0A.JPG",
name: "Bret",
photoUrl: "https://lh3.googleusercontent.com/-xDoJpI/photo.jpg"
},
...
}