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 #include <stdint.h>
10 
11 namespace agora {
12 
13 namespace rtm {
14 
15 enum PEER_MESSAGE_STATE {
16  PEER_MESSAGE_INIT = 0,
17  PEER_MESSAGE_FAILURE = 1,
18  PEER_MESSAGE_PEER_UNREACHABLE = 2,
19  PEER_MESSAGE_RECEIVED_BY_PEER = 3,
20  PEER_MESSAGE_SENT_TIMEOUT = 4,
21 };
25 enum LOGIN_ERR_CODE {
29  LOGIN_ERR_OK = 0,
33  LOGIN_ERR_UNKNOWN = 1,
38  LOGIN_ERR_REJECTED = 2, // ALREADY LOGIN OR NOT INITIALIZED, SERVER REJECT
42  LOGIN_ERR_INVALID_ARGUMENT = 3,
46  LOGIN_ERR_INVALID_APP_ID = 4,
50  LOGIN_ERR_INVALID_TOKEN = 5,
54  LOGIN_ERR_TOKEN_EXPIRED = 6,
58  LOGIN_ERR_NOT_AUTHORIZED = 7,
62  LOGIN_ERR_TIMEOUT = 8,
63 };
67 enum LOGOUT_ERR_CODE {
71  LOGOUT_ERR_OK = 0,
75  LOGOUT_ERR_REJECTED = 1,
76 };
80 enum CONNECTION_STATE {
84  CONNECTION_STATE_CONNECTED = 1,
88  CONNECTION_STATE_DISCONNECTED = 2,
95  CONNECTION_STATE_ABORTED = 3,
96 };
97 
101 enum CHANNEL_MESSAGE_STATE {
105  CHANNEL_MESSAGE_RECEIVED_BY_SERVER = 1,
110  CHANNEL_MESSAGE_SENT_TIMEOUT = 3,
111 };
115 enum JOIN_CHANNEL_ERR {
119  JOIN_CHANNEL_ERR_OK = 0,
120 
124  JOIN_CHANNEL_ERR_FAILURE = 1,
125 
129  JOIN_CHANNEL_ERR_REJECTED = 2, // Usually occurs when the user is already in the channel
130 
134  JOIN_CHANNEL_ERR_INVALID_ARGUMENT = 3,
135 
139  JOIN_CHANNEL_TIMEOUT = 4,
140 
144  JOIN_CHANNEL_ERR_EXCEED_LIMIT = 5,
145 
149  JOIN_CHANNEL_ERR_ALREADY_JOINED = 6,
150 
154  JOIN_CHANNEL_ERR_TOO_OFTEN = 7,
155 
159  JOIN_CHANNEL_ERR_JOIN_SAME_CHANNEL_TOO_OFTEN = 8,
160 
164  JOIN_CHANNEL_ERR_NOT_INITIALIZED = 101,
165 
169  JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
170 };
174 enum LEAVE_CHANNEL_ERR {
175 
179  LEAVE_CHANNEL_ERR_OK = 0,
180 
184  LEAVE_CHANNEL_ERR_FAILURE = 1,
185 
189  LEAVE_CHANNEL_ERR_REJECTED = 2,
190 
194  LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL = 3,
195 
199  LEAVE_CHANNEL_ERR_NOT_INITIALIZED = 101,
200 
204  LEAVE_CHANNEL_ERR_USER_NOT_LOGGED_IN = 102,
205 };
206 
210 enum LEAVE_CHANNEL_REASON {
214  LEAVE_CHANNEL_REASON_QUIT = 1,
218  LEAVE_CHANNEL_REASON_KICKED = 2,
219 };
223 enum CHANNEL_MESSAGE_ERR_CODE {
224 
228  CHANNEL_MESSAGE_ERR_OK = 0,
229 
233  CHANNEL_MESSAGE_ERR_FAILURE = 1,
234 
238  CHANNEL_MESSAGE_ERR_SENT_TIMEOUT = 2,
239 
243  CHANNEL_MESSAGE_ERR_TOO_OFTEN = 3,
244 
248  CHANNEL_MESSAGE_ERR_INVALID_MESSAGE = 4,
249 
253  CHANNEL_MESSAGE_ERR_NOT_INITIALIZED = 101,
254 
258  CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN = 102,
259 };
260 
264 enum RESPONSE_CODE {
268  RESPONSE_CODE_SUCCESS = 1,
269  RESPONSE_CODE_FAILURE = 2,
270 };
274 enum MESSAGE_TYPE {
278  MESSAGE_TYPE_UNDEFINED = 0,
282  MESSAGE_TYPE_TEXT = 1,
286  MESSAGE_TYPE_BINARY = 2,
290  MESSAGE_TYPE_CONVERGE = 4,
291 };
295 class IMessage {
296  public:
307  virtual ~IMessage() {}
312  virtual int64_t getMessageId() const = 0;
319  virtual int getMessageType() const = 0;
325  virtual void setText(const char *str) = 0;
331  virtual const char *getText() const = 0;
337  virtual const unsigned char *getRawMessageData() const = 0;
343  virtual int getRawMessageLength() const = 0;
347  virtual void setMessageType(int32_t type) = 0;
351  virtual void setRawMessage(const uint8_t* data, int length) = 0;
355  virtual void release() = 0;
356 };
357 
362  public:
363  virtual ~IChannelMember() {}
368  virtual const char *getMemberId() const = 0;
373  virtual const char *getChannelId() const = 0;
377  virtual void release() = 0;
378 };
383  public:
399  virtual int addAttribute(const char *key, const char *value) = 0;
407  virtual int removeAttribute(const char *key) = 0;
414  virtual int getAttributesSize() const = 0;
421  virtual void getAttributes(int size, char **key,
422  char **value) const = 0; // todo: discussion, how to traveral
427  virtual const char *getAttributeValue(const char *key) const = 0;
434  virtual int release() = 0;
435 };
440  public:
441  virtual ~IChannelEventHandler() {}
445  virtual void onJoinSuccess() {}
450  virtual void onJoinFailure(JOIN_CHANNEL_ERR errorCode) {}
455  virtual void onLeave(LEAVE_CHANNEL_ERR errorCode) {}
460  virtual void onMessageReceived(const char *userId, const IMessage *message) {}
466  virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state) {}
473  virtual void onSendMessageResult(long long messageId, CHANNEL_MESSAGE_ERR_CODE state) {}
478  virtual void onMemberJoined(IChannelMember *member) {}
483  virtual void onMemberLeft(IChannelMember *member) {}
489  virtual void onMembersGotten(IChannelMember **members, int userCount) {}
494  virtual void onAttributesUpdated(const IChannelAttributes *attributes) {}
500  virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
505  virtual void onAttributesDeleted(const IChannelAttributes *attributes) {}
511  virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode) {}
512 };
516 class IChannel {
517  public:
522  virtual void setEventHandler(IChannelEventHandler *eventHandler) = 0;
532  virtual int join() = 0;
541  virtual int leave() = 0;
552  virtual int sendMessage(const IMessage *message) = 0;
563  virtual int updateAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
574  virtual int deleteAttributes(IChannelAttributes *attributes, int64_t &requestId) = 0;
581  virtual const char *getId() const = 0;
582 
583  // sync_call
593  virtual int release() = 0;
594 };
599  public:
600  virtual ~IRtmServiceEventHandler() {}
601 
605  virtual void onLoginSuccess() {}
610  virtual void onLoginFailure(LOGIN_ERR_CODE errorCode) {}
614  virtual void onLogout() {}
619  virtual void onConnectionStateChanged(CONNECTION_STATE state) {}
625  virtual void onSendMessageState(int64_t messageId, PEER_MESSAGE_STATE state) {}
631  virtual void onMessageReceivedFromPeer(const char *peerId, const IMessage *message) {}
632 };
636 class IRtmService {
637  public:
638  virtual ~IRtmService() {}
648  virtual int initialize(const char *appId, IRtmServiceEventHandler *eventHandler) = 0;
653  virtual void unregisterObserver(IRtmServiceEventHandler *eventHandler) = 0;
664  virtual int release(bool sync = false) = 0;
677  virtual int login(const char *token, const char *userId) = 0;
684  virtual int logout() = 0;
694  virtual int sendMessageToPeer(const char *peerId, const IMessage *message) = 0;
711  virtual IChannel *createChannel(const char *channelId, IChannelEventHandler *eventHandler) = 0;
712 };
713 
714 } // namespace rtm
715 } // 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:625
agora::rtm::IChannelEventHandler::onDeleteAttributesResponse
virtual void onDeleteAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:511
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:473
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:450
agora::rtm::IRtmService
Definition: IAgoraRtmService.h:636
agora::rtm::IMessage
Definition: IAgoraRtmService.h:295
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:631
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:483
agora::rtm::IChannelAttributes
Definition: IAgoraRtmService.h:382
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:605
agora::rtm::IRtmServiceEventHandler::onLoginFailure
virtual void onLoginFailure(LOGIN_ERR_CODE errorCode)
Definition: IAgoraRtmService.h:610
agora::rtm::IChannel
Definition: IAgoraRtmService.h:516
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:361
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:455
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:478
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:460
agora::rtm::IChannelEventHandler::onAttributesUpdated
virtual void onAttributesUpdated(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:494
agora::rtm::IChannelEventHandler::onJoinSuccess
virtual void onJoinSuccess()
Definition: IAgoraRtmService.h:445
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:439
agora::rtm::IRtmServiceEventHandler::onConnectionStateChanged
virtual void onConnectionStateChanged(CONNECTION_STATE state)
Definition: IAgoraRtmService.h:619
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:489
agora::rtm::IChannelAttributes::createChannelAttributes
static IChannelAttributes * createChannelAttributes()
agora::rtm::IChannelEventHandler::onAttributesDeleted
virtual void onAttributesDeleted(const IChannelAttributes *attributes)
Definition: IAgoraRtmService.h:505
agora::rtm::IRtmServiceEventHandler::onLogout
virtual void onLogout()
Definition: IAgoraRtmService.h:614
agora::rtm::IRtmServiceEventHandler
Definition: IAgoraRtmService.h:598
agora::rtm::IChannelEventHandler::onSendMessageState
virtual void onSendMessageState(int64_t messageId, CHANNEL_MESSAGE_STATE state)
Definition: IAgoraRtmService.h:466
agora::rtm::IRtmService::logout
virtual int logout()=0
agora::rtm::IChannelEventHandler::onUpdateAttributesResponse
virtual void onUpdateAttributesResponse(int64_t requestId, RESPONSE_CODE resCode)
Definition: IAgoraRtmService.h:500