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 
12 namespace agora {
13 namespace rtc {
14 class IAudioEncodedFrameSender;
15 class IRtcConnectionObserver;
16 class INetworkObserver;
17 class IRtcConnection;
18 class IVideoEncodedImageSender;
19 class ILocalUser;
20 
28  conn_id_t id;
36  CONNECTION_STATE_TYPE state;
44  uid_t internalUid;
45 
46  TConnectionInfo() : id(-1), state(CONNECTION_STATE_DISCONNECTED), internalUid(0) {}
47 };
48 
54  packetOnly(false),
55  bytesPerSample(TWO_BYTES_PER_SAMPLE),
57  sampleRateHz(0) {
58  }
59 
65  }
66 
68  {
69  if (this == &rhs) {
70  return *this;
71  }
72 
73  packetOnly = rhs.packetOnly;
77  return *this;
78  }
86  bool packetOnly;
98  uint32_t sampleRateHz;
99 };
100 
132  int minPort;
136  int maxPort;
144  CLIENT_ROLE_TYPE clientRoleType;
147  CHANNEL_PROFILE_TYPE channelProfile;
148 
153 
158 
160  : autoSubscribeAudio(true),
161  autoSubscribeVideo(true),
163  maxSendBitrate(-1),
164  minPort(0),
165  maxPort(0),
166  clientRoleType(CLIENT_ROLE_AUDIENCE),
167  channelProfile(CHANNEL_PROFILE_LIVE_BROADCASTING),
168  audioRecvMediaPacket(false),
169  videoRecvMediaPacket(false) {}
170 };
171 
183  protected:
184  ~IRtcConnection() {}
185 
186  public:
214  virtual int connect(const char* token, const char* channelId, user_id_t userId) = 0;
215 
227  virtual int disconnect() = 0;
228 
256  virtual int startLastmileProbeTest(const LastmileProbeConfig& config) = 0;
257 
264  virtual int stopLastmileProbeTest() = 0;
265 
275  virtual int renewToken(const char* token) = 0;
276 
285 
293  virtual ILocalUser* getLocalUser() = 0;
294 
307  virtual int getRemoteUsers(UserList& users) = 0;
308 
319  virtual int getUserInfo(user_id_t userId, agora::UserInfo& userInfo) = 0;
320 
329  virtual int registerObserver(IRtcConnectionObserver* observer, void(*safeDeleter)(IRtcConnectionObserver*) = NULL) = 0;
330 
340  virtual int unregisterObserver(IRtcConnectionObserver* observer) = 0;
341 
350  virtual int registerNetworkObserver(INetworkObserver* observer, void(*safeDeleter)(INetworkObserver*) = NULL) = 0;
351 
361  virtual int unregisterNetworkObserver(INetworkObserver* observer) = 0;
362 
370  virtual conn_id_t getConnId() = 0;
371 
380 
389 
409  virtual int createDataStream(int* streamId, bool reliable, bool ordered, bool sync) = 0;
410 
426  virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
427 
446  virtual int enableEncryption(bool enabled, const EncryptionConfig& config) = 0;
447 
461  virtual int sendCustomReportMessage(const char* id, const char* category, const char* event, const char* label, int value) = 0;
473  virtual int getUserInfoByUserAccount(const char* userAccount, rtc::UserInfo* userInfo) = 0;
485  virtual int getUserInfoByUid(uid_t uid, rtc::UserInfo* userInfo) = 0;
486 };
487 
492  public:
493  virtual ~IRtcConnectionObserver() {}
494 
501  virtual void onConnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
502 
509  virtual void onDisconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
510 
517  virtual void onConnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
518 
525  virtual void onReconnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
526 
527  // This should be deleted. onConnected is enough.
528  virtual void onReconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
529 
535  virtual void onConnectionLost(const TConnectionInfo& connectionInfo) = 0;
536 
544  virtual void onLastmileQuality(const QUALITY_TYPE quality) = 0;
545 
553  virtual void onLastmileProbeResult(const LastmileProbeResult& result) = 0;
554 
565  virtual void onTokenPrivilegeWillExpire(const char* token) = 0;
566 
573  virtual void onTokenPrivilegeDidExpire() = 0;
574 
581  virtual void onConnectionFailure(const TConnectionInfo& connectionInfo,
582  CONNECTION_CHANGED_REASON_TYPE reason) = 0;
583 
591  virtual void onUserJoined(user_id_t userId) = 0;
592 
601  virtual void onUserLeft(user_id_t userId, USER_OFFLINE_REASON_TYPE reason) = 0;
602 
610  virtual void onTransportStats(const RtcStats& stats) = 0;
611 
618  virtual void onChangeRoleSuccess(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
619  (void)oldRole;
620  (void)newRole;
621  }
622 
626  virtual void onChangeRoleFailure() {}
627 
638  virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality,
639  QUALITY_TYPE rxQuality) {
640  (void)userId;
641  (void)txQuality;
642  (void)rxQuality;
643  }
644 
648  virtual void onNetworkTypeChanged(NETWORK_TYPE type) {
649  (void)type;
650  }
651 
660  virtual void onApiCallExecuted(int err, const char* api, const char* result) {
661  (void)err;
662  (void)api;
663  (void)result;
664  }
665 
667  virtual void onContentInspectResult(media::CONTENT_INSPECT_RESULT result) { (void)result; }
680  virtual void onSnapshotTaken(const char* channel, uid_t uid, const char* filePath, int width, int height, int errCode) {
681  (void)channel;
682  (void)uid;
683  (void)filePath;
684  (void)width;
685  (void)height;
686  (void)errCode;
687  }
688 
694  virtual void onError(ERROR_CODE_TYPE error, const char* msg) {
695  (void)error;
696  (void)msg;
697  }
698 
704  virtual void onWarning(WARN_CODE_TYPE warning, const char* msg) {
705  (void)warning;
706  (void)msg;
707  }
708 
738  virtual void onChannelMediaRelayStateChanged(int state, int code) = 0;
739 
745  virtual void onLocalUserRegistered(uid_t uid, const char* userAccount) {
746  (void)uid;
747  (void)userAccount;
748  }
749 
751  virtual void onUserAccountUpdated(uid_t uid, const char* userAccount){
752  (void)uid;
753  (void)userAccount;
754  }
755 
765  virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed,
766  int cached) {
767  (void)userId;
768  (void)streamId;
769  (void)code;
770  (void)missed;
771  (void)cached;
772  }
773 
778  virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType) {
779  (void)errorType;
780  }
781 };
782 
784  public:
785  virtual ~INetworkObserver() {}
786 
787  public:
796  virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo& info) {
797  (void)info;
798  }
799 
808  (void)info;
809  }
810 };
811 
812 } // namespace rtc
813 } // namespace agora
agora::rtc::IRtcConnectionObserver::onUserNetworkQuality
virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality, QUALITY_TYPE rxQuality)
Definition: NGIAgoraRtcConnection.h:638
agora::rtc::TConnectionInfo::state
CONNECTION_STATE_TYPE state
Definition: NGIAgoraRtcConnection.h:36
agora::rtc::RtcConnectionConfiguration::channelProfile
CHANNEL_PROFILE_TYPE channelProfile
Definition: NGIAgoraRtcConnection.h:147
agora::rtc::UserInfo
Definition: AgoraBase.h:4844
agora::rtc::AudioSubscriptionOptions::bytesPerSample
size_t bytesPerSample
Definition: NGIAgoraRtcConnection.h:90
agora::rtc::AudioSubscriptionOptions::sampleRateHz
uint32_t sampleRateHz
Definition: NGIAgoraRtcConnection.h:98
agora::rtc::LastmileProbeResult
Definition: AgoraBase.h:3576
agora::rtc::IRtcConnection::getConnectionInfo
virtual TConnectionInfo getConnectionInfo()=0
agora::rtc::IRtcConnectionObserver::onEncryptionError
virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType)
Definition: NGIAgoraRtcConnection.h:778
agora::rtc::RtcConnectionConfiguration::audioSubscriptionOptions
AudioSubscriptionOptions audioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:140
agora::rtc::IRtcConnectionObserver::onError
virtual void onError(ERROR_CODE_TYPE error, const char *msg)
Definition: NGIAgoraRtcConnection.h:694
agora::rtc::IRtcConnectionObserver::onConnecting
virtual void onConnecting(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::base::IAgoraParameter
Definition: IAgoraParameter.h:189
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:132
agora::rtc::LastmileProbeConfig
Definition: AgoraBase.h:3502
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:783
agora::rtc::IRtcConnectionObserver
Definition: NGIAgoraRtcConnection.h:491
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:232
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:112
agora::rtc::RtcConnectionConfiguration::audioRecvMediaPacket
bool audioRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:152
agora::rtc::IRtcConnectionObserver::onContentInspectResult
virtual void onContentInspectResult(media::CONTENT_INSPECT_RESULT result)
Definition: NGIAgoraRtcConnection.h:667
agora::rtc::IRtcConnection::getTransportStats
virtual RtcStats getTransportStats()=0
agora::rtc::IRtcConnection::unregisterNetworkObserver
virtual int unregisterNetworkObserver(INetworkObserver *observer)=0
agora::rtc::TConnectionInfo
Definition: NGIAgoraRtcConnection.h:24
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:751
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:626
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:32
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:52
agora::rtc::IRtcConnectionObserver::onLocalUserRegistered
virtual void onLocalUserRegistered(uid_t uid, const char *userAccount)
Definition: NGIAgoraRtcConnection.h:745
agora::rtc::IRtcConnectionObserver::onStreamMessageError
virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed, int cached)
Definition: NGIAgoraRtcConnection.h:765
agora::rtc::IRtcConnection::getLocalUser
virtual ILocalUser * getLocalUser()=0
agora::rtc::INetworkObserver::onDownlinkNetworkInfoUpdated
virtual void onDownlinkNetworkInfoUpdated(const DownlinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:807
agora::rtc::IRtcConnectionObserver::onChannelMediaRelayStateChanged
virtual void onChannelMediaRelayStateChanged(int state, int code)=0
agora::UserInfo
Definition: AgoraBase.h:1129
agora::rtc::IRtcConnectionObserver::onConnectionFailure
virtual void onConnectionFailure(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::rtc::ILocalUser
Definition: NGIAgoraLocalUser.h:51
agora::rtc::RtcConnectionConfiguration::clientRoleType
CLIENT_ROLE_TYPE clientRoleType
Definition: NGIAgoraRtcConnection.h:144
agora::rtc::IRtcConnection::enableEncryption
virtual int enableEncryption(bool enabled, const EncryptionConfig &config)=0
agora::rtc::RtcConnectionConfiguration::enableAudioRecordingOrPlayout
bool enableAudioRecordingOrPlayout
Definition: NGIAgoraRtcConnection.h:124
agora::rtc::IRtcConnectionObserver::onNetworkTypeChanged
virtual void onNetworkTypeChanged(NETWORK_TYPE type)
Definition: NGIAgoraRtcConnection.h:648
agora::rtc::IRtcConnectionObserver::onConnectionLost
virtual void onConnectionLost(const TConnectionInfo &connectionInfo)=0
agora::rtc::RtcConnectionConfiguration::videoRecvMediaPacket
bool videoRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:157
agora::rtc::IRtcConnectionObserver::onWarning
virtual void onWarning(WARN_CODE_TYPE warning, const char *msg)
Definition: NGIAgoraRtcConnection.h:704
agora::rtc::RtcConnectionConfiguration::autoSubscribeVideo
bool autoSubscribeVideo
Definition: NGIAgoraRtcConnection.h:118
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:660
agora::rtc::EncryptionConfig
Definition: AgoraBase.h:4760
agora::rtc::AudioSubscriptionOptions::packetOnly
bool packetOnly
Definition: NGIAgoraRtcConnection.h:86
agora::rtc::IRtcConnectionObserver::onLastmileQuality
virtual void onLastmileQuality(const QUALITY_TYPE quality)=0
agora::rtc::RtcStats
Definition: AgoraBase.h:2079
agora::rtc::IRtcConnection::registerObserver
virtual int registerObserver(IRtcConnectionObserver *observer, void(*safeDeleter)(IRtcConnectionObserver *)=NULL)=0
agora::rtc::RtcConnectionConfiguration
Definition: NGIAgoraRtcConnection.h:106
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::RtcConnectionConfiguration::maxPort
int maxPort
Definition: NGIAgoraRtcConnection.h:136
agora::rtc::INetworkObserver::onUplinkNetworkInfoUpdated
virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:796
agora::rtc::TConnectionInfo::localUserId
util::AString localUserId
Definition: NGIAgoraRtcConnection.h:40
agora::rtc::IRtcConnection
Definition: NGIAgoraRtcConnection.h:182
agora::util::CopyableAutoPtr
Definition: AgoraBase.h:155
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::IRtcConnectionObserver::onSnapshotTaken
virtual void onSnapshotTaken(const char *channel, uid_t uid, const char *filePath, int width, int height, int errCode)
snapshot taken callback
Definition: NGIAgoraRtcConnection.h:680
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:618
agora::rtc::RtcConnectionConfiguration::maxSendBitrate
int maxSendBitrate
Definition: NGIAgoraRtcConnection.h:128
agora::rtc::AudioSubscriptionOptions::numberOfChannels
size_t numberOfChannels
Definition: NGIAgoraRtcConnection.h:94
agora::rtc::TConnectionInfo::internalUid
uid_t internalUid
Definition: NGIAgoraRtcConnection.h:44
agora::rtc::TConnectionInfo::id
conn_id_t id
Definition: NGIAgoraRtcConnection.h:28