Skip to content

Commit

Permalink
feat. add start & update & stop & remove channelMediaDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrixbirds committed Aug 22, 2019
1 parent c98af77 commit e77beaf
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 165 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* `mediaRelayStateChanged`, `receivedChannelMediaRelay`
- new apis:
* `switchChannel` switch to specified channel
* `startChannelMediaRelay`, `updateChannelMediaRelay`, `stopChannelMediaRelay` relay media streams operation for across channels.
* `startChannelMediaRelay`, `updateChannelMediaRelay`, `stopChannelMediaRelay`, `removeChannelMediaRelay` relay media streams operation for across channels.

#### 2.8.0-alpha.1
- add `string uid` api support
Expand Down
245 changes: 143 additions & 102 deletions android/src/main/java/com/syan/agora/AgoraModule.java

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions ios/RCTAgora/AgoraConst.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ + (instancetype)share {
AGTokenPrivilegeWillExpire,
AGRequestToken,

AGLocalAudioStateChanged,
AGRemoteAudioStateChanged,
AGLocalAudioStats,
AGAudioVolumeIndication,
AGActiveSpeaker,
AGFirstLocalAudioFrame,
Expand All @@ -70,6 +67,11 @@ + (instancetype)share {
AGLocalVideoStats,
AGRemoteVideoStats,
AGRemoteAudioStats,
AGLocalAudioStateChanged,
AGRemoteAudioStateChanged,
AGLocalAudioStats,
AGMediaRelayStateChanged,
AGReceivedChannelMediaRelay,

AGAudioMixingStateChanged,
AGRemoteAudioMixingStart,
Expand All @@ -85,9 +87,6 @@ + (instancetype)share {
AGReceiveStreamMessage,
AGOccurStreamMessageError,

AGReceivedChannelMediaRelay,
AGMediaRelayStateChanged,

AGMediaEngineLoaded,
AGMediaEngineStartCall,
AGIntervalTest,
Expand Down
116 changes: 74 additions & 42 deletions ios/RCTAgora/RCTAgora.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,21 @@ - (NSDictionary *)constantsToExport {
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
AgoraChannelMediaRelayConfiguration *config = [[AgoraChannelMediaRelayConfiguration alloc] init];

AgoraChannelMediaRelayInfo *src = [config sourceInfo];
NSDictionary *srcOption = options[@"src"];
src.channelName = srcOption[@"channelName"];
src.uid = [srcOption[@"uid"] integerValue];
src.token = srcOption[@"token"];
AgoraChannelMediaRelayInfo *dst = [[AgoraChannelMediaRelayInfo alloc] init];
NSDictionary *dstOption = options[@"dst"];
dst.channelName = dstOption[@"channelName"];
dst.uid = [dstOption[@"uid"] integerValue];
dst.token = dstOption[@"token"];
[config setDestinationInfo:dst forChannelName:dstOption[@"channelName"]];
if (srcOption != nil) {
src.channelName = srcOption[@"channelName"];
src.uid = [srcOption[@"uid"] integerValue];
src.token = srcOption[@"token"];
}
NSArray *channels = options[@"channels"];
for (NSDictionary *channel in channels) {
AgoraChannelMediaRelayInfo *dst = [[AgoraChannelMediaRelayInfo alloc] init];
dst.channelName = channel[@"channelName"];
dst.uid = [channel[@"uid"] integerValue];
dst.token = channel[@"token"];
[config setDestinationInfo:dst forChannelName:dst.channelName];
}
NSInteger res = [self.rtcEngine startChannelMediaRelay:config];
if (res == 0) {
resolve(nil);
Expand All @@ -343,18 +346,47 @@ - (NSDictionary *)constantsToExport {
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
AgoraChannelMediaRelayConfiguration *config = [[AgoraChannelMediaRelayConfiguration alloc] init];

AgoraChannelMediaRelayInfo *src = [config sourceInfo];
NSDictionary *srcOption = options[@"src"];
src.channelName = srcOption[@"channelName"];
src.uid = [srcOption[@"uid"] integerValue];
src.token = srcOption[@"token"];
AgoraChannelMediaRelayInfo *dst = [[AgoraChannelMediaRelayInfo alloc] init];
NSDictionary *dstOption = options[@"dst"];
dst.channelName = dstOption[@"channelName"];
dst.uid = [dstOption[@"uid"] integerValue];
dst.token = dstOption[@"token"];
[config setDestinationInfo:dst forChannelName:dstOption[@"channelName"]];
if (srcOption != nil) {
src.channelName = srcOption[@"channelName"];
src.uid = [srcOption[@"uid"] integerValue];
src.token = srcOption[@"token"];
}
NSArray *channels = options[@"channels"];
for (NSDictionary *channel in channels) {
AgoraChannelMediaRelayInfo *dst = [[AgoraChannelMediaRelayInfo alloc] init];
dst.channelName = channel[@"channelName"];
dst.uid = [channel[@"uid"] integerValue];
dst.token = channel[@"token"];
[config setDestinationInfo:dst forChannelName:dst.channelName];
}
NSInteger res = [self.rtcEngine updateChannelMediaRelay:config];
if (res == 0) {
resolve(nil);
} else {
reject(@(-1).stringValue, @(res).stringValue, nil);
}
}

// removeChannelMediaRelay
RCT_EXPORT_METHOD(removeChannelMediaRelay:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
AgoraChannelMediaRelayConfiguration *config = [[AgoraChannelMediaRelayConfiguration alloc] init];
AgoraChannelMediaRelayInfo *src = [config sourceInfo];
NSDictionary *srcOption = options[@"src"];
if (srcOption != nil) {
src.channelName = srcOption[@"channelName"];
src.uid = [srcOption[@"uid"] integerValue];
src.token = srcOption[@"token"];
}
NSArray *channels = options[@"channels"];
for (NSDictionary *channel in channels) {
if (channel[@"channelName"] != nil) {
[config removeDestinationInfoForChannelName:channel[@"channelName"]];
}
}
NSInteger res = [self.rtcEngine updateChannelMediaRelay:config];
if (res == 0) {
resolve(nil);
Expand Down Expand Up @@ -407,9 +439,9 @@ - (NSDictionary *)constantsToExport {
AgoraUserInfo *info = [self.rtcEngine getUserInfoByUid:uid withError:&code];
if ((int)code == 0) {
resolve(@{
@"uid": @(info.uid),
@"userAccount": info.userAccount
});
@"uid": @(info.uid),
@"userAccount": info.userAccount
});
} else {
reject(@(-1).stringValue, @((int)code).stringValue, nil);
}
Expand Down Expand Up @@ -1864,10 +1896,10 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRegisteredLocalUser:(NS

- (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
@"uid": @(uid),
@"peer": @{
@"uid": @(userInfo.uid),
@"userAccount": userInfo.userAccount
}}];
}

Expand Down Expand Up @@ -1912,26 +1944,26 @@ - (void)rtcEngineRequestToken:(AgoraRtcEngineKit *_Nonnull)engine {

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioStateChange:(AgoraAudioLocalState)state error:(AgoraAudioLocalError)error {
[self sendEvent:AGLocalAudioStateChanged params:@{
@"state": @(state),
@"errorCode": @(error)
}];
@"state": @(state),
@"errorCode": @(error)
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteAudioStateChangedOfUid:(NSUInteger)uid state:(AgoraAudioRemoteState)state reason:(AgoraAudioRemoteStateReason)reason elapsed:(NSInteger)elapsed {
[self sendEvent:AGRemoteAudioStateChanged params:@{
@"uid": @(uid),
@"state": @(state),
@"reason": @(reason),
@"elapsed": @(elapsed)
}];
@"uid": @(uid),
@"state": @(state),
@"reason": @(reason),
@"elapsed": @(elapsed)
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioStats:(AgoraRtcLocalAudioStats *_Nonnull)stats {
[self sendEvent:AGLocalAudioStats params:@{
@"numChannels": @(stats.numChannels),
@"sentSampleRate": @(stats.sentSampleRate),
@"sentBitrate": @(stats.sentBitrate),
}];
@"numChannels": @(stats.numChannels),
@"sentSampleRate": @(stats.sentSampleRate),
@"sentBitrate": @(stats.sentBitrate),
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioVolumeIndicationOfSpeakers:(NSArray<AgoraRtcAudioVolumeInfo*> *_Nonnull)speakers totalVolume:(NSInteger)totalVolume {
Expand Down Expand Up @@ -2193,13 +2225,13 @@ - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine channelMediaRelayStateDidC
[self sendEvent:AGMediaRelayStateChanged params:@{
@"state": @(state),
@"errorCode": @(error),
}];
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didReceiveChannelMediaRelayEvent:(AgoraChannelMediaRelayEvent)event {
[self sendEvent:AGReceivedChannelMediaRelay params:@{
@"event": @(event),
}];
@"event": @(event),
}];
}

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData *_Nonnull)data {
Expand Down
41 changes: 37 additions & 4 deletions lib/RtcEngine.native.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Option, Callback, AgoraUserInfo, AudioMixingOption, PlayEffectOption, AudioRecordingOption, AudioFrameOption, MixedAudioFrameOption, ImageOption, VideoStreamOption, DefaultVideoStreamOption, InjectStreamOption, RemoveInjectStreamOption, PublishStreamOption, RemovePublishStreamOption, LiveTranscodingOption, PositionOption, BeautyOption, LastmileProbeConfig, CameraCapturerConfiguration } from "./types";
import { Option, Callback, AgoraUserInfo, AudioMixingOption, PlayEffectOption, AudioRecordingOption, AudioFrameOption, MixedAudioFrameOption, ImageOption, VideoStreamOption, DefaultVideoStreamOption, InjectStreamOption, RemoveInjectStreamOption, PublishStreamOption, RemovePublishStreamOption, LiveTranscodingOption, PositionOption, BeautyOption, LastmileProbeConfig, CameraCapturerConfiguration, ChannelMediaConfiguration } from "./types";
/**
* RtcEngine is the javascript object for control agora native sdk through react native bridge.
*
Expand Down Expand Up @@ -46,9 +46,42 @@ declare class RtcEngine {
* @param token
*/
static switchChannel(channelName: string, token?: string): Promise<any>;
static startChannelMediaRelay(): void;
static updateChannelMediaRelay(): void;
static stopChannelMediaRelay(): void;
/**
* Starts to relay media streams across channels.
*
* This method will start relay media stream across specified channels. (maximum support 4 channels)
* It will occurs event:
* Occurs onChannelMediaRelayStateChanged
* @param config
*/
static startChannelMediaRelay(config: ChannelMediaConfiguration): Promise<any>;
/**
* Remove to relay media streams across channels.
*
* This method will remove & update relay media stream across specified channels. (maximum support relay 4 channels)
* It will occurs event:
* Occurs onChannelMediaRelayStateChanged
* @param config
*/
static removeChannelMediaRelay(config: ChannelMediaConfiguration): Promise<any>;
/**
* Updates to relay media streams across channels.
*
* This method will update relay media stream across specified channels. (maximum support 4 channels)
* It will occurs event:
* Occurs onChannelMediaRelayStateChanged
* @param config
*/
static updateChannelMediaRelay(config: ChannelMediaConfiguration): Promise<any>;
/**
* Stop to relay media streams across channels.
*
* This method will stop relay media stream across specified channels.
* It will occurs event:
* Occurs onChannelMediaRelayStateChanged
* @param config
*/
static stopChannelMediaRelay(): Promise<any>;
/**
* Registers a user account.
*
Expand Down
42 changes: 40 additions & 2 deletions lib/RtcEngine.native.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/RtcEngine.native.js.map

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
import { ViewProps } from 'react-native';
/**
* ChannelMediaInfo
* @property channelName: string
* @property token: string
* @property uid: number
*/
export interface ChannelMediaInfo {
channelName: string;
token?: string;
uid?: number;
}
/**
* ChannelMediaConfiguration
* @property src: {
* @member channelName,
* @member token,
* @member uid,
* }
* @property channels: {@link Array<ChannelMediaInfo>}
*/
export interface ChannelMediaConfiguration {
src?: {
channelName: string;
token?: string;
uid?: number;
};
channels: Array<ChannelMediaInfo>;
}
/**
* AgoraViewMode
* @mode hidden Uniformly scale the video until it fills the visible boundaries (cropped). One dimension of the video may have clipped contents.
Expand Down
2 changes: 1 addition & 1 deletion lib/types.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e77beaf

Please sign in to comment.