Once you've signed in to the server, and sent and received presence information about roster members, you'll want to set up the session management pipeline. This is the set of Session Management and Logic components that monitor incoming connection requests and make outgoing connection requests. This is the most customized part of a libjingle application, because different applications have different requirements for sending or receiving connections: for example, do you need to create or read a list of files to share? Do you need to instantiate additional media engines? Do you need to generate a list of codecs as part of the session offer?
What tasks you perform to send a connection request, or to respond to a connection request, depends on your specific application. The basic underlying steps in session connection are described in How libjingle applications work. However, all applications will need to instantiate the following core libjingle objects:
The following code demonstrates the most high level of these steps. It is taken from pcp_main.cc, and modified for brevity and concept.
// Create the HttpPortAllocator and HttpPortAllocator, and SessionManager objects.
// We use the current thread (signaling thread) as the worker thread. To create
// a new worker thread, pass a new Thread object into the SessionManager constructor.
// See CallClient::InitPhone for an example of creating a worker thread.
talk_base::NetworkManager network_manager_;
talk_base::HttpPortAllocator *port_allocator_ = new talk_base::HttpPortAllocator(&network_manager_, "pcp");
cricket::SessionManager *session_manager_ = new cricket::SessionManager(&port_allocator, NULL);
// Create the object that will be used to send/receive XMPP session requests
// and start it up.
cricket::SessionManagerTask *session_manager_task = new cricket::SessionManagerTask(xmpp_client_, session_manager_);
session_manager_task->EnableOutgoingMessages();
session_manager_task->Start();
// Query for the STUN and relay ports being used. This is an asynchronous call,
// so we need to register for SignalJingleInfo, which sends the response.
buzz::JingleInfoTask *jingle_info_task = new buzz::JingleInfoTask(xmpp_client_);
jingle_info_task->RefreshJingleInfoNow();
jingle_info_task->SignalJingleInfo.connect(this, &FileShareClient::OnJingleInfo);
jingle_info_task->Start();
// Hook up a custom logic class that is used for file sharing in the File Share sample app.
file_share_session_client_.reset(new cricket::FileShareSessionClient(session_manager_.get(),
xmpp_client_->jid(), "pcp"));
file_share_session_client_->SignalFileShareSessionCreate.connect(this, &FileShareClient::OnFileShareSessionCreate);
// Associate the FileShareSessionClient with its global ID in SessionManager.
session_manager_->AddClient(NS_GOOGLE_SHARE, file_share_session_client_.get());
...
// Called by JingleInfoTask::SignalJingleInfo with the ports being used.
void OnJingleInfo(const std::string &relay_token,
const std::vector<std::string> &relay_addresses,
const std::vector<talk_base::SocketAddress> &stun_addresses) {
port_allocator_->SetStunHosts(stun_addresses);
port_allocator_->SetRelayHosts(relay_addresses);
port_allocator_->SetRelayToken(relay_token);
}