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 
433  virtual int enableEncryption(bool enabled, const EncryptionConfig& config) = 0;
434 
448  virtual int sendCustomReportMessage(const char* id, const char* category, const char* event, const char* label, int value) = 0;
460  virtual int getUserInfoByUserAccount(const char* userAccount, rtc::UserInfo* userInfo) = 0;
472  virtual int getUserInfoByUid(uid_t uid, rtc::UserInfo* userInfo) = 0;
473 };
474 
479  public:
480  virtual ~IRtcConnectionObserver() {}
481 
488  virtual void onConnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
489 
496  virtual void onDisconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
497 
504  virtual void onConnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
505 
512  virtual void onReconnecting(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
513 
514  // This should be deleted. onConnected is enough.
515  virtual void onReconnected(const TConnectionInfo& connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason) = 0;
516 
522  virtual void onConnectionLost(const TConnectionInfo& connectionInfo) = 0;
523 
531  virtual void onLastmileQuality(const QUALITY_TYPE quality) = 0;
532 
540  virtual void onLastmileProbeResult(const LastmileProbeResult& result) = 0;
541 
552  virtual void onTokenPrivilegeWillExpire(const char* token) = 0;
553 
560  virtual void onTokenPrivilegeDidExpire() = 0;
561 
568  virtual void onConnectionFailure(const TConnectionInfo& connectionInfo,
569  CONNECTION_CHANGED_REASON_TYPE reason) = 0;
570 
578  virtual void onUserJoined(user_id_t userId) = 0;
579 
588  virtual void onUserLeft(user_id_t userId, USER_OFFLINE_REASON_TYPE reason) = 0;
589 
597  virtual void onTransportStats(const RtcStats& stats) = 0;
598 
605  virtual void onChangeRoleSuccess(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
606  (void)oldRole;
607  (void)newRole;
608  }
609 
613  virtual void onChangeRoleFailure() {}
614 
625  virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality,
626  QUALITY_TYPE rxQuality) {
627  (void)userId;
628  (void)txQuality;
629  (void)rxQuality;
630  }
631 
635  virtual void onNetworkTypeChanged(NETWORK_TYPE type) {
636  (void)type;
637  }
638 
647  virtual void onApiCallExecuted(int err, const char* api, const char* result) {
648  (void)err;
649  (void)api;
650  (void)result;
651  }
652 
658  virtual void onError(ERROR_CODE_TYPE error, const char* msg) {
659  (void)error;
660  (void)msg;
661  }
662 
668  virtual void onWarning(WARN_CODE_TYPE warning, const char* msg) {
669  (void)warning;
670  (void)msg;
671  }
672 
702  virtual void onChannelMediaRelayStateChanged(int state, int code) = 0;
703 
709  virtual void onLocalUserRegistered(uid_t uid, const char* userAccount) {
710  (void)uid;
711  (void)userAccount;
712  }
713 
715  virtual void onUserAccountUpdated(uid_t uid, const char* userAccount){
716  (void)uid;
717  (void)userAccount;
718  }
719 
729  virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed,
730  int cached) {
731  (void)userId;
732  (void)streamId;
733  (void)code;
734  (void)missed;
735  (void)cached;
736  }
737 
742  virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType) {
743  (void)errorType;
744  }
745 };
746 
748  public:
749  virtual ~INetworkObserver() {}
750 
751  public:
760  virtual void onUplinkNetworkInfoUpdated(const UplinkNetworkInfo& info) {
761  (void)info;
762  }
763 
772  (void)info;
773  }
774 };
775 
776 } // namespace rtc
777 } // namespace agora
agora::rtc::IRtcConnectionObserver::onUserNetworkQuality
virtual void onUserNetworkQuality(user_id_t userId, QUALITY_TYPE txQuality, QUALITY_TYPE rxQuality)
Definition: NGIAgoraRtcConnection.h:625
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:4790
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:3522
agora::rtc::IRtcConnection::getConnectionInfo
virtual TConnectionInfo getConnectionInfo()=0
agora::rtc::IRtcConnectionObserver::onEncryptionError
virtual void onEncryptionError(ENCRYPTION_ERROR_TYPE errorType)
Definition: NGIAgoraRtcConnection.h:742
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:658
agora::rtc::IRtcConnectionObserver::onConnecting
virtual void onConnecting(const TConnectionInfo &connectionInfo, CONNECTION_CHANGED_REASON_TYPE reason)=0
agora::base::IAgoraParameter
Definition: IAgoraParameter.h:176
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:119
agora::rtc::LastmileProbeConfig
Definition: AgoraBase.h:3448
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:747
agora::rtc::IRtcConnectionObserver
Definition: NGIAgoraRtcConnection.h:478
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:715
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:613
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:709
agora::rtc::IRtcConnectionObserver::onStreamMessageError
virtual void onStreamMessageError(user_id_t userId, int streamId, int code, int missed, int cached)
Definition: NGIAgoraRtcConnection.h:729
agora::rtc::IRtcConnection::getLocalUser
virtual ILocalUser * getLocalUser()=0
agora::rtc::INetworkObserver::onDownlinkNetworkInfoUpdated
virtual void onDownlinkNetworkInfoUpdated(const DownlinkNetworkInfo &info)
Definition: NGIAgoraRtcConnection.h:771
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: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:635
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:668
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:647
agora::rtc::EncryptionConfig
Definition: AgoraBase.h:4706
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:2050
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:760
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:605
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