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 
9 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
10 #include <cstdint>
11 #endif
12 
13 namespace agora {
14 
15 namespace rtm {
16 
17 enum PEER_MESSAGE_STATE {
18  PEER_MESSAGE_INIT = 0,
19  PEER_MESSAGE_FAILURE = 1,
20  PEER_MESSAGE_PEER_UNREACHABLE = 2,
21  PEER_MESSAGE_RECEIVED_BY_PEER = 3,
22  PEER_MESSAGE_SENT_TIMEOUT = 4,
23 };
27 enum LOGIN_ERR_CODE {
31  LOGIN_ERR_OK = 0,
35  LOGIN_ERR_UNKNOWN = 1,
40  LOGIN_ERR_REJECTED = 2, // ALREADY LOGIN OR NOT INITIALIZED, SERVER REJECT
44  LOGIN_ERR_INVALID_ARGUMENT = 3,
48  LOGIN_ERR_INVALID_APP_ID = 4,
52  LOGIN_ERR_INVALID_TOKEN = 5,
56  LOGIN_ERR_TOKEN_EXPIRED = 6,
60  LOGIN_ERR_NOT_AUTHORIZED = 7,
64  LOGIN_ERR_TIMEOUT = 8,
65 };
69 enum LOGOUT_ERR_CODE {
73  LOGOUT_ERR_OK = 0,
77  LOGOUT_ERR_REJECTED = 1,
78 };
82 enum CONNECTION_STATE {
86  CONNECTION_STATE_CONNECTED = 1,
90  CONNECTION_STATE_DISCONNECTED = 2,
97  CONNECTION_STATE_ABORTED = 3,
98 };
99 
103 enum CHANNEL_MESSAGE_STATE {
107  CHANNEL_MESSAGE_RECEIVED_BY_SERVER = 1,
112  CHANNEL_MESSAGE_SENT_TIMEOUT = 3,
113 };
117 enum JOIN_CHANNEL_ERR {
121  JOIN_CHANNEL_ERR_OK = 0,
122 
126  JOIN_CHANNEL_ERR_FAILURE = 1,
127 
131  JOIN_CHANNEL_ERR_REJECTED = 2, // Usually occurs when the user is already in the channel
132 
136  JOIN_CHANNEL_ERR_INVALID_ARGUMENT = 3,
137 
141  JOIN_CHANNEL_TIMEOUT = 4,
142 
146  JOIN_CHANNEL_ERR_EXCEED_LIMIT = 5,
147 
151  JOIN_CHANNEL_ERR_ALREADY_JOINED = 6,
152 
156  JOIN_CHANNEL_ERR_TOO_OFTEN = 7,
157 
161  JOIN_CHANNEL_ERR_JOIN_SAME_CHANNEL_TOO_OFTEN = 8,
162 
166  JOIN_CHANNEL_ERR_NOT_INITIALIZED = 101,
167 
171  JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
172 };
176 enum LEAVE_CHANNEL_ERR {
177 
181  LEAVE_CHANNEL_ERR_OK = 0,
182 
186  LEAVE_CHANNEL_ERR_FAILURE = 1,
187 
191  LEAVE_CHANNEL_ERR_REJECTED = 2,
192 
196  LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL = 3,
197 
201  LEAVE_CHANNEL_ERR_NOT_INITIALIZED = 101,
202 
206  LEAVE_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
207 };
208 
212 enum LEAVE_CHANNEL_REASON {
216  LEAVE_CHANNEL_REASON_QUIT = 1,
220  LEAVE_CHANNEL_REASON_KICKED = 2,
221 };
225 enum CHANNEL_MESSAGE_ERR_CODE {
226 
230  CHANNEL_MESSAGE_ERR_OK = 0,
231 
235  CHANNEL_MESSAGE_ERR_FAILURE = 1,
236 
240  CHANNEL_MESSAGE_ERR_SENT_TIMEOUT = 2,
241 
245  CHANNEL_MESSAGE_ERR_TOO_OFTEN = 3,
246 
250  CHANNEL_MESSAGE_ERR_INVALID_MESSAGE = 4,
251 
255  CHANNEL_MESSAGE_ERR_NOT_INITIALIZED = 101,
256 
260  CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN = 102,
261 };
262 
266 enum RESPONSE_CODE {
270  RESPONSE_CODE_SUCCESS = 1,
271  RESPONSE_CODE_FAILURE = 2,
272 };
276 enum MESSAGE_TYPE {
280  MESSAGE_TYPE_UNDEFINED = 0,
284  MESSAGE_TYPE_TEXT = 1,
288  MESSAGE_TYPE_BINARY = 2,
292  MESSAGE_TYPE_CONVERGE = 4,
293 };
297 class IMessage {
298  public:
309  virtual ~IMessage() {}
314  virtual int64_t getMessageId() const = 0;
321  virtual int getMessageType() const = 0;
327  virtual void setText(const char *str) = 0;
333  virtual const char *getText() const = 0;
339  virtual const unsigned char *getRawMessageData() const = 0;
345  virtual int getRawMessageLength() const = 0;
349  virtual void setMessageType(int32_t type) = 0;
353  virtual void setRawMessage(const uint8_t* data, int length) = 0;
357  virtual void release() = 0;
358 };
359 
364  public:
365  virtual ~IChannelMember() {}
370  virtual const char *getMemberId() const = 0;
375  virtual const char *getChannelId() const = 0;
379  virtual void release() = 0;
380 };
385  public:
401  virtual int addAttribute(const char *key, const char *value) = 0;
409  virtual int removeAttribute(const char *key) = 0;
416  virtual int getAttributesSize() const = 0;
423  virtual void getAttributes(int size, char **key,
424  char **value) const = 0; // todo: discussion, how to traveral
429  virtual const char *getAttributeValue(const char *key) const = 0;
436  virtual int release() = 0;
437 };
442  public:
443  virtual ~IChannelEventHandler() {}
447  virtual void onJoinSuccess() {}
452  virtual void onJoinFailure(JOIN_CHANNEL_ERR errorCode) {}
457  virtual void onLeave(LEAVE_CHANNEL_ERR errorCode) {}
462  virtual void onMessageReceived(const char *userId, const IMessage *message) {}
468  virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state) {}
475  virtual void onSendMessageResult(long long messageId, CHANNEL_MESSAGE_ERR_CODE state) {}
480  virtual void onMemberJoined(IChannelMember *member) {}
485  virtual void onMemberLeft(IChannelMember *member) {}
491  virtual void onMembersGotten(IChannelMember **members, int userCount) {}
496  virtual void onAttributesUpdated(const IChannelAttributes *attributes) {}
502  virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
507  virtual void onAttributesDeleted(const IChannelAttributes *attributes) {}
513  virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
514 };
518 class IChannel {
519  public:
524  virtual void setEventHandler(IChannelEventHandler *eventHandler) = 0;
534  virtual int join() = 0;
543  virtual int leave() = 0;
554  virtual int sendMessage(const IMessage *message) = 0;
565  virtual int updateAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
576  virtual int deleteAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
583  virtual const char *getId() const = 0;
584 
585  // sync_call
595  virtual int release() = 0;
596 };
601  public:
602  virtual ~IRtmServiceEventHandler() {}
603 
607  virtual void onLoginSuccess() {}
612  virtual void onLoginFailure(LOGIN_ERR_CODE errorCode) {}
616  virtual void onLogout() {}
621  virtual void onConnectionStateChanged(CONNECTION_STATE state) {}
627  virtual void onSendMessageState(int64_t messageId, PEER_MESSAGE_STATE state) {}
633  virtual void onMessageReceivedFromPeer(const char *peerId, const IMessage *message) {}
634 };
638 class IRtmService {
639  public:
640  virtual ~IRtmService() {}
650  virtual int initialize(const char *appId, IRtmServiceEventHandler *eventHandler) = 0;
655  virtual void unregisterObserver(IRtmServiceEventHandler *eventHandler) = 0;
666  virtual int release(bool sync = false) = 0;
679  virtual int login(const char *token, const char *userId) = 0;
686  virtual int logout() = 0;
696  virtual int sendMessageToPeer(const char *peerId, const IMessage *message) = 0;
713  virtual IChannel *createChannel(const char *channelId, IChannelEventHandler *eventHandler) = 0;
714 };
715 
716 } // namespace rtm
717 } // 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:627
agora::rtm::IChannelEventHandler::onDeleteAttributesResponse
virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:513
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:475
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:452
agora::rtm::IRtmService
Definition: IAgoraRtmService.h:638
agora::rtm::IMessage
Definition: IAgoraRtmService.h:297
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:633
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:485
agora::rtm::IChannelAttributes
Definition: IAgoraRtmService.h:384
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:607
agora::rtm::IRtmServiceEventHandler::onLoginFailure
virtual void onLoginFailure(LOGIN_ERR_CODE errorCode)
Definition: IAgoraRtmService.h:612
agora::rtm::IChannel
Definition: IAgoraRtmService.h:518
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:363
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:457
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:480
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:462
agora::rtm::IChannelEventHandler::onAttributesUpdated
virtual void onAttributesUpdated(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:496
agora::rtm::IChannelEventHandler::onJoinSuccess
virtual void onJoinSuccess()
Definition: IAgoraRtmService.h:447
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:441
agora::rtm::IRtmServiceEventHandler::onConnectionStateChanged
virtual void onConnectionStateChanged(CONNECTION_STATE state)
Definition: IAgoraRtmService.h:621
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:491
agora::rtm::IChannelAttributes::createChannelAttributes
static IChannelAttributes * createChannelAttributes()
agora::rtm::IChannelEventHandler::onAttributesDeleted
virtual void onAttributesDeleted(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:507
agora::rtm::IRtmServiceEventHandler::onLogout
virtual void onLogout()
Definition: IAgoraRtmService.h:616
agora::rtm::IRtmServiceEventHandler
Definition: IAgoraRtmService.h:600
agora::rtm::IChannelEventHandler::onSendMessageState
virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state)
Definition: IAgoraRtmService.h:468
agora::rtm::IRtmService::logout
virtual int logout()=0
agora::rtm::IChannelEventHandler::onUpdateAttributesResponse
virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:502