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  }
73  bool packetOnly;
85  uint32_t sampleRateHz;
86 };
87 
119  int minPort;
123  int maxPort;
131  CLIENT_ROLE_TYPE clientRoleType;
134  CHANNEL_PROFILE_TYPE channelProfile;
135 
140 
145 
147  : autoSubscribeAudio(true),
148  autoSubscribeVideo(true),
150  maxSendBitrate(-1),
151  minPort(0),
152  maxPort(0),
153  clientRoleType(CLIENT_ROLE_AUDIENCE),
154  channelProfile(CHANNEL_PROFILE_LIVE_BROADCASTING),
155  audioRecvMediaPacket(false),
156  videoRecvMediaPacket(false) {}
157 };
158 
170  protected:
171  ~IRtcConnection() {}
172 
173  public:
201  virtual int connect(const char* token, const char* channelId, user_id_t userId) = 0;
202 
214  virtual int disconnect() = 0;
215 
243  virtual int startLastmileProbeTest(const LastmileProbeConfig& config) = 0;
244 
251  virtual int stopLastmileProbeTest() = 0;
252 
262  virtual int renewToken(const char* token) = 0;
263 
272 
280  virtual ILocalUser* getLocalUser() = 0;
281 
294  virtual int getRemoteUsers(UserList& users) = 0;
295 
306  virtual int getUserInfo(user_id_t userId, agora::UserInfo& userInfo) = 0;
307 
316  virtual int registerObserver(IRtcConnectionObserver* observer, void(*safeDeleter)(IRtcConnectionObserver*) = NULL) = 0;
317 
327  virtual int unregisterObserver(IRtcConnectionObserver* observer) = 0;
328 
337  virtual int registerNetworkObserver(INetworkObserver* observer, void(*safeDeleter)(INetworkObserver*) = NULL) = 0;
338 
348  virtual int unregisterNetworkObserver(INetworkObserver* observer) = 0;
349 
357  virtual conn_id_t getConnId() = 0;
358 
367 
376 
396  virtual int createDataStream(int* streamId, bool reliable, bool ordered, bool sync) = 0;
397 
413  virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
414 
434  virtual int enableEncryption(bool enabled, const EncryptionConfig& config) = 0;
435 
449  virtual int sendCustomReportMessage(const char* id, const char* category, const char* event, const char* label, int value) = 0;
461  virtual int getUserInfoByUserAccount(const char* userAccount, rtc::UserInfo* userInfo) = 0;
473  virtual int getUserInfoByUid(uid_t uid, rtc::UserInfo* userInfo) = 0;
474 };
475 
480  public:
481  virtual ~IRtcConnectionObserver() {}
482 
489  virtual void onConnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
490 
497  virtual void onDisconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
498 
505  virtual void onConnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
506 
513  virtual void onReconnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
514 
515  // This should be deleted. onConnected is enough.
516  virtual void onReconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
517 
523  virtual void onConnectionLost(const TConnectionInfo& connectionInfo) = 0;
524 
532  virtual void onLastmileQuality(const QUALITY_TYPE quality) = 0;
533 
541  virtual void onLastmileProbeResult(const LastmileProbeResult& result) = 0;
542 
553  virtual void onTokenPrivilegeWillExpire(const char* token) = 0;
554 
561  virtual void onTokenPrivilegeDidExpire() = 0;
562 
569  virtual void onConnectionFailure(const TConnectionInfo& connectionInfo,
570  CONNECTION_CHANGED_REASON_TYPE reason) = 0;
571 
579  virtual void onUserJoined(user_id_t userId) = 0;
580 
589  virtual void onUserLeft(user_id_t userId, USER_OFFLINE_REASON_TYPE reason) = 0;
590 
598  virtual void onTransportStats(const RtcStats& stats) = 0;
599 
606  virtual void onChangeRoleSuccess(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
607  (void)oldRole;
608  (void)newRole;
609  }
610 
614  virtual void onChangeRoleFailure() {}
615 
626  virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality,
627  QUALITY_TYPE rxQuality) {
628  (void)userId;
629  (void)txQuality;
630  (void)rxQuality;
631  }
632 
636  virtual void onNetworkTypeChanged(NETWORK_TYPE type) {
637  (void)type;
638  }
639 
648  virtual void onApiCallExecuted(int err, const char* api, const char* result) {
649  (void)err;
650  (void)api;
651  (void)result;
652  }
653 
659  virtual void onError(ERROR_CODE_TYPE error, const char* msg) {
660  (void)error;
661  (void)msg;
662  }
663 
669  virtual void onWarning(WARN_CODE_TYPE warning, const char* msg) {
670  (void)warning;
671  (void)msg;
672  }
673 
703  virtual void onChannelMediaRelayStateChanged(int state, int code) = 0;
704 
710  virtual void onLocalUserRegistered(uid_t uid, const char* userAccount) {
711  (void)uid;
712  (void)userAccount;
713  }
714 
716  virtual void onUserAccountUpdated(uid_t uid, const char* userAccount){
717  (void)uid;
718  (void)userAccount;
719  }
720 
730  virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed,
731  int cached) {
732  (void)userId;
733  (void)streamId;
734  (void)code;
735  (void)missed;
736  (void)cached;
737  }
738 
743  virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType) {
744  (void)errorType;
745  }
746 };
747 
749  public:
750  virtual ~INetworkObserver() {}
751 
752  public:
761  virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo& info) {
762  (void)info;
763  }
764 
773  (void)info;
774  }
775 };
776 
777 } // namespace rtc
778 } // namespace agora
agora::rtc::IRtcConnectionObserver::onUserNetworkQuality
virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality, QUALITY_TYPE rxQuality)
Definition: NGIAgoraRtcConnection.h:626
agora::rtc::TConnectionInfo::state
CONNECTION_STATE_TYPE state
Definition: NGIAgoraRtcConnection.h:36
agora::rtc::RtcConnectionConfiguration::channelProfile
CHANNEL_PROFILE_TYPE channelProfile
Definition: NGIAgoraRtcConnection.h:134
agora::rtc::UserInfo
Definition: AgoraBase.h:4742
agora::rtc::AudioSubscriptionOptions::bytesPerSample
size_t bytesPerSample
Definition: NGIAgoraRtcConnection.h:77
agora::rtc::AudioSubscriptionOptions::sampleRateHz
uint32_t sampleRateHz
Definition: NGIAgoraRtcConnection.h:85
agora::rtc::LastmileProbeResult
Definition: AgoraBase.h:3513
agora::rtc::IRtcConnection::getConnectionInfo
virtual TConnectionInfo getConnectionInfo()=0
agora::rtc::IRtcConnectionObserver::onEncryptionError
virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType)
Definition: NGIAgoraRtcConnection.h:743
agora::rtc::RtcConnectionConfiguration::audioSubscriptionOptions
AudioSubscriptionOptions audioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:127
agora::rtc::IRtcConnectionObserver::onError
virtual void onError(ERROR_CODE_TYPE error, const char *msg)
Definition: NGIAgoraRtcConnection.h:659
agora::rtc::IRtcConnectionObserver::onConnecting
virtual void onConnecting(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::base::IAgoraParameter
Definition: IAgoraParameter.h:174
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:119
agora::rtc::LastmileProbeConfig
Definition: AgoraBase.h:3439
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:748
agora::rtc::IRtcConnectionObserver
Definition: NGIAgoraRtcConnection.h:479
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:99
agora::rtc::RtcConnectionConfiguration::audioRecvMediaPacket
bool audioRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:139
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:716
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:614
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:710
agora::rtc::IRtcConnectionObserver::onStreamMessageError
virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed, int cached)
Definition: NGIAgoraRtcConnection.h:730
agora::rtc::IRtcConnection::getLocalUser
virtual ILocalUser * getLocalUser()=0
agora::rtc::INetworkObserver::onDownlinkNetworkInfoUpdated
virtual void onDownlinkNetworkInfoUpdated(const DownlinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:772
agora::rtc::IRtcConnectionObserver::onChannelMediaRelayStateChanged
virtual void onChannelMediaRelayStateChanged(int state, int code)=0
agora::UserInfo
Definition: AgoraBase.h:1123
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:131
agora::rtc::IRtcConnection::enableEncryption
virtual int enableEncryption(bool enabled, const EncryptionConfig &config)=0
agora::rtc::RtcConnectionConfiguration::enableAudioRecordingOrPlayout
bool enableAudioRecordingOrPlayout
Definition: NGIAgoraRtcConnection.h:111
agora::rtc::IRtcConnectionObserver::onNetworkTypeChanged
virtual void onNetworkTypeChanged(NETWORK_TYPE type)
Definition: NGIAgoraRtcConnection.h:636
agora::rtc::IRtcConnectionObserver::onConnectionLost
virtual void onConnectionLost(const TConnectionInfo &connectionInfo)=0
agora::rtc::RtcConnectionConfiguration::videoRecvMediaPacket
bool videoRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:144
agora::rtc::IRtcConnectionObserver::onWarning
virtual void onWarning(WARN_CODE_TYPE warning, const char *msg)
Definition: NGIAgoraRtcConnection.h:669
agora::rtc::RtcConnectionConfiguration::autoSubscribeVideo
bool autoSubscribeVideo
Definition: NGIAgoraRtcConnection.h:105
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:648
agora::rtc::EncryptionConfig
Definition: AgoraBase.h:4658
agora::rtc::AudioSubscriptionOptions::packetOnly
bool packetOnly
Definition: NGIAgoraRtcConnection.h:73
agora::rtc::IRtcConnectionObserver::onLastmileQuality
virtual void onLastmileQuality(const QUALITY_TYPE quality)=0
agora::rtc::RtcStats
Definition: AgoraBase.h:2040
agora::rtc::IRtcConnection::registerObserver
virtual int registerObserver(IRtcConnectionObserver *observer, void(*safeDeleter)(IRtcConnectionObserver *)=NULL)=0
agora::rtc::RtcConnectionConfiguration
Definition: NGIAgoraRtcConnection.h:93
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::RtcConnectionConfiguration::maxPort
int maxPort
Definition: NGIAgoraRtcConnection.h:123
agora::rtc::INetworkObserver::onUplinkNetworkInfoUpdated
virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:761
agora::rtc::TConnectionInfo::localUserId
util::AString localUserId
Definition: NGIAgoraRtcConnection.h:40
agora::rtc::IRtcConnection
Definition: NGIAgoraRtcConnection.h:169
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::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:606
agora::rtc::RtcConnectionConfiguration::maxSendBitrate
int maxSendBitrate
Definition: NGIAgoraRtcConnection.h:115
agora::rtc::AudioSubscriptionOptions::numberOfChannels
size_t numberOfChannels
Definition: NGIAgoraRtcConnection.h:81
agora::rtc::TConnectionInfo::internalUid
uid_t internalUid
Definition: NGIAgoraRtcConnection.h:44
agora::rtc::TConnectionInfo::id
conn_id_t id
Definition: NGIAgoraRtcConnection.h:28