Professional XMPP Programming with JavaScript® and jQuery

Book description

Create real-time, highly interactive apps quickly with the powerful XMPP protocol

XMPP is a robust protocol used for a wide range of applications, including instant messaging, multi-user chat, voice and video conferencing, collaborative spaces, real-time gaming, data synchronization, and search. This book teaches you how to harness the power of XMPP in your own apps and presents you with all the tools you need to build the next generation of apps using XMPP or add new features to your current apps. Featuring the JavaScript language throughout and making use of the jQuery library, the book contains several XMPP apps of increasing complexity that serve as ideal learning tools.

Coverage Includes:

  • Getting to Know XMPP

  • Designing XMPP Applications

  • Saying Hello: The First Application

  • Exploring the XMPP Protocol: A Debugging Console

  • Microblogging in Real Time: An Identica Client

  • Talking with Friends: One-on-One Chat

  • Exploring Services: Service Discovery and Browsing

  • Group Chatting: A Multi-User Chat Client

  • Publishing and Subscribing: A Shared Sketch Pad Introduction

  • Writing with Friends: A Collaborative Text Editor

  • Playing Games: Head to Head Tic-Tac-Toe

  • Getting Attached: Bootstrapping BOSH

  • Deploying XMPP Applications

  • Writing Strophe Plug-ins

  • Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.

    Table of contents

    1. Copyright
    2. CREDITS
    3. ABOUT THE AUTHOR
    4. ACKNOWLEDGMENTS
    5. INTRODUCTION
      1. 0.1. WHO THIS BOOK IS FOR
      2. 0.2. WHAT THIS BOOK COVERS
      3. 0.3. HOW THIS BOOK IS STRUCTURED
      4. 0.4. WHAT YOU NEED TO USE THIS BOOK
      5. 0.5. CONVENTIONS
      6. 0.6. SOURCE CODE
      7. 0.7. ERRATA
      8. 0.8. P2P.WROX.COM
    6. I. XMPP Protocol and Architecture
      1. 1. Getting to Know XMPP
        1. 1.1. WHAT IS XMPP?
        2. 1.2. A BRIEF HISTORY OF XMPP
        3. 1.3. THE XMPP NETWORK
          1. 1.3.1. Servers
          2. 1.3.2. Clients
          3. 1.3.3. Components
          4. 1.3.4. Plug-ins
        4. 1.4. XMPP ADDRESSING
        5. 1.5. XMPP STANZAS
          1. 1.5.1. Common Attributes
            1. 1.5.1.1. from
            2. 1.5.1.2. to
            3. 1.5.1.3. type
            4. 1.5.1.4. id
          2. 1.5.2. Presence Stanzas
            1. 1.5.2.1. Normal Presence Stanzas
            2. 1.5.2.2. Extending Presence Stanzas
            3. 1.5.2.3. Presence Subscriptions
            4. 1.5.2.4. Directed Presence
          3. 1.5.3. Message Stanzas
            1. 1.5.3.1. Message Types
            2. 1.5.3.2. Message Contents
          4. 1.5.4. IQ Stanzas
          5. 1.5.5. Error Stanzas
        6. 1.6. THE CONNECTION LIFE CYCLE
          1. 1.6.1. Connection
          2. 1.6.2. Stream Set Up
          3. 1.6.3. Authentication
          4. 1.6.4. Disconnection
        7. 1.7. SUMMARY
      2. 2. Designing XMPP Applications
        1. 2.1. LEARNING FROM OTHERS
        2. 2.2. XMPP VERSUS HTTP
          1. 2.2.1. Advantages of XMPP
            1. 2.2.1.1. Pushing Data
            2. 2.2.1.2. Pleasing Firewalls
            3. 2.2.1.3. Improving Security
            4. 2.2.1.4. A Bigger Toolbox
          2. 2.2.2. Disadvantages of XMPP
            1. 2.2.2.1. Statefulness
            2. 2.2.2.2. Smaller Ecosystem
            3. 2.2.2.3. More Overhead
            4. 2.2.2.4. Specialized Implementations
        3. 2.3. BRIDGING XMPP AND THE WEB
          1. 2.3.1. Long Polling
          2. 2.3.2. Managing the Connection
          3. 2.3.3. Making JavaScript Speak XMPP
        4. 2.4. MAKING XMPP APPLICATIONS
          1. 2.4.1. The Browser Platform
          2. 2.4.2. Basic Infrastructure
          3. 2.4.3. Protocol Design
            1. 2.4.3.1. Compose Existing Protocols
            2. 2.4.3.2. Keep It Simple
            3. 2.4.3.3. Avoid Extending Presence
            4. 2.4.3.4. Participate in the Community
        5. 2.5. SUMMARY
    7. II. The Applications
      1. 3. Saying Hello: The First Application
        1. 3.1. APPLICATION PREVIEW
        2. 3.2. HELLO DESIGN
        3. 3.3. PREPARING THE WAY
          1. 3.3.1. jQuery and jQuery UI
          2. 3.3.2. Strophe
          3. 3.3.3. flXHR
          4. 3.3.4. XMPP Accounts
        4. 3.4. STARTING YOUR FIRST APPLICATION
          1. 3.4.1. User Interface
          2. 3.4.2. Application Code
            1. 3.4.2.1. Namespacing
            2. 3.4.2.2. Document Ready Handler
            3. 3.4.2.3. Custom Event Handlers
        5. 3.5. MAKING CONNECTIONS
          1. 3.5.1. The Connection Life Cycle
          2. 3.5.2. Creating a Connection
          3. 3.5.3. Connecting Hello
          4. 3.5.4. Running the Application
        6. 3.6. CREATING STANZAS
          1. 3.6.1. Strophe Builders
          2. 3.6.2. Saying Hello
        7. 3.7. HANDLING EVENTS
          1. 3.7.1. Adding and Removing Handlers
          2. 3.7.2. Stanza Matching
          3. 3.7.3. Stanza Handler Functions
          4. 3.7.4. Handling Responses in Hello
        8. 3.8. MORE HELLOS
        9. 3.9. SUMMARY
      2. 4. Exploring the XMPP Protocol: A Debugging Console
        1. 4.1. APPLICATION PREVIEW
        2. 4.2. PEEK DESIGN
        3. 4.3. BUILDING THE CONSOLE
          1. 4.3.1. User Interface
          2. 4.3.2. Displaying Traffic
          3. 4.3.3. Making XML Pretty
          4. 4.3.4. Dealing with XML Input
          5. 4.3.5. Making Input Easier
        4. 4.4. EXPLORING XMPP
          1. 4.4.1. Controlling Presence
          2. 4.4.2. Probing Versions
          3. 4.4.3. Dealing with Errors
            1. 4.4.3.1. IQ Stanza Errors
            2. 4.4.3.2. Message Stanza Errors
            3. 4.4.3.3. Presence Stanza Errors
        5. 4.5. BETTER DEBUGGING
        6. 4.6. SUMMARY
      3. 5. Microblogging in Real Time: An Identica Client
        1. 5.1. APPLICATION PREVIEW
        2. 5.2. ARTHUR DESIGN
        3. 5.3. MICROBLOGGING WITH IDENTICA
          1. 5.3.1. Creating Your Account
          2. 5.3.2. Turning on XMPP
        4. 5.4. BUILDING ARTHUR
          1. 5.4.1. Getting Started
          2. 5.4.2. Receiving Messages
        5. 5.5. XHTML-IM
          1. 5.5.1. Adding XHTML-IM to Arthur
          2. 5.5.2. Sending Messages
        6. 5.6. OFFLINE MESSAGES
        7. 5.7. CREATING A BETTER MICROBLOGGER
        8. 5.8. SUMMARY
      4. 6. Talking with Friends: One-on-One Chat
        1. 6.1. APPLICATION PREVIEW
        2. 6.2. GAB DESIGN
          1. 6.2.1. Presence
          2. 6.2.2. Messages
          3. 6.2.3. Chat Area
          4. 6.2.4. Roster Area
        3. 6.3. MAKING THE INTERFACE
        4. 6.4. BUILDING THE ROSTER
          1. 6.4.1. Requesting Rosters
          2. 6.4.2. Handling IQs
          3. 6.4.3. Updating Presence Status
          4. 6.4.4. Adding New Contacts
          5. 6.4.5. Responding to Roster Changes
          6. 6.4.6. Dealing with Subscription Requests
        5. 6.5. BUILDING THE CHATS
          1. 6.5.1. Working with Tabs
          2. 6.5.2. Creating New Chats
          3. 6.5.3. Sending Messages
        6. 6.6. BEST PRACTICES FOR INSTANT MESSAGING
          1. 6.6.1. Understanding Message Routing
          2. 6.6.2. Addressing Messages Better
        7. 6.7. ADDING ACTIVITY NOTIFICATIONS
          1. 6.7.1. Understanding Chat States
          2. 6.7.2. Sending Notifications
          3. 6.7.3. Receiving Notifications
        8. 6.8. FINAL TOUCHES
        9. 6.9. GABBING MORE
        10. 6.10. SUMMARY
      5. 7. Exploring Services: Service Discovery and Browsing
        1. 7.1. APPLICATION PREVIEW
        2. 7.2. DIG DESIGN
        3. 7.3. FINDING INFORMATION
          1. 7.3.1. Disco#info Queries
          2. 7.3.2. Disco#items Queries
          3. 7.3.3. Disco Nodes
        4. 7.4. CREATING DIG
          1. 7.4.1. Initial Disco Queries
          2. 7.4.2. Browsing the Disco Tree
        5. 7.5. DIGGING INTO SERVICES
          1. 7.5.1. Finding a Proxy Server
          2. 7.5.2. Discovering Features
          3. 7.5.3. Looking for a Chat
        6. 7.6. DISCOVERING MORE
        7. 7.7. SUMMARY
      6. 8. Group Chatting: A Multi-User Chat Client
        1. 8.1. APPLICATION PREVIEW
        2. 8.2. GROUPIE DESIGN
        3. 8.3. PUBLIC SPEAKING
          1. 8.3.1. Group Chat Services
          2. 8.3.2. Entering and Leaving a Room
          3. 8.3.3. Sending and Receiving Messages
          4. 8.3.4. Anonymity
          5. 8.3.5. Creating Rooms
          6. 8.3.6. Understanding Roles and Affiliations
        4. 8.4. BUILDING THE INTERFACE
        5. 8.5. JOINING THE ROOM
        6. 8.6. DEALING WITH PRESENCE AND MESSAGES
          1. 8.6.1. Handling Room Messages
          2. 8.6.2. Tracking Presence Changes
          3. 8.6.3. Chat History
          4. 8.6.4. Keeping It Private
          5. 8.6.5. Describing Actions
        7. 8.7. MANAGING THE ROOM
          1. 8.7.1. Changing Topics
          2. 8.7.2. Dealing with Troublemakers
          3. 8.7.3. Recruiting Help
        8. 8.8. IMPROVING GROUPIE
        9. 8.9. SUMMARY
      7. 9. Publishing and Subscribing: A Shared Sketch Pad Introduction
        1. 9.1. SKETCHCAST PREVIEW
        2. 9.2. SKETCHCAST DESIGN
          1. 9.2.1. Everything Is Pubsub
          2. 9.2.2. Presenter's Flow
          3. 9.2.3. Audience's Flow
        3. 9.3. FILLING OUT FORMS
          1. 9.3.1. What Is The Data Forms Extension?
          2. 9.3.2. Form Elements, Fields, and Types
            1. 9.3.2.1. The <x> Element's type Attribute
            2. 9.3.2.2. Form Metadata
            3. 9.3.2.3. Form Fields
          3. 9.3.3. Standardized Form Fields
        4. 9.4. WORKING WITH PUBSUB NODES
          1. 9.4.1. Creating Nodes
          2. 9.4.2. Configuring Nodes
          3. 9.4.3. Pubsub Events
          4. 9.4.4. Publishing to a Node
          5. 9.4.5. Subscribing and Unsubscribing
          6. 9.4.6. Retrieving Subscriptions
          7. 9.4.7. Retrieving Items
          8. 9.4.8. Subscription Management
        5. 9.5. BROADCASTING SKETCHES USING PUBSUB
          1. 9.5.1. Building the Interface
          2. 9.5.2. Sketching with Canvas
          3. 9.5.3. Logging In and Making Nodes
          4. 9.5.4. Publishing and Receiving Sketch Events
            1. 9.5.4.1. Sketch Events
            2. 9.5.4.2. Publishing Sketch Events
            3. 9.5.4.3. Receiving Sketch Events
            4. 9.5.4.4. Joining Late and Catching Up
            5. 9.5.4.5. Gracefully Ending the Session
            6. 9.5.4.6. A Better SketchPad
        6. 9.6. SUMMARY
      8. 10. Writing with Friends: A Collaborative Text Editor
        1. 10.1. APPLICATION PREVIEW
        2. 10.2. NETPAD DESIGN
        3. 10.3. OPERATIONAL TRANSFORMATION
          1. 10.3.1. Basic Principles
          2. 10.3.2. Details of the Algorithm
            1. 10.3.2.1. State
            2. 10.3.2.2. Operation Requests
            3. 10.3.2.3. Request Queue and Execution Log
            4. 10.3.2.4. Priorities
          3. 10.3.3. Implementation
            1. 10.3.3.1. Initial Code
            2. 10.3.3.2. Comparison Functions
            3. 10.3.3.3. Handling Requests
            4. 10.3.3.4. Execution
            5. 10.3.3.5. Transformation
        4. 10.4. EXTENDING THE XMPP PROTOCOL
          1. 10.4.1. Ignoring the Unknown
          2. 10.4.2. XML Namespaces
          3. 10.4.3. Extended Elements
            1. 10.4.3.1. Changing the Default Namespace
            2. 10.4.3.2. Namespace Prefixes
          4. 10.4.4. Extended Attributes
          5. 10.4.5. Contributing Extensions
        5. 10.5. DESIGNING THE PROTOCOL
          1. 10.5.1. Testing for Support
          2. 10.5.2. Requesting and Controlling Sessions
          3. 10.5.3. Editing Operations
        6. 10.6. BUILDING THE EDITOR
          1. 10.6.1. The Initial Skeleton
          2. 10.6.2. Starting Editing Sessions
            1. 10.6.2.1. Determining Feature Support
            2. 10.6.2.2. Establishing NetPad Sessions
          3. 10.6.3. Chatting About Work
          4. 10.6.4. Making Edits
            1. 10.6.4.1. Initializing OpTrans
            2. 10.6.4.2. Local and Remote Operations
        7. 10.7. EXPANDING NETPAD
        8. 10.8. SUMMARY
      9. 11. Playing Games: Head to Head Tic-Tac-Toe
        1. 11.1. APPLICATION PREVIEW
        2. 11.2. TOETEM DESIGN
        3. 11.3. DESIGNING THE GAME PROTOCOL
          1. 11.3.1. Keeping Track of Users
          2. 11.3.2. Managing Players
          3. 11.3.3. Managing Games
          4. 11.3.4. Playing and Watching the Game
        4. 11.4. GETTING STARTED ON TOETEM
        5. 11.5. IMPLEMENTING SESSIONS AND THE WAITING LIST
          1. 11.5.1. Referee Version One
          2. 11.5.2. Toetem Client Version One
        6. 11.6. IMPLEMENTING GAME MANAGEMENT
          1. 11.6.1. Referee Version Two
          2. 11.6.2. Toetem Client Version Two
        7. 11.7. IMPLEMENTING THE GAME LOGIC
          1. 11.7.1. The Tic-Tac-Toe Library
          2. 11.7.2. Referee Version Three
          3. 11.7.3. Toetem Client Version Three
        8. 11.8. MAKING THE GAME MORE FUN
        9. 11.9. SUMMARY
    8. III. Advanced Topics
      1. 12. Getting Attached: Bootstrapping BOSH
        1. 12.1. SESSION ATTACHMENT
          1. 12.1.1. The Mechanics of Sessions
          2. 12.1.2. Use Cases
            1. 12.1.2.1. Increased or Easier Security
            2. 12.1.2.2. Pushing Performance
            3. 12.1.2.3. Persisting Connections
        2. 12.2. AUTOMATIC LOGINS WITH SESSION ATTACHMENT
          1. 12.2.1. Creating the Django Project
        3. 12.3. SUMMARY
      2. 13. Deploying XMPP Applications
        1. 13.1. GROWING HORIZONTALLY
          1. 13.1.1. Multiple Connection Managers
            1. 13.1.1.1. nginx
            2. 13.1.1.2. Haproxy
          2. 13.1.2. Clustering XMPP Servers
          3. 13.1.3. Spreading Out Components
          4. 13.1.4. Federating Internally
          5. 13.1.5. Becoming a Server
        2. 13.2. GROWING VERTICALLY
          1. 13.2.1. Reducing Latency
            1. 13.2.1.1. Streamlining Connections and Setup
            2. 13.2.1.2. Dealing with Large Stanzas
          2. 13.2.2. Minimizing XML Serialization
          3. 13.2.3. Optimizing DOM Operations
            1. 13.2.3.1. Batching Operations
            2. 13.2.3.2. Cloning Instead of Creating
            3. 13.2.3.3. Limiting the Scope of Operations
        3. 13.3. SUMMARY
      3. 14. Writing Strophe Plug-ins
        1. 14.1. USING PLUG-INS
          1. 14.1.1. Loading Plug-ins
          2. 14.1.2. Accessing Plug-in Functionality
        2. 14.2. BUILDING PLUG-INS
        3. 14.3. CREATING A ROSTER PLUG-IN
          1. 14.3.1. Storing Contacts
          2. 14.3.2. Getting and Maintaining the Roster
          3. 14.3.3. Manipulating the Roster
        4. 14.4. TAKING THE PLUG-IN FOR A SPIN
          1. 14.4.1. Improving the Roster Plug-in
        5. 14.5. SUMMARY
    9. A. Getting Started with jQuery
      1. A.1. FINDING JQUERY
      2. A.2. JQUERY VERSUS DOM
      3. A.3. USING JQUERY
        1. A.3.1. Finding Elements
          1. A.3.1.1. Selectors
          2. A.3.1.2. Augmenting Selections
        2. A.3.2. Acting on Elements
        3. A.3.3. Making Chains
      4. A.4. MANIPULATING ELEMENTS
        1. A.4.1. Data Extraction
        2. A.4.2. Styling Elements
        3. A.4.3. Adding and Removing Elements
        4. A.4.4. Iterating over Selections
      5. A.5. DEALING WITH EVENTS
        1. A.5.1. Basic Event Methods
        2. A.5.2. Convenience Event Methods
        3. A.5.3. The Document Ready Event
      6. A.6. FURTHER READING
    10. B. Setting Up a BOSH Connection Manager
      1. B.1. CHOOSING A CONNECTION MANAGER
        1. B.1.1. Standalone Managers
        2. B.1.2. Built-In Managers
        3. B.1.3. Connection Manager Trade-offs
          1. B.1.3.1. Support for External Servers
          2. B.1.3.2. Setup and Configuration Complexity
          3. B.1.3.3. Scalability
      2. B.2. PUNJAB: A STANDALONE MANAGER
        1. B.2.1. Getting Punjab
        2. B.2.2. Installation and Setup
        3. B.2.3. Starting and Testing Punjab
      3. B.3. EJABBERD AND MOD_HTTP_BIND: A BUILT-IN MANAGER
        1. B.3.1. Obtaining mod_http_bind
        2. B.3.2. Configuring mod_http_bind
        3. B.3.3. Restarting and Testing ejabberd
      4. B.4. PROXIES AND SECURITY POLICY
        1. B.4.1. Cross-Domain Requests with Flash
          1. B.4.1.1. Serving crossdomain.xml with Punjab
          2. B.4.1.2. Serving crossdomain.xml with ejabberd
        2. B.4.2. Proxying BOSH
          1. B.4.2.1. Configuring Apache to Proxy BOSH
          2. B.4.2.2. Configuring nginx to Proxy BOSH
          3. B.4.2.3. Using Tape for Local Development
      5. B.5. MORE BOSH CONNECTION MANAGERS

    Product information

    • Title: Professional XMPP Programming with JavaScript® and jQuery
    • Author(s):
    • Release date: January 2010
    • Publisher(s): Wrox
    • ISBN: 9780470540718