Skip to content

Commit

Permalink
chore. upgrade to 2.8.0
Browse files Browse the repository at this point in the history
feat. support new methods of 2.8.0
  • Loading branch information
Matrixbirds committed Aug 12, 2019
1 parent 62180de commit 14c44b4
Show file tree
Hide file tree
Showing 17 changed files with 442 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## THE CHANGELOG

#### 2.8.0-alpha.1
- add `string uid` api support
- android: deprecate `lowLatency` member of LiveTranscoding
- add methods `getUserInfoByUserAccount`, `getUserInfoByUid`, `joinChannelWithUserAccount`, `registerLocalUserAccount`
- add events `localUserRegistered`, `userInfoUpdated`
- android: upgrade native sdk to 2.8.2
- ios: upgrade native sdk to 2.8.0

#### 2.4.1-alpha.3
- refactor setLiveTranscoding: rename ios & android native parameters. export enum for javascript/typescript api.
- fix negative number case in android platform.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
def androidSupportVersion = rootProject.hasProperty("androidSupportVersion") ? rootProject.androidSupportVersion : DEFAULT_ANDROID_SUPPORT_VERSION
// from internet
implementation "com.android.support:appcompat-v7:$androidSupportVersion"
implementation "io.agora.rtc:full-sdk:2.4.1"
implementation "io.agora.rtc:full-sdk:2.8.2"
// from node_modules
implementation "com.facebook.react:react-native:+"
}
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/java/com/syan/agora/AgoraConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class AgoraConst {
public final static String AGRejoinChannelSuccess = "rejoinChannelSuccess";
public final static String AGLeaveChannel = "leaveChannel";
public final static String AGClientRoleChanged = "clientRoleChanged";
public final static String AGLocalUserRegistered = "localUserRegistered";
public final static String AGUserInfoUpdated = "userInfoUpdated";
public final static String AGUserJoined = "userJoined";
public final static String AGUserOffline = "userOffline";
public final static String AGConnectionStateChanged = "connectionStateChanged";
Expand Down
97 changes: 94 additions & 3 deletions android/src/main/java/com/syan/agora/AgoraModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.agora.rtc.internal.LastmileProbeConfig;
import io.agora.rtc.live.LiveInjectStreamConfig;
import io.agora.rtc.live.LiveTranscoding;
import io.agora.rtc.models.UserInfo;
import io.agora.rtc.video.AgoraImage;
import io.agora.rtc.video.BeautyOptions;
import io.agora.rtc.video.CameraCapturerConfiguration;
Expand Down Expand Up @@ -142,6 +143,9 @@ public class AgoraModule extends ReactContextBaseJavaModule {
private static final String AgoraAudioMode = "AudioMode";
private static final String AgoraVideoMode = "VideoMode";

private RtcEngine rtcEngine;
private String appId;

public AgoraModule(ReactApplicationContext context) {
super(context);
}
Expand Down Expand Up @@ -379,6 +383,35 @@ public void run() {
});
}

@Override
public void onLocalUserRegistered(final int uid, final String userAccount) {
runOnUiThread(new Runnable() {
@Override
public void run() {
WritableMap map = Arguments.createMap();
map.putInt("uid", uid);
map.putString("userAccount", userAccount);
sendEvent(getReactApplicationContext(), AGLocalUserRegistered, map);
}
});
}

@Override
public void onUserInfoUpdated(final int uid, final UserInfo peer) {
runOnUiThread(new Runnable() {
@Override
public void run() {
WritableMap map = Arguments.createMap();
map.putInt("uid", uid);
WritableMap peerInfo = Arguments.createMap();
peerInfo.putInt("uid", peer.uid);
peerInfo.putString("userAccount", peer.userAccount);
map.putMap("peer", peerInfo);
sendEvent(getReactApplicationContext(), AGUserInfoUpdated, map);
}
});
}

@Override
public void onUserJoined(final int uid, final int elapsed) {
runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -775,6 +808,11 @@ public void run() {
statsMap.putInt("networkTransportDelay", stats.networkTransportDelay);
statsMap.putInt("jitterBufferDelay", stats.jitterBufferDelay);
statsMap.putInt("audioLossRate", stats.audioLossRate);
statsMap.putInt("totalFrozenTime", stats.totalFrozenTime);
statsMap.putInt("frozenRate", stats.frozenRate);
statsMap.putInt("numChannels", stats.numChannels);
statsMap.putInt("receivedSampleRate", stats.receivedSampleRate);
statsMap.putInt("receivedBitrate", stats.receivedBitrate);
WritableMap map = Arguments.createMap();
map.putMap("stats", statsMap);
sendEvent(getReactApplicationContext(), AGRemoteAudioStats, map);
Expand Down Expand Up @@ -865,6 +903,8 @@ public void run() {
statsMap.putInt("receivedBitrate", stats.receivedBitrate);
statsMap.putInt("rendererOutputFrameRate", stats.rendererOutputFrameRate);
statsMap.putInt("rxStreamType", stats.rxStreamType);
statsMap.putInt("totalFrozenTime", stats.totalFrozenTime);
statsMap.putInt("frozenRate", stats.frozenRate);
WritableMap map = Arguments.createMap();
map.putMap("stats", statsMap);
sendEvent(getReactApplicationContext(), AGRemoteVideoStats, map);
Expand Down Expand Up @@ -1077,6 +1117,8 @@ public void run() {
@ReactMethod
public void init(ReadableMap options) {
AgoraManager.getInstance().init(getReactApplicationContext(), mRtcEventHandler, options);
appId = options.getString("appid");
rtcEngine = AgoraManager.getInstance().mRtcEngine;
}

@ReactMethod
Expand Down Expand Up @@ -1130,6 +1172,58 @@ public void joinChannel(ReadableMap options, Promise promise) {
}
}

@ReactMethod
public void registerLocalUserAccount(ReadableMap options, Promise promise) {
Integer res = rtcEngine.registerLocalUserAccount(appId, options.getString("userAccount"));
if (res == 0) {
promise.resolve(null);
} else {
promise.reject("-1", res.toString());
}
}

@ReactMethod
public void joinChannelWithUserAccount(ReadableMap options, Promise promise) {
String token = null;
if (options.hasKey("token")) {
token = options.getString("token");
}
Integer res = rtcEngine.joinChannelWithUserAccount(token, options.getString("channelName"), options.getString("userAccount"));
if (res == 0) {
promise.resolve(null);
} else {
promise.reject("-1", res.toString());
}
}

@ReactMethod
public void getUserInfoByUid(Integer uid, Promise promise) {
UserInfo info = new UserInfo();
Integer res = rtcEngine.getUserInfoByUid(uid, info);
if (res == 0) {
WritableMap map = Arguments.createMap();
map.putInt("uid", info.uid);
map.putString("userAccount", info.userAccount);
promise.resolve(map);
} else {
promise.reject("-1", res.toString());
}
}

@ReactMethod
public void getUserInfoByUserAccount(String userAccount, Promise promise) {
UserInfo info = new UserInfo();
Integer res = rtcEngine.getUserInfoByUserAccount(userAccount, info);
if (res == 0) {
WritableMap map = Arguments.createMap();
map.putInt("uid", info.uid);
map.putString("userAccount", info.userAccount);
promise.resolve(map);
} else {
promise.reject("-1", res.toString());
}
}

@ReactMethod
public void leaveChannel(Promise promise) {
Integer res = AgoraManager.getInstance().leaveChannel();
Expand Down Expand Up @@ -2018,9 +2112,6 @@ public void setLiveTranscoding(ReadableMap options, Promise promise) {
if (options.hasKey("videoFramerate")) {
transcoding.videoFramerate = options.getInt("videoFramerate");
}
if (options.hasKey("lowLatency")) {
transcoding.lowLatency = options.getBoolean("lowLatency");
}
if (options.hasKey("videoGop")) {
transcoding.videoGop = options.getInt("videoGop");
}
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTAgora/AgoraConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static NSString *AGJoinChannelSuccess = @"joinChannelSuccess";
static NSString *AGRejoinChannelSuccess = @"rejoinChannelSuccess";
static NSString *AGLeaveChannel = @"leaveChannel";
static NSString *AGClientRoleChanged = @"clientRoleChanged";
static NSString *AGLocalUserRegistered = @"localUserRegistered";
static NSString *AGUserInfoUpdated = @"userInfoUpdated";
static NSString *AGUserJoined = @"userJoined";
static NSString *AGUserOffline = @"userOffline";
static NSString *AGConnectionStateChanged = @"connectionStateChanged";
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTAgora/AgoraConst.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ + (instancetype)share {
AGRejoinChannelSuccess,
AGLeaveChannel,
AGClientRoleChanged,
AGLocalUserRegistered,
AGUserInfoUpdated,
AGUserJoined,
AGUserOffline,
AGConnectionStateChanged,
Expand Down
92 changes: 86 additions & 6 deletions ios/RCTAgora/RCTAgora.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@interface RCTAgora ()
@property (strong, nonatomic) AgoraRtcEngineKit *rtcEngine;
@property (strong, nonatomic) NSString *appId;
@property (strong, nonatomic) NSData *metadata;
@end

Expand Down Expand Up @@ -176,6 +177,7 @@ - (NSDictionary *)constantsToExport {
[AgoraConst share].appid = options[@"appid"];

self.rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:options[@"appid"] delegate:self];
self.appId = options[@"appid"];

[AgoraConst share].rtcEngine = self.rtcEngine;

Expand Down Expand Up @@ -299,6 +301,63 @@ - (NSDictionary *)constantsToExport {
}
}

// register user account
RCT_EXPORT_METHOD(registerLocalUserAccount:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
NSInteger res = [self.rtcEngine registerLocalUserAccount:options[@"userAccount"] appId:self.appId];
if (res == 0) {
resolve(nil);
} else {
reject(@(-1).stringValue, @(res).stringValue, nil);
}
}

// join channel with user account
RCT_EXPORT_METHOD(joinChannelWithUserAccount:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
NSString *token = [options objectForKey:@"token"] != nil ? options[@"token"] : nil;
NSInteger res = [self.rtcEngine joinChannelByUserAccount:options[@"userAccount"] token:token channelId:options[@"channelName"] joinSuccess:nil];
if (res == 0) {
resolve(nil);
} else {
reject(@(-1).stringValue, @(res).stringValue, nil);
}
}

// get user info by uid
RCT_EXPORT_METHOD(getUserInfoByUid:(NSUInteger)uid
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
AgoraErrorCode code = 0;
AgoraUserInfo *info = [self.rtcEngine getUserInfoByUid:uid withError:&code];
if ((int)code == 0) {
resolve(@{
@"uid": @(info.uid),
@"userAccount": info.userAccount
});
} else {
reject(@(-1).stringValue, @((int)code).stringValue, nil);
}
}

// get user info by user account
RCT_EXPORT_METHOD(getUserInfoByUserAccount:(NSString *)userAccount
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
AgoraErrorCode code = 0;
AgoraUserInfo *info = [self.rtcEngine getUserInfoByUserAccount:userAccount withError:&code];
if ((int)code == 0) {
resolve(@{
@"uid": @(info.uid),
@"userAccount": info.userAccount
});
} else {
reject(@(-1).stringValue, @((int)code).stringValue, nil);
}
}

// leave channel
RCT_EXPORT_METHOD(leaveChannel
:(RCTPromiseResolveBlock) resolve
Expand Down Expand Up @@ -1400,9 +1459,6 @@ - (NSDictionary *)constantsToExport {
if ([options objectForKey:@"videoFramerate"]) {
transcoding.videoFramerate = [options[@"videoFramerate"] integerValue];
}
if ([options objectForKey:@"lowLatancy"]) {
transcoding.lowLatency = [options[@"lowLatancy"] boolValue];
}
if ([options objectForKey:@"videoGop"]) {
transcoding.videoGop = [options[@"videoGop"] integerValue];
}
Expand Down Expand Up @@ -1714,6 +1770,23 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didJoinedOfUid:(NSUInteger
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRegisteredLocalUser:(NSString *_Nonnull)userAccount withUid:(NSUInteger)uid {
[self sendEvent:AGLocalUserRegistered params:@{
@"uid": @(uid),
@"userAccount": userAccount
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didUpdatedUserInfo:(AgoraUserInfo *_Nonnull)userInfo withUid:(NSUInteger)uid {
[self sendEvent:AGUserInfoUpdated params:@{
@"uid": @(uid),
@"peer": @{
@"uid": @(userInfo.uid),
@"userAccount": userInfo.userAccount
}}];
}


- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason {
[self sendEvent:AGUserOffline params:@{
@"uid": @(uid),
Expand Down Expand Up @@ -1905,7 +1978,12 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteAudioStats:(AgoraRtc
@"quality": @(stats.quality),
@"networkTransportDelay": @(stats.networkTransportDelay),
@"jitterBufferDelay": @(stats.jitterBufferDelay),
@"audioLossRate": @(stats.audioLossRate)
@"audioLossRate": @(stats.audioLossRate),
@"totalFrozenTime": @(stats.totalFrozenTime),
@"frozenRate": @(stats.frozenRate),
@"numChannels": @(stats.numChannels),
@"receivedSampleRate": @(stats.receivedSampleRate),
@"receivedBitrate": @(stats.receivedBitrate),
}
}];
}
Expand Down Expand Up @@ -1965,7 +2043,9 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteVideoStats:(AgoraRtc
@"receivedBitrate": @(stats.receivedBitrate),
@"rendererOutputFrameRate": @(stats.rendererOutputFrameRate),
@"rxStreamType": @(stats.rxStreamType),
@"decoderOutputFrameRate": @(stats.decoderOutputFrameRate)
@"decoderOutputFrameRate": @(stats.decoderOutputFrameRate),
@"totalFrozenTime": @(stats.totalFrozenTime),
@"frozenRate": @(stats.frozenRate)
}
}];
}
Expand Down Expand Up @@ -2106,4 +2186,4 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine lastmileProbeTestResult:(A
}];
}

@end
@end
Loading

0 comments on commit 14c44b4

Please sign in to comment.