O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building the Realtime User Experience

Book Description

The Web is increasingly happening in realtime. With websites such as Facebook and Twitter leading the way, users are coming to expect that all sites should serve content as it occurs—on smartphones as well as computers. This book shows you how to build realtime user experiences by adding chat, streaming content, and including more features on your site one piece at a time, without making big changes to the existing infrastructure. You'll also learn how to serve realtime content beyond the browser.

Throughout the book are many practical JavaScript and Python examples for advanced web developers that you can use on your site now. And in the final chapter, you'll build a location-aware game that combines all of the technologies discussed.

  • Use the latest realtime syndication technology, including PubSubHubbub
  • Build dynamic widgets on your homepage to show realtime updates from several sources
  • Learn how to use long polling to "push" content from your server to browsers
  • Create an application using the Tornado web server that makes sense of massive amounts of streaming content
  • Understand the unique requirements for setting up a basic chat service
  • Use IM and SMS to enable users to interact with your site outside of a web browser
  • Implement custom analytics to measure engagement in realtime

Table of Contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
  3. 1. Introduction
    1. What Is Realtime?
      1. Changing Interactions
    2. Push Versus Pull
    3. Prerequisites
      1. Python
      2. JavaScript
      3. JavaScript Object Notation
      4. Google’s App Engine
    4. The Rest
  4. 2. Realtime Syndication
    1. Simple Update Protocol (SUP)
      1. The SUP file
      2. Subscribing with SUP
        1. Locating SUP feeds
        2. Checking the SUP feed
      3. Publishing with SUP
        1. Generating a SUP file
        2. Testing our SUP file
        3. The SUP header
    2. PubSubHubbub
      1. The Protocol
        1. Subscribe
        2. Publishing content
      2. Subscribing with PubSubHubbub
      3. Publishing with PubSubHubbub
  5. 3. The Dynamic Homepage (Widgets in Pseudorealtime)
    1. The Basic Widgets
      1. HTML
      2. Setting Up the JavaScript
        1. Initialize
        2. A word about JSONP
        3. Catching the trends
        4. Catching the tweets
        5. Displaying the updates
    2. FriendFeed in Realtime
    3. Live Images
    4. It Was All a Setup!
      1. The Old Versus the New
  6. 4. River of Content
    1. A Crash Course in Server Push
      1. Long Polling
      2. The Bayeux Protocol
      3. Cometd
    2. Setting Up Your Cometd Environment
      1. Putting Everything in Its Place
    3. A Realtime Live Blog
      1. The Two-Connection Limit
    4. Server-Side Filters (with Java)
    5. Integrating Cometd into Your Infrastructure
  7. 5. Taming the Firehose with Tornado
    1. Tornado
      1. Installing Tornado
      2. The Basic Framework
      3. Building an Application
      4. Asynchronous Tornado in Realtime
    2. Twitter’s Realtime Streaming APIs
    3. From the Firehose to the Web Browser
      1. Templates in Tornado
      2. Creating a Template for This Project
      3. The JavaScript Parts
  8. 6. Chat
    1. Setting Up the Basic Code
      1. The Basic HTML Frame
      2. The Python Shell
      3. The JavaScript Base
      4. Checking the Progress
    2. Logging In
      1. On the Server Side
      2. JavaScript
    3. Basic Chatting
      1. Chatting on the Server Side
      2. Sending Messages
      3. Receiving Messages
    4. Acting Natural
  9. 7. Instant Messaging
    1. Getting Started with Google App Engine
      1. Setting Up an Account
      2. Creating an Application with the SDK
        1. Inspecting the default application
      3. Taking Advantage of Google
      4. Keeping Track of the User
      5. The Deploy Button
      6. The Dashboard
    2. Receiving Instant Messages
    3. Sending Instant Messages
    4. Responding Intelligently
      1. The Basic Commands
      2. Checking Authentication via Instant Messenger
      3. Introducing a Third Party
    5. Setting Up an API
  10. 8. SMS
    1. The SMS Landscape
      1. Email to SMS
      2. SMS APIs
        1. SMS API providers
    2. Building the Basic Application
      1. Extending the Instant Messaging Application
      2. An SMS Service Class
      3. The Base Handler
      4. Preparing to Accept Messages
      5. Setting Up the Server
    3. Sending and Receiving the Messages
      1. TextMarks
        1. Reserving a keyword
        2. The Python class
        3. Testing it out
      2. Zeep Mobile
        1. Reserving a keyword
        2. The Python class
      3. Authenticating Users
        1. The authentication process
        2. The basic code
          1. Authenticating with Zeep Mobile
          2. Testing the authentication process
      4. Building an SMS API
        1. Testing the API
  11. 9. Measuring User Engagement: Analytics on the Realtime Web
    1. Realtime Analytics Services
      1. Chartbeat
      2. Woopra
    2. Customized Analytics
      1. Sending Tracking Pings with JavaScript
      2. Catching the Statistics on the Server
        1. Testing the pings
      3. Making Sense of the Traffic
      4. Viewing the Traffic
      5. Tracking Backend Traffic and Custom Data
      6. Sending Out Alerts
  12. 10. Putting It All Together
    1. The Game
      1. Caveats
    2. Getting Set Up
      1. Google App Engine
      2. Google Maps API Key
      3. EC2 or Other Hosted Server
      4. GeoModel
    3. The Basic Models
      1. UserInfo
      2. Disease
      3. Germ
      4. CommandCenter
      5. Textmark
      6. Messenger
      7. UserThreats
      8. GameUtils
    4. Building the Game Itself
      1. User Authentication
      2. Geolocation
      3. Spreading Germs
      4. Loading Germs
      5. Threats
        1. Natural threats
        2. Initiating a challenge
        3. Updating threats
        4. Responding to challenge threats: Receiving XMPP and SMS messages
          1. Receiving XMPP messages
          2. Receiving SMS messages
          3. Handling the response
          4. Responses in action
      6. Spreading Germs
      7. Fighting Germs
      8. Realtime Syndication
        1. Publishing the feed
      9. The Command Center
        1. The basic site
        2. Authentication
        3. Consuming PubSubHubbub
        4. Notifying users
          1. Handling long polling on the server
          2. Long polling on the client side
        5. Chat
          1. Server side
          2. Client side
    5. In Review
  13. Index
  14. About the Author
  15. Colophon
  16. Copyright