Home | History | Annotate | Download | only in xmpp
      1 /*
      2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_
     12 #define WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_
     13 
     14 #include "webrtc/libjingle/xmpp/module.h"
     15 #include "webrtc/libjingle/xmpp/rostermodule.h"
     16 
     17 namespace buzz {
     18 
     19 // forward declarations
     20 class XmppChatroomModule;
     21 class XmppChatroomHandler;
     22 class XmppChatroomMember;
     23 class XmppChatroomMemberEnumerator;
     24 
     25 enum XmppChatroomState {
     26   XMPP_CHATROOM_STATE_NOT_IN_ROOM      = 0,
     27   XMPP_CHATROOM_STATE_REQUESTED_ENTER  = 1,
     28   XMPP_CHATROOM_STATE_IN_ROOM          = 2,
     29   XMPP_CHATROOM_STATE_REQUESTED_EXIT   = 3,
     30 };
     31 
     32 //! Module that encapsulates a chatroom.
     33 class XmppChatroomModule : public XmppModule {
     34 public:
     35 
     36   //! Creates a new XmppChatroomModule
     37   static XmppChatroomModule* Create();
     38   virtual ~XmppChatroomModule() {}
     39 
     40   //! Sets the chatroom handler (callbacks) for the chatroom
     41   virtual XmppReturnStatus set_chatroom_handler(XmppChatroomHandler* handler) = 0;
     42 
     43   //! Gets the chatroom handler for the module
     44   virtual XmppChatroomHandler* chatroom_handler() = 0;
     45 
     46   //! Sets the jid of the chatroom.
     47   //! Has to be set before entering the chatroom and can't be changed
     48   //! while in the chatroom
     49   virtual XmppReturnStatus set_chatroom_jid(const Jid& chatroom_jid) = 0;
     50 
     51   //! The jid for the chatroom
     52   virtual const Jid& chatroom_jid() const = 0;
     53 
     54   //! Sets the nickname of the member
     55   //! Has to be set before entering the chatroom and can't be changed
     56   //! while in the chatroom
     57   virtual XmppReturnStatus set_nickname(const std::string& nickname) = 0;
     58 
     59   //! The nickname of the member in the chatroom
     60   virtual const std::string& nickname() const = 0;
     61 
     62   //! Returns the jid of the member (this is the chatroom_jid plus the
     63   //! nickname as the resource name)
     64   virtual const Jid member_jid() const = 0;
     65 
     66   //! Requests that the user enter a chatroom
     67   //! The EnterChatroom callback will be called when the request is complete.
     68   //! Password should be empty for a room that doesn't require a password
     69   //! If the room doesn't exist, the server will create an "Instant Room" if the
     70   //! server policy supports this action.
     71   //! There will be different methods for creating/configuring a "Reserved Room"
     72   //! Async callback for this method is ChatroomEnteredStatus
     73   virtual XmppReturnStatus RequestEnterChatroom(const std::string& password,
     74       const std::string& client_version,
     75       const std::string& locale) = 0;
     76 
     77   //! Requests that the user exit a chatroom
     78   //! Async callback for this method is ChatroomExitedStatus
     79   virtual XmppReturnStatus RequestExitChatroom() = 0;
     80 
     81   //! Requests a status change
     82   //! status is the standard XMPP status code
     83   //! extended_status is the extended status when status is XMPP_PRESENCE_XA
     84   virtual XmppReturnStatus RequestConnectionStatusChange(
     85       XmppPresenceConnectionStatus connection_status) = 0;
     86 
     87   //! Returns the number of members in the room
     88   virtual size_t GetChatroomMemberCount() = 0;
     89 
     90   //! Gets an enumerator for the members in the chatroom
     91   //! The caller must delete the enumerator when the caller is finished with it.
     92   //! The caller must also ensure that the lifetime of the enumerator is
     93   //! scoped by the XmppChatRoomModule that created it.
     94   virtual XmppReturnStatus CreateMemberEnumerator(XmppChatroomMemberEnumerator** enumerator) = 0;
     95 
     96   //! Gets the subject of the chatroom
     97   virtual const std::string subject() = 0;
     98 
     99   //! Returns the current state of the user with respect to the chatroom
    100   virtual XmppChatroomState state() = 0;
    101 
    102   virtual XmppReturnStatus SendMessage(const XmlElement& message) = 0;
    103 };
    104 
    105 //! Class for enumerating participatns
    106 class XmppChatroomMemberEnumerator {
    107 public:
    108   virtual ~XmppChatroomMemberEnumerator() { }
    109   //! Returns the member at the current position
    110   //! Returns null if the enumerator is before the beginning
    111   //! or after the end of the collection
    112   virtual XmppChatroomMember* current() = 0;
    113 
    114   //! Returns whether the enumerator is valid
    115   //! This returns true if the collection has changed
    116   //! since the enumerator was created
    117   virtual bool IsValid() = 0;
    118 
    119   //! Returns whether the enumerator is before the beginning
    120   //! This is the initial state of the enumerator
    121   virtual bool IsBeforeBeginning() = 0;
    122 
    123   //! Returns whether the enumerator is after the end
    124   virtual bool IsAfterEnd() = 0;
    125 
    126   //! Advances the enumerator to the next position
    127   //! Returns false is the enumerator is advanced
    128   //! off the end of the collection
    129   virtual bool Next() = 0;
    130 
    131   //! Advances the enumerator to the previous position
    132   //! Returns false is the enumerator is advanced
    133   //! off the end of the collection
    134   virtual bool Prev() = 0;
    135 };
    136 
    137 
    138 //! Represents a single member in a chatroom
    139 class XmppChatroomMember {
    140 public:
    141   virtual ~XmppChatroomMember() { }
    142 
    143   //! The jid for the member in the chatroom
    144   virtual const Jid member_jid() const = 0;
    145 
    146   //! The full jid for the member
    147   //! This is only available in non-anonymous rooms.
    148   //! If the room is anonymous, this returns JID_EMPTY
    149   virtual const Jid full_jid() const = 0;
    150 
    151    //! Returns the backing presence for this member
    152   virtual const XmppPresence* presence() const = 0;
    153 
    154   //! The nickname for this member
    155   virtual const std::string name() const = 0;
    156 };
    157 
    158 //! Status codes for ChatroomEnteredStatus callback
    159 enum XmppChatroomEnteredStatus
    160 {
    161   //! User successfully entered the room
    162   XMPP_CHATROOM_ENTERED_SUCCESS                    = 0,
    163   //! The nickname confliced with somebody already in the room
    164   XMPP_CHATROOM_ENTERED_FAILURE_NICKNAME_CONFLICT  = 1,
    165   //! A password is required to enter the room
    166   XMPP_CHATROOM_ENTERED_FAILURE_PASSWORD_REQUIRED  = 2,
    167   //! The specified password was incorrect
    168   XMPP_CHATROOM_ENTERED_FAILURE_PASSWORD_INCORRECT = 3,
    169   //! The user is not a member of a member-only room
    170   XMPP_CHATROOM_ENTERED_FAILURE_NOT_A_MEMBER       = 4,
    171   //! The user cannot enter because the user has been banned
    172   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BANNED      = 5,
    173   //! The room has the maximum number of users already
    174   XMPP_CHATROOM_ENTERED_FAILURE_MAX_USERS          = 6,
    175   //! The room has been locked by an administrator
    176   XMPP_CHATROOM_ENTERED_FAILURE_ROOM_LOCKED        = 7,
    177   //! Someone in the room has blocked you
    178   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BLOCKED     = 8,
    179   //! You have blocked someone in the room
    180   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BLOCKING    = 9,
    181   //! Client is old. User must upgrade to a more recent version for
    182   // hangouts to work.
    183   XMPP_CHATROOM_ENTERED_FAILURE_OUTDATED_CLIENT    = 10,
    184   //! Some other reason
    185   XMPP_CHATROOM_ENTERED_FAILURE_UNSPECIFIED        = 2000,
    186 };
    187 
    188 //! Status codes for ChatroomExitedStatus callback
    189 enum XmppChatroomExitedStatus
    190 {
    191   //! The user requested to exit and did so
    192   XMPP_CHATROOM_EXITED_REQUESTED                   = 0,
    193   //! The user was banned from the room
    194   XMPP_CHATROOM_EXITED_BANNED                      = 1,
    195   //! The user has been kicked out of the room
    196   XMPP_CHATROOM_EXITED_KICKED                      = 2,
    197   //! The user has been removed from the room because the
    198   //! user is no longer a member of a member-only room
    199   //! or the room has changed to membership-only
    200   XMPP_CHATROOM_EXITED_NOT_A_MEMBER                = 3,
    201   //! The system is shutting down
    202   XMPP_CHATROOM_EXITED_SYSTEM_SHUTDOWN             = 4,
    203   //! For some other reason
    204   XMPP_CHATROOM_EXITED_UNSPECIFIED                 = 5,
    205 };
    206 
    207 //! The XmppChatroomHandler is the interface for callbacks from the
    208 //! the chatroom
    209 class XmppChatroomHandler {
    210 public:
    211   virtual ~XmppChatroomHandler() {}
    212 
    213   //! Indicates the response to RequestEnterChatroom method
    214   //! XMPP_CHATROOM_SUCCESS represents success.
    215   //! Other status codes are for errors
    216   virtual void ChatroomEnteredStatus(XmppChatroomModule* room,
    217                                      const XmppPresence* presence,
    218                                      XmppChatroomEnteredStatus status) = 0;
    219 
    220 
    221   //! Indicates that the user has exited the chatroom, either due to
    222   //! a call to RequestExitChatroom or for some other reason.
    223   //! status indicates the reason the user exited
    224   virtual void ChatroomExitedStatus(XmppChatroomModule* room,
    225                                     XmppChatroomExitedStatus status) = 0;
    226 
    227   //! Indicates a member entered the room.
    228   //! It can be called before ChatroomEnteredStatus.
    229   virtual void MemberEntered(XmppChatroomModule* room,
    230                                   const XmppChatroomMember* entered_member) = 0;
    231 
    232   //! Indicates that a member exited the room.
    233   virtual void MemberExited(XmppChatroomModule* room,
    234                               const XmppChatroomMember* exited_member) = 0;
    235 
    236   //! Indicates that the data for the member has changed
    237   //! (such as the nickname or presence)
    238   virtual void MemberChanged(XmppChatroomModule* room,
    239                              const XmppChatroomMember* changed_member) = 0;
    240 
    241   //! Indicates a new message has been received
    242   //! message is the message -
    243   // $TODO - message should be changed
    244   //! to a strongly-typed message class that contains info
    245   //! such as the sender, message bodies, etc.,
    246   virtual void MessageReceived(XmppChatroomModule* room,
    247                                const XmlElement& message) = 0;
    248 };
    249 
    250 
    251 }
    252 
    253 #endif  // WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_
    254