“In addition to giving developers near real-time access to our data, we got out of the box well designed, easy to use SDKs for iOS, Android and the Web, in addition to a REST API for developers building server apps. It should hopefully making switching your apps fairly painless.”
var ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); var itemRef; ref.child('topstories').child(0).on('value', function(snapshot) { if(itemRef) { itemRef.off(); } //Get the ID of the top article var id = snapshot.val(); //Get the article details and update in realtime itemRef = ref.child('item').child(id); itemRef.on('value', function(snapshot) { var item = snapshot.val(); document.getElementById("score").innerHTML = item.score; var anchor = document.getElementById("article_a") anchor.innerHTML = item.title; anchor.href = item.url; document.getElementById("comments_a").href = "https://news.ycombinator.com/item?id=" + item.id; }); });
Firebase *ref = [[Firebase alloc] initWithUrl:@"https://hacker-news.firebaseio.com/v0/"]; __block Firebase *itemRef = nil; Firebase *topStories = [ref childByAppendingPath:@"topstories"]; Firebase *firstStory = [topStories childByAppendingPath:@"0"]; FirebaseHandle handle = [firstStory observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { if(itemRef != nil) { [itemRef removeObserverWithHandle: handle]; } NSString *itemId = [NSString stringWithFormat:@"item/%@",snapshot.value]; itemRef = [ref childByAppendingPath:itemId]; [itemRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *itemSnap) { NSLog(@"%@", itemSnap.value); }]; }];
final Firebase ref = new Firebase("https://hacker-news.firebaseio.com/v0/"); final Map<Long, ValueEventListener> valueEventListenerMap = new HashMap(); ref.child("topstories").child("0").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if(!valueEventListenerMap.isEmpty()) { for(Long id : valueEventListenerMap.keySet()) { ref.child("item").child(String.valueOf(id)).removeEventListener(valueEventListenerMap.get(id)); } valueEventListenerMap.clear(); } //Get the ID of the top article Long id = (Long) snapshot.getValue(); //Get the article details and update in realtime ValueEventListener articleListener = ref.child("item").child(String.valueOf(id)).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Map itemMap = (Map) snapshot.getValue(); // Print the title to the console System.out.println(itemMap.get("title")); } @Override public void onCancelled(FirebaseError firebaseError) { } }); valueEventListenerMap.put(id, articleListener); } @Override public void onCancelled(FirebaseError firebaseError) { } });
Check out the full HN documentation at hacker-news.firebaseapp.com.
With more than 100,000 developers using our platform, we’ve seen Firebase used both as the entire backend for apps as well as to power specific realtime features in apps. A growing use case has been loading data into Firebase to expose an API to other developers. Traditionally, building and maintaining a public API is a big undertaking; often entire teams are dedicated to it. It’s not easy to give third party developers access to your data in a way that’s both safe for your users and powerful for those developers. With Firebase, all you need to do is sync data to your Firebase and API consumers can then use one of Firebase’s realtime clients or the REST API to consume that data. You don’t have to worry about scaling with developer usage and or documenting anything beyond your data structure. You can learn more in a blog post we published last year.
We can’t wait to see what you build!
Last week, we released v1.0.0 of our open-source apps Firepad and Firechat! These are two great open-source modules built on top of Firebase that you can take and use in your own apps.
Firepad is a collaborative text editor. It lets you bring the features of Google Docs right into your app. Firepad can handle both code and rich text, and is currently being used in production by Atlassian, LiveMinutes, and CoderPad to name a few.
Firechat is a realtime chat app built with Firebase. Firechat’s features include multi-user / multi-room chat, flexible authentication, moderation, presence, private messaging, chat invitations and more. CBS is using Firebase to power the realtime chat for their Big Brother TV series.
Orginally we built both of these modules to showcase the realtime and collaborative power of Firebase, but they’ve grown into full-featured, production-ready pieces of functionality. Both projects have reached the point where they’re stable, full-featured and well-documented, so we’ve decided to officially tag them as 1.0!
Here's what's new in the 1.0.0 releases:
With help from the community, we’ve added some highly-requested features and fixed many bugs over the past few months.
We added a headless mode for interacting with documents programmatically with no GUI (e.g. from your backend server code). It can run in Node or in a browser. To use it from Node, just run npm install firepad, require the module, and add a headless instance of Firepad using the following code:
npm install firepad
var Firepad = require('firepad'); var headless = new Firepad.Headless('');
We've made a number of API improvements to make writing apps using Firepad easier. For instance, there's a new defaultText option to specify initial text to be loaded in Firepad, and there's a new "synced" event to notify you when your changes have successfully been synced with Firebase so you can provide notice to the user. See the API docs for full details.
defaultText
We've also fixed many minor bugs and UI issues to make the collaborative editing as fluid and seamless as possible! Firepad is now available on the Firebase CDN as well as Bower, making it even easier to include in your app.
Our Firechat homepage is now hosted on Firebase Hosting. In addition to this, we’ve improved the documentation, fixed bugs, and added warning messages to make development easier. Firechat now works well with other frameworks like Twitter Bootstrap, so you can customize the app’s default styling.
If you’re using Firepad or Firechat in your apps, we’d love your input. Email us any feedback at firebase-support@google.com or submit a pull request on GitHub. We’re excited to see what you build!
Ever since we released GeoFire for JavaScript, we've seen many requests for mobile ports of the library. Today, we're happy to announce GeoFire for iOS and Android!
GeoFire is now supported on our three major platforms - web, iOS and Android - and each library is open source! Each version comes with a sample app, which queries and displays San Francisco public transportation data in realtime.
You can find the corresponding sample apps as part of the GeoFire repos for Objective-C and Java.
If you're new to GeoFire, it's a geolocation library that maps string keys to locations and stores them in Firebase. Using GeoFire, you can answer a simple but important question: Which keys lie within a given geographic region? But GeoFire's features don't stop at simple location queries, it's true power is that everything happens in realtime. When objects move, events will be fired as they enter, exit and move around the region.
GeoFire opens a wide range of possibilities: You can build an app that displays who's going for a run within a mile radius of yourself and show their location in realtime. You can display taxis within a search radius and animate them as they move. Or you can build an app that simply lists all interesting bars nearby.
The GeoFire libraries are available as a XCode Framework and as a Java jar-file for easy integration. Add them to your app, include the Firebase library and you're ready to go.
All three versions are compatible with each other. If you are storing locations in your iOS or Android app, you will be able to query them in the web and vice versa.
Take a look at our quick start guides for the Objective-C and the Java versions to get familiar with GeoFire on each platform.
GeoFire is designed to be a lightweight add-on for Firebase, not a replacement. As such, you will continue to store your data just as you would normally do in Firebase and use GeoFire to query keys by location.
Let's assume we're building a social running app, where we want to display stats for all runners in our area. We'll start by storing basic data for each user like the following:
{ "users": { "steve123": { "displayname": "Steve T.", "age": 29, "location": [37.12314, -122.49182], "stats": { "averageSpeed": 11.2, "currentSpeed": 9.7, ... } }, "nikky_kay": { "displayname": "Nicole", "age": 37, "location": [37.67134, -122.32990], "stats": { ... } }, ... } }
Now that we've stored our user information in Firebase, we'll use GeoFire to search for nearby runners in realtime. In this example, we're storing each user by their username, and the user's location as a pair of latitude-longitude coordinates. By keeping the location key as a child of the user key, we can listen for realtime updates for a single user. Everytime we update the location of a user we simultaneously update the location for that user in GeoFire.
We'll now use a GeoQuery to retrieve all keys (usernames in this example) in a given geographic region. Using the key entered and key exited events, we can keep track of all users currently matching the query, e.g. with a NSMutableSet in Objective-C or Set<String> in Java.
NSMutableSet
Set<String>
NSMutableSet *runnersNearby = [NSMutableSet set]; // query around current user location with 1.6km radius GFQuery *query = [self.geoFire queryAtLocation:currentUserLocation withRadius:1.6]; [query observeEventType:GFEventTypeKeyEntered withBlock:^(NSString *username, CLLocation *location) { [runnersNearby addObject:username]; // additional code, like displaying a pin on the map // and adding Firebase listeners for this user }]; [query observeEventType:GFEventTypeKeyExited withBlock:^(NSString *username, CLLocation *location) { [runnersNearby removeObject:username] // additional code, like removing a pin from the map // and removing any Firebase listener for this user }];
final Set<String> runnersNearby = new HashSet<String>(); // query around current user location with 1.6km radius GeoQuery geoQuery = geoFire.queryAtLocation(currentUserLocation, 1.6); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String username, GeoLocation location) { runnersNearby.add(username); // additional code, like displaying a pin on the map // and adding Firebase listeners for this user } @Override public void onKeyExited(String username) { runnersNearby.remove(username); // additional code, like removing a pin from the map // and removing any Firebase listener for this user } ... });
We're ready to update our UI in realtime! Now that we know which users are nearby and we want to display, we can add a normal Firebase listener to each user and keep their stats updated in realtime. Remember, adding a listener in Firebase is a very lightweight operation, and adding thousands of listeners is not a problem. If a user ever moves outside the query, all we need to do is remove that listener and update our UI.
We're excited to see the amazing apps you build with Firebase and GeoFire! If you have any feedback on our new mobile libraries, you can email me at jonny@firebase.com or send us a pull request.
This past weekend Y Combinator hosted a hackathon, YCHacks. 540 developers answered the call. Over the weekend they turned pizza, energy drinks, and APIs into 123 projects.
At Firebase we really love hackathons, so it didn't take much effort to convince about half of the team to attend. This gave us a great opportunity to exchange high fives with developers who use Firebase. It turned out to be quite a few high fives because 34 teams used Firebase including two of the top three prize winners. In fact, so many developers used Firebase, that nearly 4% of the total network traffic was to our API servers.
All of the presentations were impressive, but a couple stood out as the best realtime apps.
Awear combines the Myo gesture detection arm band with Bluetooth location beacons to provide you with a way to control the technology near you by waving your hand. For example, when you're in the living room, a hand gesture might turn on the music, and in the kitchen the same gesture could flip through a digital cookbook.
Awear is a great example of how ubiquitous Internet connectivity is going to change the way devices talk to each other. With so many devices interacting with each other, the team found inter-device communication challenging. At 3:00 AM on Saturday they decided to give Firebase a go. Within a couple hours, all of the hardware was working in harmony. To quote them, "Firebase, you saved our lives!"
Virtual reality makes a lot of new, amazing experiences possible, but the Vrniture team also thinks it can change the way we do some more mundane tasks. Specifically, shopping for furniture. Vrniture used Firebase to wire up 3d models of your room with models of furniture you might like. It then presented a preview on an Oculus Rift so that you can experience new furniture in your home without having to rent a truck.
Those were our favorite examples of realtime development with Firebase, but there was other cool stuff too. A lot of it happened to be powered by Firebase.
High fives keep many of us running. They're an effective way to smack back the things that get us down. But as effective as they are for happiness, they're hard to track. It's hard to know if you've had your prescribed dose.
Quantified High Fives changes all that. It uses the motion sensor in the Pebble smartwatch, and a Firebase to accurately and effectively track your intake of High-5s. It even displays your current count in realtime. Now when you wonder, "Have I had enough?" your Pebble smartwatch and Firebase can tell you.
Tanay Tandon of team Athelas added a hemispherical lens to an iPhone and discovered that the optically enhanced camera was able to image individual blood cells. He then threw OpenCV at in an attempt to identify blood borne pathogens, like Malaria. In other words, he turned commodity electronics into a low cost blood scanner. The scanner app then stores test results in Firebase.
YCHacks was great fun. We really enjoyed seeing all of the ways that people used Firebase, and we can't wait for the next one!
There was some celebration in our office yesterday as the total number of concurrent network connections to our servers topped one million for the first time. This is a much bigger milestone than simply one million total users; it means that at this very moment there are one million users active on Firebase-powered apps.
Firebase is no longer the scrappy little startup you might remember from our launch more than two years ago. We’ve grown up. More than 83,000 developers have created over 100,000 applications using our platform. Our servers handle 24,000,000 user sessions every day, and in the last month we’ve seen traffic from over 50,000,000 unique IP addresses (over 1% of the IPv4 address space!). Our customer list now includes large companies like Google, Yahoo, and Citrix, as well as up-and-coming startups like Instacart, Nitrous.io, and Invision.
Our team has grown as well. One year ago, there were seven of us. Today, there are 24 (plus an intern), including new folks hailing from great companies like Google, Microsoft, and Salesforce. We’ve even welcomed our first PhD to the team.
The last couple years have been a whirlwind, but we’re far more excited about what’s coming next. Nearly every part of our product has new features currently under heavy development. In fact, most of the work we’ve done over the last year has been on features that have yet to be announced. Expect big upgrades to our core API, mobile support, security API, tooling, educational resources, and framework integrations in the near future.
Mobile is an especially bright spot for us. Our sync-based API is especially powerful on mobile devices where network connections are spotty or absent. As a result, Android and iOS are now our fastest growing platforms, and we’re putting a ton of resources into improving our mobile featureset.
None of this would have been possible without a ton of community support. Thank you for your help, whether that was providing API feedback, contributing to our open source projects, answering questions on our Google Groups, or simply telling a friend about our service.
We’d invite you all by our office so we could thank you in-person, but we know most of you are not in San Francisco. So instead, if you’d like us to send you some delicious Firebase Hot Sauce and other swag, shoot us an email and we’ll hook you up. Or, if you are in fact in San Francisco, you’re welcome to come by for office hours any Friday.
Thanks again, and we look forward to updating you again at 10,000,000 concurrents!