Agora Java API Reference for Android
NGIAgoraRtcConnection.h
1 //
2 // Agora SDK
3 //
4 // Created by Sting Feng in 2018-01.
5 // Copyright (c) 2018 Agora.io. All rights reserved.
6 //
7 
8 #pragma once // NOLINT(build/header_guard)
9 
10 #include "AgoraBase.h"
11 #include "AgoraRefPtr.h"
12 #include "NGIAgoraLocalUser.h"
13 
14 namespace agora {
15 namespace rtc {
16 class IAudioEncodedFrameSender;
17 class IRtcConnectionObserver;
18 class INetworkObserver;
19 class IRtcConnection;
20 class IVideoEncodedImageSender;
21 
29  conn_id_t id;
37  CONNECTION_STATE_TYPE state;
45  uid_t internalUid;
46 
47  TConnectionInfo() : id(-1), state(CONNECTION_STATE_DISCONNECTED), internalUid(0) {}
48 };
49 
55  packetOnly(false),
56  bytesPerSample(TWO_BYTES_PER_SAMPLE),
58  sampleRateHz(0) {
59  }
60 
66  }
74  bool packetOnly;
86  uint32_t sampleRateHz;
87 };
88 
120  int minPort;
124  int maxPort;
132  CLIENT_ROLE_TYPE clientRoleType;
135  CHANNEL_PROFILE_TYPE channelProfile;
136 
141 
146 
148  : autoSubscribeAudio(true),
149  autoSubscribeVideo(true),
151  maxSendBitrate(-1),
152  minPort(0),
153  maxPort(0),
154  clientRoleType(CLIENT_ROLE_AUDIENCE),
155  channelProfile(CHANNEL_PROFILE_LIVE_BROADCASTING),
156  audioRecvMediaPacket(false),
157  videoRecvMediaPacket(false) {}
158 };
159 
171  protected:
172  ~IRtcConnection() {}
173 
174  public:
202  virtual int connect(const char* token, const char* channelId, user_id_t userId) = 0;
203 
215  virtual int disconnect() = 0;
216 
244  virtual int startLastmileProbeTest(const LastmileProbeConfig& config) = 0;
245 
252  virtual int stopLastmileProbeTest() = 0;
253 
263  virtual int renewToken(const char* token) = 0;
264 
273 
281  virtual ILocalUser* getLocalUser() = 0;
282 
295  virtual int getRemoteUsers(UserList& users) = 0;
296 
307  virtual int getUserInfo(user_id_t userId, agora::UserInfo& userInfo) = 0;
308 
317  virtual int registerObserver(IRtcConnectionObserver* observer, void(*safeDeleter)(IRtcConnectionObserver*) = NULL) = 0;
318 
328  virtual int unregisterObserver(IRtcConnectionObserver* observer) = 0;
329 
338  virtual int registerNetworkObserver(INetworkObserver* observer, void(*safeDeleter)(INetworkObserver*) = NULL) = 0;
339 
349  virtual int unregisterNetworkObserver(INetworkObserver* observer) = 0;
350 
358  virtual conn_id_t getConnId() = 0;
359 
368 
377 
397  virtual int createDataStream(int* streamId, bool reliable, bool ordered, bool sync) = 0;
398 
414  virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
415 
435  virtual int enableEncryption(bool enabled, const EncryptionConfig& config) = 0;
436 
450  virtual int sendCustomReportMessage(const char* id, const char* category, const char* event, const char* label, int value) = 0;
462  virtual int getUserInfoByUserAccount(const char* userAccount, rtc::UserInfo* userInfo) = 0;
474  virtual int getUserInfoByUid(uid_t uid, rtc::UserInfo* userInfo) = 0;
475 };
476 
481  public:
482  virtual ~IRtcConnectionObserver() {}
483 
490  virtual void onConnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
491 
498  virtual void onDisconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
499 
506  virtual void onConnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
507 
514  virtual void onReconnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
515 
516  // This should be deleted. onConnected is enough.
517  virtual void onReconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
518 
524  virtual void onConnectionLost(const TConnectionInfo& connectionInfo) = 0;
525 
533  virtual void onLastmileQuality(const QUALITY_TYPE quality) = 0;
534 
542  virtual void onLastmileProbeResult(const LastmileProbeResult& result) = 0;
543 
554  virtual void onTokenPrivilegeWillExpire(const char* token) = 0;
555 
562  virtual void onTokenPrivilegeDidExpire() = 0;
563 
570  virtual void onConnectionFailure(const TConnectionInfo& connectionInfo,
571  CONNECTION_CHANGED_REASON_TYPE reason) = 0;
572 
580  virtual void onUserJoined(user_id_t userId) = 0;
581 
590  virtual void onUserLeft(user_id_t userId, USER_OFFLINE_REASON_TYPE reason) = 0;
591 
599  virtual void onTransportStats(const RtcStats& stats) = 0;
600 
607  virtual void onChangeRoleSuccess(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
608  (void)oldRole;
609  (void)newRole;
610  }
611 
615  virtual void onChangeRoleFailure() {}
616 
627  virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality,
628  QUALITY_TYPE rxQuality) {
629  (void)userId;
630  (void)txQuality;
631  (void)rxQuality;
632  }
633 
637  virtual void onNetworkTypeChanged(NETWORK_TYPE type) {
638  (void)type;
639  }
640 
649  virtual void onApiCallExecuted(int err, const char* api, const char* result) {
650  (void)err;
651  (void)api;
652  (void)result;
653  }
654 
660  virtual void onError(ERROR_CODE_TYPE error, const char* msg) {
661  (void)error;
662  (void)msg;
663  }
664 
670  virtual void onWarning(WARN_CODE_TYPE warning, const char* msg) {
671  (void)warning;
672  (void)msg;
673  }
674 
704  virtual void onChannelMediaRelayStateChanged(int state, int code) = 0;
705 
711  virtual void onLocalUserRegistered(uid_t uid, const char* userAccount) {
712  (void)uid;
713  (void)userAccount;
714  }
715 
717  virtual void onUserAccountUpdated(uid_t uid, const char* userAccount){
718  (void)uid;
719  (void)userAccount;
720  }
721 
731  virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed,
732  int cached) {
733  (void)userId;
734  (void)streamId;
735  (void)code;
736  (void)missed;
737  (void)cached;
738  }
739 
744  virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType) {
745  (void)errorType;
746  }
747 };
748 
750  public:
751  virtual ~INetworkObserver() {}
752 
753  public:
762  virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo& info) {
763  (void)info;
764  }
765 
774  (void)info;
775  }
776 };
777 
778 } // namespace rtc
779 } // namespace agora
agora::rtc::IRtcConnectionObserver::onUserNetworkQuality
virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality, QUALITY_TYPE rxQuality)
Definition: NGIAgoraRtcConnection.h:627
agora::rtc::TConnectionInfo::state
CONNECTION_STATE_TYPE state
Definition: NGIAgoraRtcConnection.h:37
agora::rtc::RtcConnectionConfiguration::channelProfile
CHANNEL_PROFILE_TYPE channelProfile
Definition: NGIAgoraRtcConnection.h:135
agora::rtc::UserInfo
Definition: AgoraBase.h:4218
agora::rtc::AudioSubscriptionOptions::bytesPerSample
size_t bytesPerSample
Definition: NGIAgoraRtcConnection.h:78
agora::rtc::AudioSubscriptionOptions::sampleRateHz
uint32_t sampleRateHz
Definition: NGIAgoraRtcConnection.h:86
agora::rtc::LastmileProbeResult
Definition: AgoraBase.h:3424
agora::rtc::IRtcConnection::getConnectionInfo
virtual TConnectionInfo getConnectionInfo()=0
agora::rtc::IRtcConnectionObserver::onEncryptionError
virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType)
Definition: NGIAgoraRtcConnection.h:744
agora::rtc::RtcConnectionConfiguration::audioSubscriptionOptions
AudioSubscriptionOptions audioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:128
agora::rtc::IRtcConnectionObserver::onError
virtual void onError(ERROR_CODE_TYPE error, const char *msg)
Definition: NGIAgoraRtcConnection.h:660
agora::rtc::IRtcConnectionObserver::onConnecting
virtual void onConnecting(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::base::IAgoraParameter
Definition: IAgoraParameter.h:159
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:120
agora::rtc::LastmileProbeConfig
Definition: AgoraBase.h:3350
agora::rtc::IRtcConnection::sendCustomReportMessage
virtual int sendCustomReportMessage(const char *id, const char *category, const char *event, const char *label, int value)=0
agora::rtc::IRtcConnectionObserver::onTransportStats
virtual void onTransportStats(const RtcStats &stats)=0
agora::rtc::INetworkObserver
Definition: NGIAgoraRtcConnection.h:749
agora::rtc::IRtcConnectionObserver
Definition: NGIAgoraRtcConnection.h:480
agora::rtc::IRtcConnection::stopLastmileProbeTest
virtual int stopLastmileProbeTest()=0
agora::rtc::IRtcConnectionObserver::onUserJoined
virtual void onUserJoined(user_id_t userId)=0
agora::rtc::IRtcConnection::startLastmileProbeTest
virtual int startLastmileProbeTest(const LastmileProbeConfig &config)=0
agora::rtc::IRtcConnection::getUserInfo
virtual int getUserInfo(user_id_t userId, agora::UserInfo &userInfo)=0
agora::util::AList
Definition: AgoraBase.h:213
agora::rtc::IRtcConnection::disconnect
virtual int disconnect()=0
agora::rtc::IRtcConnectionObserver::onReconnecting
virtual void onReconnecting(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::rtc::IRtcConnectionObserver::onDisconnected
virtual void onDisconnected(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::rtc::IRtcConnection::getAgoraParameter
virtual agora::base::IAgoraParameter * getAgoraParameter()=0
agora::rtc::IRtcConnection::getUserInfoByUid
virtual int getUserInfoByUid(uid_t uid, rtc::UserInfo *userInfo)=0
agora::rtc::RtcConnectionConfiguration::autoSubscribeAudio
bool autoSubscribeAudio
Definition: NGIAgoraRtcConnection.h:100
agora::rtc::RtcConnectionConfiguration::audioRecvMediaPacket
bool audioRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:140
agora::rtc::IRtcConnection::getTransportStats
virtual RtcStats getTransportStats()=0
agora::rtc::IRtcConnection::unregisterNetworkObserver
virtual int unregisterNetworkObserver(INetworkObserver *observer)=0
agora::rtc::TConnectionInfo
Definition: NGIAgoraRtcConnection.h:25
agora::rtc::IRtcConnection::getRemoteUsers
virtual int getRemoteUsers(UserList &users)=0
agora::rtc::IRtcConnectionObserver::onTokenPrivilegeWillExpire
virtual void onTokenPrivilegeWillExpire(const char *token)=0
agora::rtc::IRtcConnection::renewToken
virtual int renewToken(const char *token)=0
agora::rtc::IRtcConnectionObserver::onUserAccountUpdated
virtual void onUserAccountUpdated(uid_t uid, const char *userAccount)
Definition: NGIAgoraRtcConnection.h:717
agora::rtc::IRtcConnection::sendStreamMessage
virtual int sendStreamMessage(int streamId, const char *data, size_t length)=0
agora::rtc::IRtcConnection::connect
virtual int connect(const char *token, const char *channelId, user_id_t userId)=0
agora::rtc::IRtcConnectionObserver::onChangeRoleFailure
virtual void onChangeRoleFailure()
Definition: NGIAgoraRtcConnection.h:615
agora::rtc::IRtcConnectionObserver::onTokenPrivilegeDidExpire
virtual void onTokenPrivilegeDidExpire()=0
agora::rtc::IRtcConnection::createDataStream
virtual int createDataStream(int *streamId, bool reliable, bool ordered, bool sync)=0
agora::rtc::TConnectionInfo::channelId
util::AString channelId
Definition: NGIAgoraRtcConnection.h:33
agora::rtc::IRtcConnectionObserver::onLastmileProbeResult
virtual void onLastmileProbeResult(const LastmileProbeResult &result)=0
agora::rtc::IRtcConnectionObserver::onConnected
virtual void onConnected(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::rtc::AudioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:53
agora::rtc::IRtcConnectionObserver::onLocalUserRegistered
virtual void onLocalUserRegistered(uid_t uid, const char *userAccount)
Definition: NGIAgoraRtcConnection.h:711
agora::rtc::IRtcConnectionObserver::onStreamMessageError
virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed, int cached)
Definition: NGIAgoraRtcConnection.h:731
agora::rtc::IRtcConnection::getLocalUser
virtual ILocalUser * getLocalUser()=0
agora::rtc::INetworkObserver::onDownlinkNetworkInfoUpdated
virtual void onDownlinkNetworkInfoUpdated(const DownlinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:773
agora::rtc::IRtcConnectionObserver::onChannelMediaRelayStateChanged
virtual void onChannelMediaRelayStateChanged(int state, int code)=0
agora::UserInfo
Definition: AgoraBase.h:1104
agora::rtc::IRtcConnectionObserver::onConnectionFailure
virtual void onConnectionFailure(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::rtc::ILocalUser
Definition: NGIAgoraLocalUser.h:40
agora::rtc::RtcConnectionConfiguration::clientRoleType
CLIENT_ROLE_TYPE clientRoleType
Definition: NGIAgoraRtcConnection.h:132
agora::rtc::IRtcConnection::enableEncryption
virtual int enableEncryption(bool enabled, const EncryptionConfig &config)=0
agora::rtc::RtcConnectionConfiguration::enableAudioRecordingOrPlayout
bool enableAudioRecordingOrPlayout
Definition: NGIAgoraRtcConnection.h:112
agora::rtc::IRtcConnectionObserver::onNetworkTypeChanged
virtual void onNetworkTypeChanged(NETWORK_TYPE type)
Definition: NGIAgoraRtcConnection.h:637
agora::rtc::IRtcConnectionObserver::onConnectionLost
virtual void onConnectionLost(const TConnectionInfo &connectionInfo)=0
agora::rtc::RtcConnectionConfiguration::videoRecvMediaPacket
bool videoRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:145
agora::rtc::IRtcConnectionObserver::onWarning
virtual void onWarning(WARN_CODE_TYPE warning, const char *msg)
Definition: NGIAgoraRtcConnection.h:670
agora::rtc::RtcConnectionConfiguration::autoSubscribeVideo
bool autoSubscribeVideo
Definition: NGIAgoraRtcConnection.h:106
agora::rtc::IRtcConnectionObserver::onUserLeft
virtual void onUserLeft(user_id_t userId, USER_OFFLINE_REASON_TYPE reason)=0
agora::rtc::IRtcConnectionObserver::onApiCallExecuted
virtual void onApiCallExecuted(int err, const char *api, const char *result)
Definition: NGIAgoraRtcConnection.h:649
agora::rtc::EncryptionConfig
Definition: AgoraBase.h:4137
agora::rtc::AudioSubscriptionOptions::packetOnly
bool packetOnly
Definition: NGIAgoraRtcConnection.h:74
agora::rtc::IRtcConnectionObserver::onLastmileQuality
virtual void onLastmileQuality(const QUALITY_TYPE quality)=0
agora::rtc::RtcStats
Definition: AgoraBase.h:1952
agora::rtc::IRtcConnection::registerObserver
virtual int registerObserver(IRtcConnectionObserver *observer, void(*safeDeleter)(IRtcConnectionObserver *)=NULL)=0
agora::rtc::RtcConnectionConfiguration
Definition: NGIAgoraRtcConnection.h:94
agora::RefCountInterface
Definition: AgoraRefPtr.h:21
agora::rtc::RtcConnectionConfiguration::maxPort
int maxPort
Definition: NGIAgoraRtcConnection.h:124
agora::rtc::INetworkObserver::onUplinkNetworkInfoUpdated
virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:762
agora::rtc::TConnectionInfo::localUserId
util::AString localUserId
Definition: NGIAgoraRtcConnection.h:41
agora::rtc::IRtcConnection
Definition: NGIAgoraRtcConnection.h:170
agora::util::CopyableAutoPtr
Definition: AgoraBase.h:136
agora::rtc::IRtcConnection::registerNetworkObserver
virtual int registerNetworkObserver(INetworkObserver *observer, void(*safeDeleter)(INetworkObserver *)=NULL)=0
agora::rtc::IRtcConnection::getConnId
virtual conn_id_t getConnId()=0
agora::rtc::IRtcConnection::getUserInfoByUserAccount
virtual int getUserInfoByUserAccount(const char *userAccount, rtc::UserInfo *userInfo)=0
agora::rtc::IRtcConnection::unregisterObserver
virtual int unregisterObserver(IRtcConnectionObserver *observer)=0
agora::rtc::IRtcConnectionObserver::onChangeRoleSuccess
virtual void onChangeRoleSuccess(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole)
Definition: NGIAgoraRtcConnection.h:607
agora::rtc::RtcConnectionConfiguration::maxSendBitrate
int maxSendBitrate
Definition: NGIAgoraRtcConnection.h:116
agora::rtc::AudioSubscriptionOptions::numberOfChannels
size_t numberOfChannels
Definition: NGIAgoraRtcConnection.h:82
agora::rtc::TConnectionInfo::internalUid
uid_t internalUid
Definition: NGIAgoraRtcConnection.h:45
agora::rtc::TConnectionInfo::id
conn_id_t id
Definition: NGIAgoraRtcConnection.h:29