//1. 接收服务器发送过来的状态
buzz::PresencePushTask *presence_push_ = new buzz::PresencePushTask(xmpp_client_);
presence_push_->SignalStatusUpdate.connect(this, &FileShareClient::OnStatusUpdate);
presence_push_->Start();
//2. 设置自身的状态
buzz::Status my_status;
my_status.set_.......
my_status.set_show(buzz::Status::SHOW_ONLINE);
//3 发送自身的状态
buzz::PresenceOutTask* presence_out_ = new buzz::PresenceOutTask(xmpp_client_);
presence_out_->Send(my_status);
presence_out_->Start();
//4-------------收到好友状态,从服务器传递过来的、(在当前程序中可不用)
void OnStatusUpdate(const buzz::Status& status)
{
if (status.available() && status.fileshare_capability()) //可以进行文件传输
if (status.available() && status.phone_capability()) //可以进行Call通信
}
在登录服务器且获得了好友的状态信息后,你需要设置会话管理管道,用来监视进来的连接请求和响应出去的连接请求。设置会话的步骤:
1. 实例化您的NetWorkManager, PortAllocator 子类,SessionManager对象;(注意:Libjingle的文件传输程序是采用传输完一个Session就结束程序,所以它采用的是单线程也是就是使用的主线程来运行Session;而Call通信过程就采用了多线程的模式,防止主线程被阻塞。这里的主线程也就是处理信息的线程,也叫做信号线程)
talk_base::NetworkManager network_manager_;
talk_base::scoped_ptrport_allocator_;
talk_base::scoped_ptrsession_manager_;
port_allocator_.reset(new cricket::HttpPortAllocator(&network_manager_, "pcp"));
session_manager_.reset(new cricket::SessionManager(port_allocator_.get(), NULL)); //使用单线程!对于我来说用什么?
or
worker_thread_ = new talk_base::Thread();//这个是语言通信的会话管理
session_manager_ = new cricket::SessionManager(port_allocator_, worker_thread_);
session_manager_->SignalRequestSignaling.connect(this, &CallClient::OnRequestSignaling);
session_manager_->OnSignalingReady();
worker_thread_->Start();
2. 创建一个用来发送和接受Session请求;xmpp_client_(能否手工初始化,而不是从服务中获取?)
cricket::SessionManagerTask *session_manager_task = new cricket::SessionManagerTask(xmpp_client_, session_manager_);
session_manager_task->EnableOutgoingMessages();
session_manager_task->Start();
3.查询stun和relay server。这是异步调用在OnJingleInfo中接受服务器反馈的信息
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();
4.文件传输Session开始;有点类似开始侦听
file_share_session_client_.reset(new cricket::FileShareSessionClient(session_manager_.get(), xmpp_client_->jid(), "pcp"));
file_share_session_client_->SignalFileShareSessionCreate.connect(this, &FileShareClient::OnFileShareSessionCreate);
session_manager_->AddClient(NS_GOOGLE_SHARE, file_share_session_client_.get());
【or】
phone_client_ = new cricket::PhoneSessionClient(xmpp_client_->jid(),session_manager_);
phone_client_->SignalCallCreate.connect(this, &CallClient::OnCallCreate);
worker_thread_->Start();
// 接收服务器发来的stun server、relay server的信息
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);
}
批注:
1.从第三步我们可以看出:stun server和relay server的配置信息在Jabber服务器上,而且不是一个;
公司的Jabber是否有这些信息?是否支持这种命令?
如果这三个信息不从服务器获得,relay_token又是什么东西?
2.NS_GOOGLE_SHARE="http://www.google.com/session/share";
session_manager_->AddClient(str, xmppclient)是注册一个客户端,其实就是将他们存入map中;而NS_GOOGLE_SHARE是key值,这有什么用呢?
文件传输只需要创建一个file_share_session_client_,每次传输文件是创建一个FileShareSession对象,有这个对象发送文件请求。
那么session_manager_为什么要将用map来存储file_share_session_client_呢?
文件发送完毕后;结束连接通道
下表列出了谷歌Talk中使用的非标准XMPP协议的扩展;除此之外都是标准的xmpp协议:
Extension | Description |
---|---|
User Settings | Enables a client to make and query client settings handled by the server. |
Off the Record Chats | Enables a client to turn off server-side logging for individual conversations, and alert clients to turn off client-side logging as well. |
Jingle Server Discovery | Returns a list of servers that a client can use to connect a Jingle session. 返回stun server、relay server信息清单(公司的Jabber需要扩展这条命令) |
Gmail Notifications | Enables a client to request notifications when their Gmail account receives a new email, or to query for unread emails. |
Shared Status Messages | Enables multiple client instances to share a central list of status messages. |
Extended Contact Attributes | Sets or retrieves additional information about roster members. |
JID Domain Discovery | Enables a client to sign into the Google server using either the gmail.com or googlemail.com domain. |
Voicemail | Enables a client to send voicemail messages to other chat clients. |