Agora Java API Reference for Android
IAgoraRtmService.h
1 //
2 // Agora Rtm SDK
3 //
4 // Created by junhao Wang in 2018-05.
5 // Copyright (c) 2018 Agora IO. All rights reserved.
6 //
7 #pragma once
8 #include <cstdint>
9 
10 namespace agora {
11 
12 namespace rtm {
13 
14 enum PEER_MESSAGE_STATE {
15  PEER_MESSAGE_INIT = 0,
16  PEER_MESSAGE_FAILURE = 1,
17  PEER_MESSAGE_PEER_UNREACHABLE = 2,
18  PEER_MESSAGE_RECEIVED_BY_PEER = 3,
19  PEER_MESSAGE_SENT_TIMEOUT = 4,
20 };
24 enum LOGIN_ERR_CODE {
28  LOGIN_ERR_OK = 0,
32  LOGIN_ERR_UNKNOWN = 1,
37  LOGIN_ERR_REJECTED = 2, // ALREADY LOGIN OR NOT INITIALIZED, SERVER REJECT
41  LOGIN_ERR_INVALID_ARGUMENT = 3,
45  LOGIN_ERR_INVALID_APP_ID = 4,
49  LOGIN_ERR_INVALID_TOKEN = 5,
53  LOGIN_ERR_TOKEN_EXPIRED = 6,
57  LOGIN_ERR_NOT_AUTHORIZED = 7,
61  LOGIN_ERR_TIMEOUT = 8,
62 };
66 enum LOGOUT_ERR_CODE {
70  LOGOUT_ERR_OK = 0,
74  LOGOUT_ERR_REJECTED = 1,
75 };
79 enum CONNECTION_STATE {
83  CONNECTION_STATE_CONNECTED = 1,
87  CONNECTION_STATE_DISCONNECTED = 2,
94  CONNECTION_STATE_ABORTED = 3,
95 };
96 
100 enum CHANNEL_MESSAGE_STATE {
104  CHANNEL_MESSAGE_RECEIVED_BY_SERVER = 1,
109  CHANNEL_MESSAGE_SENT_TIMEOUT = 3,
110 };
114 enum JOIN_CHANNEL_ERR {
118  JOIN_CHANNEL_ERR_OK = 0,
119 
123  JOIN_CHANNEL_ERR_FAILURE = 1,
124 
128  JOIN_CHANNEL_ERR_REJECTED = 2, // Usually occurs when the user is already in the channel
129 
133  JOIN_CHANNEL_ERR_INVALID_ARGUMENT = 3,
134 
138  JOIN_CHANNEL_TIMEOUT = 4,
139 
143  JOIN_CHANNEL_ERR_EXCEED_LIMIT = 5,
144 
148  JOIN_CHANNEL_ERR_ALREADY_JOINED = 6,
149 
153  JOIN_CHANNEL_ERR_TOO_OFTEN = 7,
154 
158  JOIN_CHANNEL_ERR_JOIN_SAME_CHANNEL_TOO_OFTEN = 8,
159 
163  JOIN_CHANNEL_ERR_NOT_INITIALIZED = 101,
164 
168  JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
169 };
173 enum LEAVE_CHANNEL_ERR {
174 
178  LEAVE_CHANNEL_ERR_OK = 0,
179 
183  LEAVE_CHANNEL_ERR_FAILURE = 1,
184 
188  LEAVE_CHANNEL_ERR_REJECTED = 2,
189 
193  LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL = 3,
194 
198  LEAVE_CHANNEL_ERR_NOT_INITIALIZED = 101,
199 
203  LEAVE_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
204 };
205 
209 enum LEAVE_CHANNEL_REASON {
213  LEAVE_CHANNEL_REASON_QUIT = 1,
217  LEAVE_CHANNEL_REASON_KICKED = 2,
218 };
222 enum CHANNEL_MESSAGE_ERR_CODE {
223 
227  CHANNEL_MESSAGE_ERR_OK = 0,
228 
232  CHANNEL_MESSAGE_ERR_FAILURE = 1,
233 
237  CHANNEL_MESSAGE_ERR_SENT_TIMEOUT = 2,
238 
242  CHANNEL_MESSAGE_ERR_TOO_OFTEN = 3,
243 
247  CHANNEL_MESSAGE_ERR_INVALID_MESSAGE = 4,
248 
252  CHANNEL_MESSAGE_ERR_NOT_INITIALIZED = 101,
253 
257  CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN = 102,
258 };
259 
263 enum RESPONSE_CODE {
267  RESPONSE_CODE_SUCCESS = 1,
268  RESPONSE_CODE_FAILURE = 2,
269 };
273 enum MESSAGE_TYPE {
277  MESSAGE_TYPE_UNDEFINED = 0,
281  MESSAGE_TYPE_TEXT = 1,
285  MESSAGE_TYPE_BINARY = 2,
289  MESSAGE_TYPE_CONVERGE = 4,
290 };
294 class IMessage {
295  public:
306  virtual ~IMessage() {}
311  virtual int64_t getMessageId() const = 0;
318  virtual int getMessageType() const = 0;
324  virtual void setText(const char *str) = 0;
330  virtual const char *getText() const = 0;
336  virtual const unsigned char *getRawMessageData() const = 0;
342  virtual int getRawMessageLength() const = 0;
346  virtual void setMessageType(int32_t type) = 0;
350  virtual void setRawMessage(const uint8_t* data, int length) = 0;
354  virtual void release() = 0;
355 };
356 
361  public:
362  virtual ~IChannelMember() {}
367  virtual const char *getMemberId() const = 0;
372  virtual const char *getChannelId() const = 0;
376  virtual void release() = 0;
377 };
382  public:
398  virtual int addAttribute(const char *key, const char *value) = 0;
406  virtual int removeAttribute(const char *key) = 0;
413  virtual int getAttributesSize() const = 0;
420  virtual void getAttributes(int size, char **key,
421  char **value) const = 0; // todo: discussion, how to traveral
426  virtual const char *getAttributeValue(const char *key) const = 0;
433  virtual int release() = 0;
434 };
439  public:
440  virtual ~IChannelEventHandler() {}
444  virtual void onJoinSuccess() {}
449  virtual void onJoinFailure(JOIN_CHANNEL_ERR errorCode) {}
454  virtual void onLeave(LEAVE_CHANNEL_ERR errorCode) {}
459  virtual void onMessageReceived(const char *userId, const IMessage *message) {}
465  virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state) {}
472  virtual void onSendMessageResult(long long messageId, CHANNEL_MESSAGE_ERR_CODE state) {}
477  virtual void onMemberJoined(IChannelMember *member) {}
482  virtual void onMemberLeft(IChannelMember *member) {}
488  virtual void onMembersGotten(IChannelMember **members, int userCount) {}
493  virtual void onAttributesUpdated(const IChannelAttributes *attributes) {}
499  virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
504  virtual void onAttributesDeleted(const IChannelAttributes *attributes) {}
510  virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
511 };
515 class IChannel {
516  public:
521  virtual void setEventHandler(IChannelEventHandler *eventHandler) = 0;
531  virtual int join() = 0;
540  virtual int leave() = 0;
551  virtual int sendMessage(const IMessage *message) = 0;
562  virtual int updateAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
573  virtual int deleteAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
580  virtual const char *getId() const = 0;
581 
582  // sync_call
592  virtual int release() = 0;
593 };
598  public:
599  virtual ~IRtmServiceEventHandler() {}
600 
604  virtual void onLoginSuccess() {}
609  virtual void onLoginFailure(LOGIN_ERR_CODE errorCode) {}
613  virtual void onLogout() {}
618  virtual void onConnectionStateChanged(CONNECTION_STATE state) {}
624  virtual void onSendMessageState(int64_t messageId, PEER_MESSAGE_STATE state) {}
630  virtual void onMessageReceivedFromPeer(const char *peerId, const IMessage *message) {}
631 };
635 class IRtmService {
636  public:
637  virtual ~IRtmService() {}
647  virtual int initialize(const char *appId, IRtmServiceEventHandler *eventHandler) = 0;
652  virtual void unregisterObserver(IRtmServiceEventHandler *eventHandler) = 0;
663  virtual int release(bool sync = false) = 0;
676  virtual int login(const char *token, const char *userId) = 0;
683  virtual int logout() = 0;
693  virtual int sendMessageToPeer(const char *peerId, const IMessage *message) = 0;
710  virtual IChannel *createChannel(const char *channelId, IChannelEventHandler *eventHandler) = 0;
711 };
712 
713 } // namespace rtm
714 } // namespace agora
agora::rtm::IChannel::setEventHandler
virtual void setEventHandler(IChannelEventHandler *eventHandler)=0
agora::rtm::IMessage::createMessage
static IMessage * createMessage()
agora::rtm::IMessage::getMessageType
virtual int getMessageType() const =0
agora::rtm::IRtmService::login
virtual int login(const char *token, const char *userId)=0
agora::rtm::IMessage::setRawMessage
virtual void setRawMessage(const uint8_t *data, int length)=0
agora::rtm::IChannelAttributes::removeAttribute
virtual int removeAttribute(const char *key)=0
agora::rtm::IRtmServiceEventHandler::onSendMessageState
virtual void onSendMessageState(int64_t messageId, PEER_MESSAGE_STATE state)
Definition: IAgoraRtmService.h:624
agora::rtm::IChannelEventHandler::onDeleteAttributesResponse
virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:510
agora::rtm::IMessage::getText
virtual const char * getText() const =0
agora::rtm::IChannelEventHandler::onSendMessageResult
virtual void onSendMessageResult(long long messageId, CHANNEL_MESSAGE_ERR_CODE state)
Definition: IAgoraRtmService.h:472
agora::rtm::IChannelMember::getChannelId
virtual const char * getChannelId() const =0
agora::rtm::IRtmService::release
virtual int release(bool sync=false)=0
agora::rtm::IRtmService::createChannel
virtual IChannel * createChannel(const char *channelId, IChannelEventHandler *eventHandler)=0
agora::rtm::IChannelEventHandler::onJoinFailure
virtual void onJoinFailure(JOIN_CHANNEL_ERR errorCode)
Definition: IAgoraRtmService.h:449
agora::rtm::IRtmService
Definition: IAgoraRtmService.h:635
agora::rtm::IMessage
Definition: IAgoraRtmService.h:294
agora::rtm::IChannel::join
virtual int join()=0
agora::rtm::IChannelAttributes::getAttributes
virtual void getAttributes(int size, char **key, char **value) const =0
agora::rtm::IChannel::sendMessage
virtual int sendMessage(const IMessage *message)=0
agora::rtm::IMessage::setMessageType
virtual void setMessageType(int32_t type)=0
agora::rtm::IRtmServiceEventHandler::onMessageReceivedFromPeer
virtual void onMessageReceivedFromPeer(const char *peerId, const IMessage *message)
Definition: IAgoraRtmService.h:630
agora::rtm::IChannel::updateAttributes
virtual int updateAttributes(IChannelAttributes *attributes, int64_t &requestId)=0
agora::rtm::IChannelAttributes::getAttributesSize
virtual int getAttributesSize() const =0
agora::rtm::IChannelMember::release
virtual void release()=0
agora::rtm::IChannelEventHandler::onMemberLeft
virtual void onMemberLeft(IChannelMember *member)
Definition: IAgoraRtmService.h:482
agora::rtm::IChannelAttributes
Definition: IAgoraRtmService.h:381
agora::rtm::IChannelAttributes::release
virtual int release()=0
agora::rtm::IChannel::leave
virtual int leave()=0
agora::rtm::IRtmServiceEventHandler::onLoginSuccess
virtual void onLoginSuccess()
Definition: IAgoraRtmService.h:604
agora::rtm::IRtmServiceEventHandler::onLoginFailure
virtual void onLoginFailure(LOGIN_ERR_CODE errorCode)
Definition: IAgoraRtmService.h:609
agora::rtm::IChannel
Definition: IAgoraRtmService.h:515
agora::rtm::IChannel::getId
virtual const char * getId() const =0
agora::rtm::IRtmService::unregisterObserver
virtual void unregisterObserver(IRtmServiceEventHandler *eventHandler)=0
agora::rtm::IChannelMember
Definition: IAgoraRtmService.h:360
agora::rtm::IMessage::setText
virtual void setText(const char *str)=0
agora::rtm::IChannelEventHandler::onLeave
virtual void onLeave(LEAVE_CHANNEL_ERR errorCode)
Definition: IAgoraRtmService.h:454
agora::rtm::IRtmService::initialize
virtual int initialize(const char *appId, IRtmServiceEventHandler *eventHandler)=0
agora::rtm::IChannel::release
virtual int release()=0
agora::rtm::IChannelEventHandler::onMemberJoined
virtual void onMemberJoined(IChannelMember *member)
Definition: IAgoraRtmService.h:477
agora::rtm::IMessage::getRawMessageLength
virtual int getRawMessageLength() const =0
agora::rtm::IMessage::getMessageId
virtual int64_t getMessageId() const =0
agora::rtm::IChannelEventHandler::onMessageReceived
virtual void onMessageReceived(const char *userId, const IMessage *message)
Definition: IAgoraRtmService.h:459
agora::rtm::IChannelEventHandler::onAttributesUpdated
virtual void onAttributesUpdated(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:493
agora::rtm::IChannelEventHandler::onJoinSuccess
virtual void onJoinSuccess()
Definition: IAgoraRtmService.h:444
agora::rtm::IChannelMember::getMemberId
virtual const char * getMemberId() const =0
agora::rtm::IChannelAttributes::addAttribute
virtual int addAttribute(const char *key, const char *value)=0
agora::rtm::IChannelAttributes::getAttributeValue
virtual const char * getAttributeValue(const char *key) const =0
agora::rtm::IChannel::deleteAttributes
virtual int deleteAttributes(IChannelAttributes *attributes, int64_t &requestId)=0
agora::rtm::IMessage::release
virtual void release()=0
agora::rtm::IChannelEventHandler
Definition: IAgoraRtmService.h:438
agora::rtm::IRtmServiceEventHandler::onConnectionStateChanged
virtual void onConnectionStateChanged(CONNECTION_STATE state)
Definition: IAgoraRtmService.h:618
agora::rtm::IRtmService::sendMessageToPeer
virtual int sendMessageToPeer(const char *peerId, const IMessage *message)=0
agora::rtm::IMessage::getRawMessageData
virtual const unsigned char * getRawMessageData() const =0
agora::rtm::IChannelEventHandler::onMembersGotten
virtual void onMembersGotten(IChannelMember **members, int userCount)
Definition: IAgoraRtmService.h:488
agora::rtm::IChannelAttributes::createChannelAttributes
static IChannelAttributes * createChannelAttributes()
agora::rtm::IChannelEventHandler::onAttributesDeleted
virtual void onAttributesDeleted(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:504
agora::rtm::IRtmServiceEventHandler::onLogout
virtual void onLogout()
Definition: IAgoraRtmService.h:613
agora::rtm::IRtmServiceEventHandler
Definition: IAgoraRtmService.h:597
agora::rtm::IChannelEventHandler::onSendMessageState
virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state)
Definition: IAgoraRtmService.h:465
agora::rtm::IRtmService::logout
virtual int logout()=0
agora::rtm::IChannelEventHandler::onUpdateAttributesResponse
virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:499