diff options
Diffstat (limited to 'third_party/libjingle/source/talk/examples')
4 files changed, 155 insertions, 395 deletions
diff --git a/third_party/libjingle/source/talk/examples/call/call_main.cc b/third_party/libjingle/source/talk/examples/call/call_main.cc index dde0784..541aca8 100644 --- a/third_party/libjingle/source/talk/examples/call/call_main.cc +++ b/third_party/libjingle/source/talk/examples/call/call_main.cc @@ -36,6 +36,7 @@ #include "talk/base/stream.h" #include "talk/base/ssladapter.h" #include "talk/base/win32socketserver.h" +#include "talk/p2p/base/constants.h" #include "talk/xmpp/xmppclientsettings.h" #include "talk/examples/login/xmppthread.h" #include "talk/examples/login/xmppauth.h" @@ -194,7 +195,7 @@ cricket::MediaEngine* CreateFileMediaEngine(const char* voice_in, // the the input voice and video streams. std::vector<cricket::AudioCodec> voice_codecs; voice_codecs.push_back( - cricket::AudioCodec(9, "G722", 16000, 64000, 1, 0)); + cricket::AudioCodec(9, "G722", 16000, 0, 1, 0)); file_media_engine->set_voice_codecs(voice_codecs); std::vector<cricket::VideoCodec> video_codecs; video_codecs.push_back( @@ -214,7 +215,11 @@ int main(int argc, char **argv) { // define options DEFINE_bool(a, false, "Turn on auto accept."); DEFINE_bool(d, false, "Turn on debugging."); + DEFINE_string( + protocol, "hybrid", + "Initial signaling protocol to use: jingle, gingle, or hybrid."); DEFINE_bool(testserver, false, "Use test server"); + DEFINE_bool(plainserver, false, "Turn off tls and allow plain password."); DEFINE_int(portallocator, 0, "Filter out unwanted connection types."); DEFINE_string(filterhost, NULL, "Filter out the host from all candidates."); DEFINE_string(pmuc, "groupchat.google.com", "The persistant muc domain."); @@ -234,11 +239,25 @@ int main(int argc, char **argv) { bool auto_accept = FLAG_a; bool debug = FLAG_d; + std::string protocol = FLAG_protocol; bool test_server = FLAG_testserver; + bool plain_server = FLAG_plainserver; int32 portallocator_flags = FLAG_portallocator; std::string pmuc_domain = FLAG_pmuc; std::string server = FLAG_s; + cricket::SignalingProtocol initial_protocol = cricket::PROTOCOL_HYBRID; + if (protocol == "jingle") { + initial_protocol = cricket::PROTOCOL_JINGLE; + } else if (protocol == "gingle") { + initial_protocol = cricket::PROTOCOL_GINGLE; + } else if (protocol == "hybrid") { + initial_protocol = cricket::PROTOCOL_HYBRID; + } else { + printf("Invalid protocol. Must be jingle, gingle, or hybrid."); + return 1; + } + // parse username and password, if present buzz::Jid jid; std::string username; @@ -279,6 +298,10 @@ int main(int argc, char **argv) { xcs.set_host(jid.domain()); xcs.set_use_tls(!test_server); + if (plain_server) { + xcs.set_use_tls(false); + xcs.set_allow_plain(true); + } if (test_server) { pass.password() = jid.node(); xcs.set_allow_plain(true); @@ -329,6 +352,8 @@ int main(int argc, char **argv) { client->SetAutoAccept(auto_accept); client->SetPmucDomain(pmuc_domain); client->SetPortAllocatorFlags(portallocator_flags); + client->SetAllowLocalIps(true); + client->SetInitialProtocol(initial_protocol); console->Start(); if (debug) { diff --git a/third_party/libjingle/source/talk/examples/call/call_main.cc~ b/third_party/libjingle/source/talk/examples/call/call_main.cc~ deleted file mode 100644 index fd7aafd..0000000 --- a/third_party/libjingle/source/talk/examples/call/call_main.cc~ +++ /dev/null @@ -1,348 +0,0 @@ -/* - * libjingle - * Copyright 2004--2005, Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <time.h> -#include <iomanip> -#include <cstdio> -#include <cstring> -#include <vector> -#include "talk/base/logging.h" -#include "talk/base/flags.h" -#include "talk/base/pathutils.h" -#include "talk/base/stream.h" -#include "talk/base/ssladapter.h" -#include "talk/base/win32socketserver.h" -#include "talk/xmpp/xmppclientsettings.h" -#include "talk/examples/login/xmppthread.h" -#include "talk/examples/login/xmppauth.h" -#include "talk/examples/login/xmpppump.h" -#include "talk/examples/call/callclient.h" -#include "talk/examples/call/console.h" -#include "talk/session/phone/filemediaengine.h" - -class DebugLog : public sigslot::has_slots<> { - public: - DebugLog() : - debug_input_buf_(NULL), debug_input_len_(0), debug_input_alloc_(0), - debug_output_buf_(NULL), debug_output_len_(0), debug_output_alloc_(0), - censor_password_(false) - {} - char * debug_input_buf_; - int debug_input_len_; - int debug_input_alloc_; - char * debug_output_buf_; - int debug_output_len_; - int debug_output_alloc_; - bool censor_password_; - - void Input(const char * data, int len) { - if (debug_input_len_ + len > debug_input_alloc_) { - char * old_buf = debug_input_buf_; - debug_input_alloc_ = 4096; - while (debug_input_alloc_ < debug_input_len_ + len) { - debug_input_alloc_ *= 2; - } - debug_input_buf_ = new char[debug_input_alloc_]; - memcpy(debug_input_buf_, old_buf, debug_input_len_); - delete[] old_buf; - } - memcpy(debug_input_buf_ + debug_input_len_, data, len); - debug_input_len_ += len; - DebugPrint(debug_input_buf_, &debug_input_len_, false); - } - - void Output(const char * data, int len) { - if (debug_output_len_ + len > debug_output_alloc_) { - char * old_buf = debug_output_buf_; - debug_output_alloc_ = 4096; - while (debug_output_alloc_ < debug_output_len_ + len) { - debug_output_alloc_ *= 2; - } - debug_output_buf_ = new char[debug_output_alloc_]; - memcpy(debug_output_buf_, old_buf, debug_output_len_); - delete[] old_buf; - } - memcpy(debug_output_buf_ + debug_output_len_, data, len); - debug_output_len_ += len; - DebugPrint(debug_output_buf_, &debug_output_len_, true); - } - - static bool IsAuthTag(const char * str, size_t len) { - if (str[0] == '<' && str[1] == 'a' && - str[2] == 'u' && - str[3] == 't' && - str[4] == 'h' && - str[5] <= ' ') { - std::string tag(str, len); - - if (tag.find("mechanism") != std::string::npos) - return true; - } - return false; - } - - void DebugPrint(char * buf, int * plen, bool output) { - int len = *plen; - if (len > 0) { - time_t tim = time(NULL); - struct tm * now = localtime(&tim); - char *time_string = asctime(now); - if (time_string) { - size_t time_len = strlen(time_string); - if (time_len > 0) { - time_string[time_len-1] = 0; // trim off terminating \n - } - } - LOG(INFO) << (output ? "SEND >>>>>>>>>>>>>>>>" : "RECV <<<<<<<<<<<<<<<<") - << " : " << time_string; - - bool indent; - int start = 0, nest = 3; - for (int i = 0; i < len; i += 1) { - if (buf[i] == '>') { - if ((i > 0) && (buf[i-1] == '/')) { - indent = false; - } else if ((start + 1 < len) && (buf[start + 1] == '/')) { - indent = false; - nest -= 2; - } else { - indent = true; - } - - // Output a tag - LOG(INFO) << std::setw(nest) << " " - << std::string(buf + start, i + 1 - start); - - if (indent) - nest += 2; - - // Note if it's a PLAIN auth tag - if (IsAuthTag(buf + start, i + 1 - start)) { - censor_password_ = true; - } - - // incr - start = i + 1; - } - - if (buf[i] == '<' && start < i) { - if (censor_password_) { - LOG(INFO) << std::setw(nest) << " " << "## TEXT REMOVED ##"; - censor_password_ = false; - } else { - LOG(INFO) << std::setw(nest) << " " - << std::string(buf + start, i - start); - } - start = i; - } - } - len = len - start; - memcpy(buf, buf + start, len); - *plen = len; - } - } -}; - -static DebugLog debug_log_; -static const int DEFAULT_PORT = 5222; - - -cricket::MediaEngine* CreateFileMediaEngine(const char* voice_in, - const char* voice_out, - const char* video_in, - const char* video_out) { - cricket::FileMediaEngine* file_media_engine = new cricket::FileMediaEngine; - // Set the RTP dump file names. - if (voice_in) { - file_media_engine->set_voice_input_filename(voice_in); - } - if (voice_out) { - file_media_engine->set_voice_output_filename(voice_out); - } - if (video_in) { - file_media_engine->set_video_input_filename(video_in); - } - if (video_out) { - file_media_engine->set_video_output_filename(video_out); - } - - // Set voice and video codecs. TODO: The codecs actually depend on - // the the input voice and video streams. - std::vector<cricket::AudioCodec> voice_codecs; - voice_codecs.push_back( - cricket::AudioCodec(9, "G722", 16000, 0, 1, 0)); - file_media_engine->set_voice_codecs(voice_codecs); - std::vector<cricket::VideoCodec> video_codecs; - video_codecs.push_back( - cricket::VideoCodec(97, "H264", 320, 240, 30, 0)); - file_media_engine->set_video_codecs(video_codecs); - - return file_media_engine; -} - -int main(int argc, char **argv) { - // This app has three threads. The main thread will run the XMPP client, - // which will print to the screen in its own thread. A second thread - // will get input from the console, parse it, and pass the appropriate - // message back to the XMPP client's thread. A third thread is used - // by MediaSessionClient as its worker thread. - - // define options - DEFINE_bool(a, false, "Turn on auto accept."); - DEFINE_bool(d, false, "Turn on debugging."); - DEFINE_bool(testserver, false, "Use test server"); - DEFINE_int(portallocator, 0, "Filter out unwanted connection types."); - DEFINE_string(filterhost, NULL, "Filter out the host from all candidates."); - DEFINE_string(pmuc, "groupchat.google.com", "The persistant muc domain."); - DEFINE_string(s, "talk.google.com", "The connection server to use."); - DEFINE_string(voiceinput, NULL, "RTP dump file for voice input."); - DEFINE_string(voiceoutput, NULL, "RTP dump file for voice output."); - DEFINE_string(videoinput, NULL, "RTP dump file for video input."); - DEFINE_string(videooutput, NULL, "RTP dump file for video output."); - DEFINE_bool(help, false, "Prints this message"); - - // parse options - FlagList::SetFlagsFromCommandLine(&argc, argv, true); - if (FLAG_help) { - FlagList::Print(NULL, false); - return 0; - } - - bool auto_accept = FLAG_a; - bool debug = FLAG_d; - bool test_server = FLAG_testserver; - int32 portallocator_flags = FLAG_portallocator; - std::string pmuc_domain = FLAG_pmuc; - std::string server = FLAG_s; - - // parse username and password, if present - buzz::Jid jid; - std::string username; - talk_base::InsecureCryptStringImpl pass; - if (argc > 1) { - username = argv[1]; - if (argc > 2) { - pass.password() = argv[2]; - } - } - - if (debug) - talk_base::LogMessage::LogToDebug(talk_base::LS_VERBOSE); - - if (username.empty()) { - std::cout << "JID: "; - std::cin >> username; - } - if (username.find('@') == std::string::npos) { - username.append("@localhost"); - } - jid = buzz::Jid(username); - if (!jid.IsValid() || jid.node() == "") { - printf("Invalid JID. JIDs should be in the form user@domain\n"); - return 1; - } - if (pass.password().empty() && !test_server) { - Console::SetEcho(false); - std::cout << "Password: "; - std::cin >> pass.password(); - Console::SetEcho(true); - std::cout << std::endl; - } - - buzz::XmppClientSettings xcs; - xcs.set_user(jid.node()); - xcs.set_resource("call"); - xcs.set_host(jid.domain()); - xcs.set_use_tls(!test_server); - - if (test_server) { - pass.password() = jid.node(); - xcs.set_allow_plain(true); - } - xcs.set_pass(talk_base::CryptString(pass)); - - std::string host; - int port; - - int colon = server.find(':'); - if (colon == -1) { - host = server; - port = DEFAULT_PORT; - } else { - host = server.substr(0, colon); - port = atoi(server.substr(colon + 1).c_str()); - } - - xcs.set_server(talk_base::SocketAddress(host, port)); - printf("Logging in to %s as %s\n", server.c_str(), jid.Str().c_str()); - - talk_base::InitializeSSL(); - - -#if WIN32 - // Need to pump messages on our main thread on Windows. - talk_base::Win32Thread w32_thread; - talk_base::ThreadManager::SetCurrent(&w32_thread); -#endif - talk_base::Thread* main_thread = talk_base::Thread::Current(); - - XmppPump pump; - CallClient *client = new CallClient(pump.client()); - - if (FLAG_voiceinput || FLAG_voiceoutput || - FLAG_videoinput || FLAG_videooutput) { - // If any dump file is specified, we use FileMediaEngine. - cricket::MediaEngine* engine = CreateFileMediaEngine(FLAG_voiceinput, - FLAG_voiceoutput, - FLAG_videoinput, - FLAG_videooutput); - // The engine will be released by the client later. - client->SetMediaEngine(engine); - } - - Console *console = new Console(main_thread, client); - client->SetConsole(console); - client->SetAutoAccept(auto_accept); - client->SetPmucDomain(pmuc_domain); - client->SetPortAllocatorFlags(portallocator_flags); - console->Start(); - - if (debug) { - pump.client()->SignalLogInput.connect(&debug_log_, &DebugLog::Input); - pump.client()->SignalLogOutput.connect(&debug_log_, &DebugLog::Output); - } - - pump.DoLogin(xcs, new XmppSocket(true), NULL); - main_thread->Run(); - pump.DoDisconnect(); - - console->Stop(); - delete console; - delete client; - - return 0; -} diff --git a/third_party/libjingle/source/talk/examples/call/callclient.cc b/third_party/libjingle/source/talk/examples/call/callclient.cc index 03edf95..eb761d1 100644 --- a/third_party/libjingle/source/talk/examples/call/callclient.cc +++ b/third_party/libjingle/source/talk/examples/call/callclient.cc @@ -35,6 +35,7 @@ #include "talk/base/network.h" #include "talk/base/socketaddress.h" #include "talk/base/stringutils.h" +#include "talk/base/stringencode.h" #include "talk/p2p/base/sessionmanager.h" #include "talk/p2p/client/basicportallocator.h" #include "talk/p2p/client/sessionmanagertask.h" @@ -82,6 +83,25 @@ const char* DescribeStatus(buzz::Status::Show show, const std::string& desc) { } } +std::string GetWord(const std::vector<std::string>& words, + size_t index, const std::string& def) { + if (words.size() > index) { + return words[index]; + } else { + return def; + } +} + +int GetInt(const std::vector<std::string>& words, size_t index, int def) { + int val; + if (words.size() > index && talk_base::FromString(words[index], &val)) { + return val; + } else { + return def; + } +} + + } // namespace const char* CALL_COMMANDS = @@ -97,7 +117,7 @@ const char* CALL_COMMANDS = const char* RECEIVE_COMMANDS = "Available commands:\n" "\n" -" accept Accepts the incoming call and switches to it.\n" +" accept [bw] Accepts the incoming call and switches to it.\n" " reject Rejects the incoming call and stays with the current call.\n" " quit Quits the application.\n" ""; @@ -107,10 +127,10 @@ const char* CONSOLE_COMMANDS = "\n" " roster Prints the online friends from your roster.\n" " friend user Request to add a user to your roster.\n" -" call [jid] Initiates a call to the user[/room] with the\n" -" given JID.\n" -" vcall [jid] Initiates a video call to the user[/room] with\n" -" the given JID.\n" +" call [jid] [bw] Initiates a call to the user[/room] with the\n" +" given JID and with optional bandwidth.\n" +" vcall [jid] [bw] Initiates a video call to the user[/room] with\n" +" the given JID and with optional bandwidth.\n" " voicemail [jid] Leave a voicemail for the user with the given JID.\n" " join [room] Joins a multi-user-chat.\n" " invite user [room] Invites a friend to a multi-user-chat.\n" @@ -142,53 +162,73 @@ void CallClient::ParseLine(const std::string& line) { } // Global commands - if ((words.size() == 1) && (words[0] == "quit")) { + const std::string& command = GetWord(words, 0, ""); + if (command == "quit") { Quit(); } else if (call_ && incoming_call_) { - if ((words.size() == 1) && (words[0] == "accept")) { - Accept(); - } else if ((words.size() == 1) && (words[0] == "reject")) { + if (command == "accept") { + cricket::CallOptions options; + options.video_bandwidth = GetInt(words, 1, cricket::kAutoBandwidth); + Accept(options); + } else if (command == "reject") { Reject(); } else { console_->Print(RECEIVE_COMMANDS); } } else if (call_) { - if ((words.size() == 1) && (words[0] == "hangup")) { + if (command == "hangup") { // TODO: do more shutdown here, move to Terminate() call_->Terminate(); call_ = NULL; session_ = NULL; console_->SetPrompt(NULL); - } else if ((words.size() == 1) && (words[0] == "mute")) { + } else if (command == "mute") { call_->Mute(true); - } else if ((words.size() == 1) && (words[0] == "unmute")) { + } else if (command == "unmute") { call_->Mute(false); - } else if ((words.size() == 2) && (words[0] == "dtmf")) { + } else if ((command == "dtmf") && (words.size() == 2)) { int ev = std::string("0123456789*#").find(words[1][0]); call_->PressDTMF(ev); } else { console_->Print(CALL_COMMANDS); } } else { - if ((words.size() == 1) && (words[0] == "roster")) { + if (command == "roster") { PrintRoster(); - } else if ((words.size() == 2) && (words[0] == "friend")) { + } else if (command == "send") { + buzz::Jid jid(words[1]); + if (jid.IsValid()) { + last_sent_to_ = words[1]; + SendChat(words[1], words[2]); + } else if (!last_sent_to_.empty()) { + SendChat(last_sent_to_, words[1]); + } else { + console_->Printf( + "Invalid JID. JIDs should be in the form user@domain\n"); + } + } else if ((words.size() == 2) && (command == "friend")) { InviteFriend(words[1]); - } else if ((words.size() >= 1) && (words[0] == "call")) { - MakeCallTo((words.size() >= 2) ? words[1] : "", false); - } else if ((words.size() >= 1) && (words[0] == "vcall")) { - MakeCallTo((words.size() >= 2) ? words[1] : "", true); - } else if ((words.size() >= 1) && (words[0] == "join")) { - JoinMuc((words.size() >= 2) ? words[1] : ""); - } else if ((words.size() >= 2) && (words[0] == "invite")) { - InviteToMuc(words[1], (words.size() >= 3) ? words[2] : ""); - } else if ((words.size() >= 1) && (words[0] == "leave")) { - LeaveMuc((words.size() >= 2) ? words[1] : ""); - } else if ((words.size() == 1) && (words[0] == "getdevs")) { + } else if (command == "call") { + std::string to = GetWord(words, 1, ""); + MakeCallTo(to, cricket::CallOptions()); + } else if (command == "vcall") { + std::string to = GetWord(words, 1, ""); + int bandwidth = GetInt(words, 2, cricket::kAutoBandwidth); + cricket::CallOptions options; + options.is_video = true; + options.video_bandwidth = bandwidth; + MakeCallTo(to, options); + } else if (command == "join") { + JoinMuc(GetWord(words, 1, "")); + } else if ((words.size() >= 2) && (command == "invite")) { + InviteToMuc(words[1], GetWord(words, 2, "")); + } else if (command == "leave") { + LeaveMuc(GetWord(words, 1, "")); + } else if (command == "getdevs") { GetDevices(); - } else if ((words.size() == 2) && (words[0] == "setvol")) { + } else if ((words.size() == 2) && (command == "setvol")) { SetVolume(words[1]); - } else if ((words.size() >= 1) && (words[0] == "voicemail")) { + } else if (command == "voicemail") { CallVoicemail((words.size() >= 2) ? words[1] : ""); } else { console_->Print(CONSOLE_COMMANDS); @@ -201,7 +241,8 @@ CallClient::CallClient(buzz::XmppClient* xmpp_client) call_(NULL), incoming_call_(false), auto_accept_(false), pmuc_domain_("groupchat.google.com"), local_renderer_(NULL), remote_renderer_(NULL), - roster_(new RosterMap), portallocator_flags_(0) + roster_(new RosterMap), portallocator_flags_(0), + allow_local_ips_(false), initial_protocol_(cricket::PROTOCOL_HYBRID) #ifdef USE_TALK_SOUND , sound_system_factory_(NULL) #endif @@ -309,6 +350,8 @@ void CallClient::InitPhone() { port_allocator_, worker_thread_); session_manager_->SignalRequestSignaling.connect( this, &CallClient::OnRequestSignaling); + session_manager_->SignalSessionCreate.connect( + this, &CallClient::OnSessionCreate); session_manager_->OnSignalingReady(); session_manager_task_ = @@ -348,6 +391,11 @@ void CallClient::OnRequestSignaling() { session_manager_->OnSignalingReady(); } +void CallClient::OnSessionCreate(cricket::Session* session, bool initiate) { + session->set_allow_local_ips(allow_local_ips_); + session->set_current_protocol(initial_protocol_); +} + void CallClient::OnCallCreate(cricket::Call* call) { call->SignalSessionState.connect(this, &CallClient::OnSessionState); if (call->video()) { @@ -365,8 +413,9 @@ void CallClient::OnSessionState(cricket::Call* call, call_ = call; session_ = session; incoming_call_ = true; + cricket::CallOptions options; if (auto_accept_) { - Accept(); + Accept(options); } } else if (state == cricket::Session::STATE_SENTINITIATE) { console_->Print("calling..."); @@ -458,6 +507,19 @@ void CallClient::PrintRoster() { console_->SetPrompting(true); } +void CallClient::SendChat(const std::string& to, const std::string msg) { + buzz::XmlElement* stanza = new buzz::XmlElement(buzz::QN_MESSAGE); + stanza->AddAttr(buzz::QN_TO, to); + stanza->AddAttr(buzz::QN_ID, talk_base::CreateRandomString(16)); + stanza->AddAttr(buzz::QN_TYPE, "chat"); + buzz::XmlElement* body = new buzz::XmlElement(buzz::QN_BODY); + body->SetBodyText(msg); + stanza->AddElement(body); + + xmpp_client_->SendStanza(stanza); + delete stanza; +} + void CallClient::InviteFriend(const std::string& name) { buzz::Jid jid(name); if (!jid.IsValid() || jid.node() == "") { @@ -473,16 +535,20 @@ void CallClient::InviteFriend(const std::string& name) { console_->Printf("Requesting to befriend %s.\n", name.c_str()); } -void CallClient::MakeCallTo(const std::string& name, bool video) { +void CallClient::MakeCallTo(const std::string& name, + const cricket::CallOptions& given_options) { + // Copy so we can change .is_muc. + cricket::CallOptions options = given_options; + bool found = false; - bool is_muc = false; + options.is_muc = false; buzz::Jid callto_jid(name); buzz::Jid found_jid; if (name.length() == 0 && mucs_.size() > 0) { // if no name, and in a MUC, establish audio with the MUC found_jid = mucs_.begin()->first; found = true; - is_muc = true; + options.is_muc = true; } else if (name[0] == '+') { // if the first character is a +, assume it's a phone number found_jid = callto_jid; @@ -507,28 +573,29 @@ void CallClient::MakeCallTo(const std::string& name, bool video) { mucs_[callto_jid]->state() == buzz::Muc::MUC_JOINED) { found = true; found_jid = callto_jid; - is_muc = true; + options.is_muc = true; } } } if (found) { - console_->Printf("Found %s '%s'", is_muc ? "room" : "online friend", + console_->Printf("Found %s '%s'", options.is_muc ? "room" : "online friend", found_jid.Str().c_str()); - PlaceCall(found_jid, is_muc, video); + PlaceCall(found_jid, options); } else { console_->Printf("Could not find online friend '%s'", name.c_str()); } } -void CallClient::PlaceCall(const buzz::Jid& jid, bool is_muc, bool video) { +void CallClient::PlaceCall(const buzz::Jid& jid, + const cricket::CallOptions& options) { media_client_->SignalCallDestroy.connect( this, &CallClient::OnCallDestroy); if (!call_) { - call_ = media_client_->CreateCall(video, is_muc); + call_ = media_client_->CreateCall(); console_->SetPrompt(jid.Str().c_str()); - session_ = call_->InitiateSession(jid); - if (is_muc) { + session_ = call_->InitiateSession(jid, options); + if (options.is_muc) { // If people in this room are already in a call, must add all their // streams. buzz::Muc::MemberMap& members = mucs_[jid]->members(); @@ -566,7 +633,7 @@ void CallClient::CallVoicemail(const std::string& name) { void CallClient::OnFoundVoicemailJid(const buzz::Jid& to, const buzz::Jid& voicemail) { console_->Printf("Calling %s's voicemail.\n", to.Str().c_str()); - PlaceCall(voicemail, false, false); + PlaceCall(voicemail, cricket::CallOptions()); } void CallClient::OnVoicemailJidError(const buzz::Jid& to) { @@ -587,10 +654,10 @@ void CallClient::RemoveStream(uint32 audio_src_id, uint32 video_src_id) { } } -void CallClient::Accept() { +void CallClient::Accept(const cricket::CallOptions& options) { ASSERT(call_ && incoming_call_); ASSERT(call_->sessions().size() == 1); - call_->AcceptSession(call_->sessions()[0]); + call_->AcceptSession(call_->sessions()[0], options); media_client_->SetFocus(call_); if (call_->video()) { call_->SetLocalRenderer(local_renderer_); diff --git a/third_party/libjingle/source/talk/examples/call/callclient.h b/third_party/libjingle/source/talk/examples/call/callclient.h index af27f34..a5686b4 100644 --- a/third_party/libjingle/source/talk/examples/call/callclient.h +++ b/third_party/libjingle/source/talk/examples/call/callclient.h @@ -66,7 +66,9 @@ class MediaEngine; class MediaSessionClient; class Receiver; class Call; +struct CallOptions; class SessionManagerTask; +enum SignalingProtocol; } struct RosterItem { @@ -98,11 +100,20 @@ class CallClient: public sigslot::has_slots<> { void ParseLine(const std::string &str); + void SendChat(const std::string& to, const std::string msg); void InviteFriend(const std::string& user); void JoinMuc(const std::string& room); void InviteToMuc(const std::string& user, const std::string& room); void LeaveMuc(const std::string& room); void SetPortAllocatorFlags(uint32 flags) { portallocator_flags_ = flags; } + void SetAllowLocalIps(bool allow_local_ips) { + allow_local_ips_ = allow_local_ips; + } + + void SetInitialProtocol(cricket::SignalingProtocol initial_protocol) { + initial_protocol_ = initial_protocol; + } + typedef std::map<buzz::Jid, buzz::Muc*> MucMap; @@ -119,6 +130,7 @@ class CallClient: public sigslot::has_slots<> { void InitPresence(); void RefreshStatus(); void OnRequestSignaling(); + void OnSessionCreate(cricket::Session* session, bool initiate); void OnCallCreate(cricket::Call* call); void OnCallDestroy(cricket::Call* call); void OnSessionState(cricket::Call* call, @@ -137,10 +149,10 @@ class CallClient: public sigslot::has_slots<> { static const std::string strerror(buzz::XmppEngine::Error err); void PrintRoster(); - void MakeCallTo(const std::string& name, bool video); - void PlaceCall(const buzz::Jid& jid, bool is_muc, bool video); + void MakeCallTo(const std::string& name, const cricket::CallOptions& options); + void PlaceCall(const buzz::Jid& jid, const cricket::CallOptions& options); void CallVoicemail(const std::string& name); - void Accept(); + void Accept(const cricket::CallOptions& options); void Reject(); void Quit(); @@ -178,6 +190,10 @@ class CallClient: public sigslot::has_slots<> { buzz::FriendInviteSendTask* friend_invite_send_; RosterMap* roster_; uint32 portallocator_flags_; + + bool allow_local_ips_; + cricket::SignalingProtocol initial_protocol_; + std::string last_sent_to_; #ifdef USE_TALK_SOUND cricket::SoundSystemFactory* sound_system_factory_; #endif |