Home | History | Annotate | Download | only in call
      1 /*
      2  * libjingle
      3  * Copyright 2004--2005, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef TALK_EXAMPLES_CALL_CALLCLIENT_H_
     29 #define TALK_EXAMPLES_CALL_CALLCLIENT_H_
     30 
     31 #include <map>
     32 #include <string>
     33 #include <vector>
     34 
     35 #include "talk/p2p/base/session.h"
     36 #include "talk/session/phone/mediachannel.h"
     37 #include "talk/session/phone/mediasessionclient.h"
     38 #include "talk/xmpp/xmppclient.h"
     39 #include "talk/examples/call/status.h"
     40 #include "talk/examples/call/console.h"
     41 
     42 namespace buzz {
     43 class PresencePushTask;
     44 class PresenceOutTask;
     45 class MucInviteRecvTask;
     46 class MucInviteSendTask;
     47 class FriendInviteSendTask;
     48 class VoicemailJidRequester;
     49 class DiscoInfoQueryTask;
     50 class Muc;
     51 class Status;
     52 class MucStatus;
     53 struct AvailableMediaEntry;
     54 }
     55 
     56 namespace talk_base {
     57 class Thread;
     58 class NetworkManager;
     59 }
     60 
     61 namespace cricket {
     62 class PortAllocator;
     63 class MediaEngine;
     64 class MediaSessionClient;
     65 class Receiver;
     66 class Call;
     67 struct CallOptions;
     68 class SessionManagerTask;
     69 }
     70 
     71 struct RosterItem {
     72   buzz::Jid jid;
     73   buzz::Status::Show show;
     74   std::string status;
     75 };
     76 
     77 class NullRenderer;
     78 
     79 class CallClient: public sigslot::has_slots<> {
     80  public:
     81   explicit CallClient(buzz::XmppClient* xmpp_client);
     82   ~CallClient();
     83 
     84   cricket::MediaSessionClient* media_client() const { return media_client_; }
     85   void SetMediaEngine(cricket::MediaEngine* media_engine) {
     86     media_engine_ = media_engine;
     87   }
     88   void SetAutoAccept(bool auto_accept) {
     89     auto_accept_ = auto_accept;
     90   }
     91   void SetPmucDomain(const std::string &pmuc_domain) {
     92     pmuc_domain_ = pmuc_domain;
     93   }
     94   void SetConsole(Console *console) {
     95     console_ = console;
     96   }
     97 
     98   void ParseLine(const std::string &str);
     99 
    100   void SendChat(const std::string& to, const std::string msg);
    101   void InviteFriend(const std::string& user);
    102   void JoinMuc(const std::string& room);
    103   void InviteToMuc(const std::string& user, const std::string& room);
    104   void LeaveMuc(const std::string& room);
    105   void SetPortAllocatorFlags(uint32 flags) { portallocator_flags_ = flags; }
    106   void SetAllowLocalIps(bool allow_local_ips) {
    107     allow_local_ips_ = allow_local_ips;
    108   }
    109 
    110   void SetInitialProtocol(cricket::SignalingProtocol initial_protocol) {
    111     initial_protocol_ = initial_protocol;
    112   }
    113 
    114   void SetSecurePolicy(cricket::SecureMediaPolicy secure_policy) {
    115     secure_policy_ = secure_policy;
    116   }
    117 
    118 
    119   typedef std::map<buzz::Jid, buzz::Muc*> MucMap;
    120 
    121   const MucMap& mucs() const {
    122     return mucs_;
    123   }
    124 
    125  private:
    126   void AddStream(uint32 audio_src_id, uint32 video_src_id);
    127   void RemoveStream(uint32 audio_src_id, uint32 video_src_id);
    128   void OnStateChange(buzz::XmppEngine::State state);
    129 
    130   void InitPhone();
    131   void InitPresence();
    132   void RefreshStatus();
    133   void OnRequestSignaling();
    134   void OnSessionCreate(cricket::Session* session, bool initiate);
    135   void OnCallCreate(cricket::Call* call);
    136   void OnCallDestroy(cricket::Call* call);
    137   void OnSessionState(cricket::Call* call,
    138                       cricket::BaseSession* session,
    139                       cricket::BaseSession::State state);
    140   void OnStatusUpdate(const buzz::Status& status);
    141   void OnMucInviteReceived(const buzz::Jid& inviter, const buzz::Jid& room,
    142       const std::vector<buzz::AvailableMediaEntry>& avail);
    143   void OnMucJoined(const buzz::Jid& endpoint);
    144   void OnMucStatusUpdate(const buzz::Jid& jid, const buzz::MucStatus& status);
    145   void OnMucLeft(const buzz::Jid& endpoint, int error);
    146   void OnDevicesChange();
    147   void OnFoundVoicemailJid(const buzz::Jid& to, const buzz::Jid& voicemail);
    148   void OnVoicemailJidError(const buzz::Jid& to);
    149 
    150   static const std::string strerror(buzz::XmppEngine::Error err);
    151 
    152   void PrintRoster();
    153   void MakeCallTo(const std::string& name, const cricket::CallOptions& options);
    154   void PlaceCall(const buzz::Jid& jid, const cricket::CallOptions& options);
    155   void CallVoicemail(const std::string& name);
    156   void Accept(const cricket::CallOptions& options);
    157   void Reject();
    158   void Quit();
    159 
    160   void GetDevices();
    161   void PrintDevices(const std::vector<std::string>& names);
    162 
    163   void SetVolume(const std::string& level);
    164 
    165   typedef std::map<std::string, RosterItem> RosterMap;
    166 
    167   Console *console_;
    168   buzz::XmppClient* xmpp_client_;
    169   talk_base::Thread* worker_thread_;
    170   talk_base::NetworkManager* network_manager_;
    171   talk_base::PacketSocketFactory* socket_factory_;
    172   cricket::PortAllocator* port_allocator_;
    173   cricket::SessionManager* session_manager_;
    174   cricket::SessionManagerTask* session_manager_task_;
    175   cricket::MediaEngine* media_engine_;
    176   cricket::MediaSessionClient* media_client_;
    177   MucMap mucs_;
    178 
    179   cricket::Call* call_;
    180   cricket::BaseSession *session_;
    181   bool incoming_call_;
    182   bool auto_accept_;
    183   std::string pmuc_domain_;
    184   NullRenderer* local_renderer_;
    185   NullRenderer* remote_renderer_;
    186 
    187   buzz::Status my_status_;
    188   buzz::PresencePushTask* presence_push_;
    189   buzz::PresenceOutTask* presence_out_;
    190   buzz::MucInviteRecvTask* muc_invite_recv_;
    191   buzz::MucInviteSendTask* muc_invite_send_;
    192   buzz::FriendInviteSendTask* friend_invite_send_;
    193   RosterMap* roster_;
    194   uint32 portallocator_flags_;
    195 
    196   bool allow_local_ips_;
    197   cricket::SignalingProtocol initial_protocol_;
    198   cricket::SecureMediaPolicy secure_policy_;
    199   std::string last_sent_to_;
    200 };
    201 
    202 #endif  // TALK_EXAMPLES_CALL_CALLCLIENT_H_
    203