About libjingle ................................................................................................................................... 2
libjingle Developer Guide .............................................................................................................. 3
Jingle and libjingle .................................................................................................................... 3
Prerequisites .............................................................................................................................. 3
Organization of the Documentation .......................................................................................... 4
Organization of the SDK ........................................................................................................... 4
Version Changelist ......................................................................................................................... 6
0.5.2 (January 11, 2011) ................................................................................................ 6
0.5.1 (November 2, 2010) ............................................................................................. 6
0.5.0 (September 16, 2010) .......................................................................................... 6
0.4.0 (February 1, 2007) ................................................................................................ 7
Important Concepts ........................................................................................................................ 8
Signals ....................................................................................................................................... 8
Threads .................................................................................................................................... 10
Naming Conventions ............................................................................................................... 14
SSL Support ............................................................................................................................ 14
Connections ............................................................................................................................. 14
Transports, Channels, and Connections .................................................................................. 16
Candidates ............................................................................................................................... 18
Data Packets ............................................................................................................................ 20
Generic libjingle Applications ...................................................................................................... 21
Details of a Session Connection ........................................................................................ 25
Startup ............................................................................................................................ 25
Signing in ....................................................................................................................... 25
Connecting .................................................................................................................... 25
Cleaning Up ................................................................................................................... 28
More Details .......................................................................................................................... 29
Creating a libjingle application .................................................................................................... 30
Creating a libjingle Application .............................................................................................. 30
Sample Applications ..................................................................................................................... 32
Build flags ............................................................................................................................... 32
Logging ................................................................................................................................... 32
Voice Chat Sample Application .............................................................................................. 33
File Share Sample Application ................................................................................................ 33
libjingle License Agreement ........................................................................................................ 35
About libjingle
libjingle is a collection of open-source C++ code and sample applications that enables you to build a
peer-to-peer application. The code handles creating a network connection (through NAT and firewall
devices, relay servers, and proxies), negotiating session details (codecs, formats, etc.), and exchanging
data. It also provides helper tasks such as parsing XML, and handling network proxies. You could
build the following programs with libjingle:
A multi-user voice chat application
A multi-user video conferencing application
A multi-user live music streaming application
A peer-to-peer file sharing application
libjingle is available on Google Code for both Windows and UNIX/Linux operating systems. This
documentation supplements the readme files included with the code.
We are providing this source code as part of our ongoing commitment to promoting consumer choice
and interoperability in Internet-based real-time-communications. This code is made available under
a Berkeley-style license, which means you are free to incorporate it into commercial and
non-commercial software and distribute it.
libjingle Developer Guide
The libjingle SDK consists of C++ source code and documentation that enable you to design
applications that connect and exchange data across a network (peer to peer data connections). The SDK
contains code and sample applications, a Visual Studio 2005 solution file for compiling on Windows
computers, configuration and makefiles for other operating systems and compilers, and compilation
instructions. Note that the code has some external dependencies (for instance, the voice chat sample has
dependencies on Linphone or GIPS VoiceEngine Lite, depending on your platform). Dependencies are
indicated in the code and the build instructions.
The code includes network and proxy negotiation classes, XML parsing classes, a STUN server, and all
the code required to initiate connections and exchange data between two computers. The connection
code enables applications to robustly traverse NAT and firewall devices using the ICE mechanism, to
use STUN servers, and to exchange either UDP or TCP data packets. You can use the code as provided,
or extend it fit your own specific needs, according to the Berkeley-style license.
Jingle and libjingle
libjingle was created at about the same time as the Jingle XMPP extension (XEP-0166). The libjingle
team created their own protocol to handle session negotiation, and later worked with the XMPP
Standards Foundation to standardize Jingle; thus, although the libjingle protocol and Jingle are very
similar, they are not the same, and are not interoperable.
The current version of the libjingle code still uses the original internal protocol, which is slightly
different from, and incompatible with, the Jingle specification. Nevertheless, it is close enough to
Jingle that it is worthwhile learning the Jingle specifications. Similar "close but not identical"
conditions exist for libjingle's audio content description (early version of Jingle Audio Content
Description Format XEP-0167), ICE transport description (early version of Jingle Ice
Transport XEP-0176), and raw UDP transport description (early version of Jingle Raw UDP transport
description XEP-0177). Where this documentation refers to "Jingle" or one of its related extensions (in
terms of how libjingle uses that protocol), it really refers to the original, internal protocol
The libjingle team intends to implement the official Jingle extension in libjingle (while making
libjingle backward compatible for the current custom version).
Prerequisites
In order to use libjingle, you should be familiar with the XMPP protocol, general networking concepts,
and C++. Additionally, it helps to be familiar with the Jingle proposed extension (XEP-0166), and
other related extensions listed in Jingle and libjingle above.
The requirements to build and use libjingle are given in Creating a libjingle Application.
Organization of the Documentation
This documentation includes the following main topics:
Important Concepts Describes some of the key concepts in libjingle. Very important if
this is your first experience with libjingle.
Generic libjingle Applications Provides an overview of the main components of a
libjingle application, and some specifics about how a generic libjingle application creates a
peer-to-peer connection.
Creating a libjingle Application Describes the key tasks that every libjingle application
must perform.
Sample Applications Describes how to build and run the sample applications included
with the SDK. Also includes detailed information about how these applications work.
Reference A reference guide to the important libjingle classes.
Organization of the SDK
The libjingle SDK contains the following folders.
Directory
base/
examples/
Description
Classes for low-level base functionality such as sockets and threads. Both the p2p and session components depend on these classes.
Contains two sample applications built on libjingle: call, and file share. There are other files in this directory, but they are used for helper
applications.
p2p/
Classes in libjingle's Peer to Peer component, which negotiate, establish, and maintain peer-to-peer connections through almost any network
configuration regardless of NAT-enabled devices and firewalls.
session/
Classes that specializes the behavior of the basic peer to peer session according to what type of data is being exchanged (for example, voice or
files).
third_party/
The default folder to hold various third-party extensions needed by the code. For example, Linphone and GIPS VoiceEngine Lite files should be
xmllite/
xmpp/
installed here to use in the voice chat sample application.
Classes for parsing and building XMPP stanzas.
Classes for sending and receiving XMPP requests, and managing common XMPP server tasks (such as logging in or announcing presence).
Notes libjingle has some issues you should be aware of:
libjingle code is a work in progress. It is not perfect, complete, or flawless. Some aspects
of the code, such as password protection, are not securely implemented, and others, such as URL
parsing, are not as robust as they should be. Many, but not all, of these issues are commented in the
code. Be sure to code your application as robustly as possible. See Terms and Conditions for the
legal mumbo jumbo.
The example code uses SSL to transmit the password from the client to the XMPP server;
however, it does not provide any additional security (except turning off screen echo) to protect the
password on the client.
Version Changelist
The following changes have been made to succeeding versions of the libjingle SDK.
0.5.2 (January 11, 2011)
Fixed build on Windows 7 with VS 2010.
Fixed build on Windows x64.
Fixed build on Mac OSX.
Added an option to the "examples/call" to enable encrypted calls.
Improved logging.
Bug fixes.
0.5.1 (November 2, 2010)
Added support for call encryption.
Added addtional XEP-166 and XEP-167 features:
o Call redirection
o Candidates in session-accept or session-initiate
Added support for bandwidth control.
Added features in examples/call:
o Bandwidth control on initiate or accept
o Turn on/off SSL
o Control signaling protocol
o Send chat message
0.5.0 (September 16, 2010)
Implemented Jingle protocols XEP-166 and XEP-167.
Backward compatible with Google Talk Call Signaling protocol implemented in
previous versions.
Builds on Windows, Linux, and Mac OS X with swtoolkit.
Removed GipsLiteMediaEngine.
Added video support.
Added FileMediaEngine to support both voice and video via RTP dump.
Many bug fixes.
0.4.0 (February 1, 2007)
Updated p2p sample code -- The tunnel session client example was replaced by a file
sharing sample that uses HTTP protocol to exchange files.
New peer to peer stack -- The data pathway has been modified, with the removal of
the P2PSocket class, and addition of other helper classes. (P2PSocket has been
replaced by an additional layer of abstraction, managed by Transport.)
Removal of SessionMessage -- SessionMessage, a class that was used to wrap
custom XML data in the session negotiation channel, has been removed. All
session-specific information (such as file names and codecs) are now delivered as
raw XML stanzas to the SessionClient and Session objects.
Proxy support -- New code has been added to detect and support proxies
automatically. See base/proxydetect, base/autodetectproxy, and base/socketadapters
for details.
Threading changes:
o A new base class to create threaded objects has been created. This class,
signalthread, runs on its own thread, emits a signal when done, and destroys
itself.
o The file sharing application, unlike the tunnel sharing application, is
single-threaded.
New stream wrapper files -- libjingle 0.4.0 now includes several new stream wrapper
classes to provide additional I/O functionality. New classes include TarStream, to read
and write tar files, and StreamCounter, to count the number of bytes read or written in
a stream.
1.
2.
3.
4.
Important Concepts
You should understand the following important concepts about libjingle:
Signals
Threads and Messages
Naming Conventions
SSL Support
Connections
Transports, Channels, and Connections
Candidates
Data Packets
Signals
libjingle uses the sigslot library to facilitate communication between objects. sigslot is a generic
framework that enables you to connect a calling member to a receiving function in any class (including
the same class) very simply. The way it works is this:
The sending class declares a member variable, called a signal, using a special
template-like syntax. This signal defines the parameters of the listening function.
The listening class implements a function with the same number, type, and sequence of
parameters as the signal. This is sometimes called the receiver or the slot. (Note: this can even be
the same class as the one that declared the signal.) This function cannot return a value (e.g., returns
void). The receiver must inheritsigslot::has_slots<>.
The listener connects to the signal by calling the signal's connect method, passing in a
pointer to the instance of the listening object, and the address of the implementing class function.
The sender calls its signal member as if it were a function, passing in the appropriate
parameter types as declared. It can pass parameters by either value or reference.
You can connect as many signals as you like to a common slot. libjingle sometimes assigns multiple
signals to a single slot in order to consolidate its message handling. Conversely, several objects declare
a signal object in order to broadcast commonly needed messages from a single point (for example,
alerts sent when a connection state changes). sigslot takes care of disconnecting callbacks and
dereferencing when objects are destroyed.
The following code demonstrates using sigslot:
// Class that sends the notification.
class Sender {
// The signal declaration.