Skip to content

Commit

Permalink
feat: renderMode and mirrorMode
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 16, 2024
1 parent 57442de commit 11b042b
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 154 deletions.
6 changes: 6 additions & 0 deletions packages/rtc/src/base/DefaultValue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as NATIVE_RTC from '@iris/native-rtc';
import { VideoPlayerConfig } from 'agora-rtc-sdk-ng';

export const defaultLeaveChannelOptions: NATIVE_RTC.LeaveChannelOptions = {
stopAudioMixing: true,
stopAllEffect: true,
stopMicrophoneRecording: true,
};

export const defaultVideoPlayerConfig: VideoPlayerConfig = {
fit: 'cover',
mirror: false,
};
63 changes: 47 additions & 16 deletions packages/rtc/src/binding/IAgoraRtcEngineDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3372,34 +3372,65 @@ export class IRtcEngineDispatch implements IRtcEngine {

// @ts-ignore
setLocalRenderMode_cfb201b(apiParam: ApiParam): CallApiReturnType {
AgoraConsole.warn(
'RtcEngine_setLocalRenderMode_cfb201b not supported in this platform!'
);
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
let obj = JSON.parse(apiParam.data) as any;
let renderMode = obj.renderMode;
if (renderMode === undefined) {
AgoraConsole.error('renderMode is undefined');
throw 'renderMode is undefined';
}
let mirrorMode = obj.mirrorMode;
if (mirrorMode === undefined) {
AgoraConsole.error('mirrorMode is undefined');
throw 'mirrorMode is undefined';
}

return this._impl.setLocalRenderMode_cfb201b(renderMode, mirrorMode);
}

// @ts-ignore
setRemoteRenderMode_6771ce0(apiParam: ApiParam): CallApiReturnType {
AgoraConsole.warn(
'RtcEngine_setRemoteRenderMode_6771ce0 not supported in this platform!'
);
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
let obj = JSON.parse(apiParam.data) as any;
let uid = obj.uid;
if (uid === undefined) {
AgoraConsole.error('uid is undefined');
throw 'uid is undefined';
}
let renderMode = obj.renderMode;
if (renderMode === undefined) {
AgoraConsole.error('renderMode is undefined');
throw 'renderMode is undefined';
}
let mirrorMode = obj.mirrorMode;
if (mirrorMode === undefined) {
AgoraConsole.error('mirrorMode is undefined');
throw 'mirrorMode is undefined';
}

return this._impl.setRemoteRenderMode_6771ce0(uid, renderMode, mirrorMode);
}

// @ts-ignore
setLocalRenderMode_bedb5ae(apiParam: ApiParam): CallApiReturnType {
AgoraConsole.warn(
'RtcEngine_setLocalRenderMode_bedb5ae not supported in this platform!'
);
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
let obj = JSON.parse(apiParam.data) as any;
let renderMode = obj.renderMode;
if (renderMode === undefined) {
AgoraConsole.error('renderMode is undefined');
throw 'renderMode is undefined';
}

return this._impl.setLocalRenderMode_bedb5ae(renderMode);
}

// @ts-ignore
setLocalVideoMirrorMode_b8a6c69(apiParam: ApiParam): CallApiReturnType {
AgoraConsole.warn(
'RtcEngine_setLocalVideoMirrorMode_b8a6c69 not supported in this platform!'
);
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
let obj = JSON.parse(apiParam.data) as any;
let mirrorMode = obj.mirrorMode;
if (mirrorMode === undefined) {
AgoraConsole.error('mirrorMode is undefined');
throw 'mirrorMode is undefined';
}

return this._impl.setLocalVideoMirrorMode_b8a6c69(mirrorMode);
}

// @ts-ignore
Expand Down
30 changes: 27 additions & 3 deletions packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,34 @@ export class IRtcEngineExDispatch extends IRtcEngineDispatch

// @ts-ignore
setRemoteRenderModeEx_a72fe4e(apiParam: ApiParam): CallApiReturnType {
AgoraConsole.warn(
'RtcEngineEx_setRemoteRenderModeEx_a72fe4e not supported in this platform!'
let obj = JSON.parse(apiParam.data) as any;
let uid = obj.uid;
if (uid === undefined) {
AgoraConsole.error('uid is undefined');
throw 'uid is undefined';
}
let renderMode = obj.renderMode;
if (renderMode === undefined) {
AgoraConsole.error('renderMode is undefined');
throw 'renderMode is undefined';
}
let mirrorMode = obj.mirrorMode;
if (mirrorMode === undefined) {
AgoraConsole.error('mirrorMode is undefined');
throw 'mirrorMode is undefined';
}
let connection = obj.connection;
if (connection === undefined) {
AgoraConsole.error('connection is undefined');
throw 'connection is undefined';
}

return this._impl.setRemoteRenderModeEx_a72fe4e(
uid,
renderMode,
mirrorMode,
connection
);
return this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
}

// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions packages/rtc/src/engine/IrisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class IrisClient {

addLocalAudioTrack(trackPackage: AudioTrackPackage) {
this.audioTrackPackages.push(trackPackage);
trackPackage.setIrisClient(this);
trackPackage.irisClient = this;
}

removeLocalAudioTrack(trackPackage: AudioTrackPackage) {
Expand All @@ -235,7 +235,7 @@ export class IrisClient {

setLocalVideoTrack(trackPackage: VideoTrackPackage) {
this.videoTrackPackage = trackPackage;
trackPackage.setIrisClient(this);
trackPackage.irisClient = this;
}

clearLocalVideoTrack() {
Expand Down
66 changes: 8 additions & 58 deletions packages/rtc/src/engine/IrisClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IRemoteAudioTrack,
IRemoteVideoTrack,
ITrack,
VideoPlayerConfig,
} from 'agora-rtc-sdk-ng';

import {
Expand All @@ -18,6 +19,7 @@ import {
IrisVideoFrameBufferConfig,
VideoParams,
} from '../base/BaseType';
import { defaultVideoPlayerConfig } from '../base/DefaultValue';
import { IrisTrackEventHandler } from '../event_handler/IrisTrackEventHandler';

import { IrisClient } from './IrisClient';
Expand All @@ -29,36 +31,22 @@ export type WalkILocalVideoPackageTrackFun = (track: VideoTrackPackage) => void;
export class RemoteUserPackage {
connection: NATIVE_RTC.RtcConnection;
element: string;
videoPlayerConfig: VideoPlayerConfig;
uid: number;
videoSourceType: NATIVE_RTC.VIDEO_SOURCE_TYPE;
audioSourceType: IrisAudioSourceType;

constructor(
connection: NATIVE_RTC.RtcConnection,
element: string,
videoPlayerConfig: VideoPlayerConfig = defaultVideoPlayerConfig,
uid: number,
videoSourceType: NATIVE_RTC.VIDEO_SOURCE_TYPE,
audioSourceType: IrisAudioSourceType
) {
this.connection = connection;
this.element = element;
this.uid = uid;
this.videoSourceType = videoSourceType;
this.audioSourceType = audioSourceType;
}

update({
element = this.element,
uid = this.uid,
videoSourceType = this.videoSourceType,
audioSourceType = this.audioSourceType,
}: {
element?: string;
uid?: number;
videoSourceType?: NATIVE_RTC.VIDEO_SOURCE_TYPE;
audioSourceType?: IrisAudioSourceType;
}) {
this.element = element;
this.videoPlayerConfig = videoPlayerConfig;
this.uid = uid;
this.videoSourceType = videoSourceType;
this.audioSourceType = audioSourceType;
Expand All @@ -69,39 +57,20 @@ export class RemoteUserPackage {

export class VideoTrackPackage {
element?: string;
videoPlayerConfig: VideoPlayerConfig;
type?: NATIVE_RTC.VIDEO_SOURCE_TYPE | NATIVE_RTC.EXTERNAL_VIDEO_SOURCE_TYPE;
track?: ILocalVideoTrack | IRemoteVideoTrack;
isPreview: boolean = false;
irisClient: IrisClient;

constructor(
element?: string,
videoPlayerConfig: VideoPlayerConfig = defaultVideoPlayerConfig,
type?: NATIVE_RTC.VIDEO_SOURCE_TYPE | NATIVE_RTC.EXTERNAL_VIDEO_SOURCE_TYPE,
track?: ILocalVideoTrack | IRemoteVideoTrack
) {
this.element = element;
this.type = type;
this.track = track;
}

setPreview(isPreview: boolean) {
this.isPreview = isPreview;
}

setIrisClient(irisClient: IrisClient) {
this.irisClient = irisClient;
}

update({
type = this.type,
track = this.track,
element = this.element,
}: {
type?: NATIVE_RTC.VIDEO_SOURCE_TYPE | NATIVE_RTC.EXTERNAL_VIDEO_SOURCE_TYPE;
track?: ILocalVideoTrack | IRemoteVideoTrack;
element?: string;
}) {
this.element = element;
this.videoPlayerConfig = videoPlayerConfig;
this.type = type;
this.track = track;
}
Expand Down Expand Up @@ -138,25 +107,6 @@ export class AudioTrackPackage {
this.track = track;
}

setIrisClient(irisClient: IrisClient) {
this.irisClient = irisClient;
}

update({
type = this.type,
track = this.track,
}: {
type?: IrisAudioSourceType;
track?:
| ILocalAudioTrack
| IRemoteAudioTrack
| IMicrophoneAudioTrack
| ILocalTrack;
}) {
this.type = type;
this.track = track;
}

dispose() {
try {
if (this.track) {
Expand Down
3 changes: 2 additions & 1 deletion packages/rtc/src/engine/IrisClientObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export class IrisClientObserver {
if (userPackage.element) {
this._engine.trackHelper.play(
user!.videoTrack as ITrack,
userPackage.element
userPackage.element,
userPackage.videoPlayerConfig
);
}
let param: IrisTrackEventHandlerParam = {
Expand Down
5 changes: 2 additions & 3 deletions packages/rtc/src/event_handler/IrisClientEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class IrisClientEventHandler {
userPackage = new RemoteUserPackage(
connection,
'',
undefined,
remoteUid,
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE,
IrisAudioSourceType.kAudioSourceTypeRemote
Expand All @@ -205,9 +206,7 @@ export class IrisClientEventHandler {
this.agoraRTCClient
);
} else {
userPackage.update({
uid: remoteUid,
});
userPackage.uid = remoteUid;
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/rtc/src/helper/ImplHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class ImplHelper {

if (!videoTrackPackage) {
videoTrackPackage = new VideoTrackPackage(
undefined,
undefined,
videoType,
videoTrack
Expand All @@ -111,7 +112,7 @@ export class ImplHelper {
videoTrackPackage
);
} else {
videoTrackPackage.update({ track: videoTrack });
videoTrackPackage.track = videoTrack;
}
let trackEventHandler: IrisTrackEventHandler = new IrisTrackEventHandler(
{
Expand Down Expand Up @@ -171,6 +172,7 @@ export class ImplHelper {

if (!videoTrackPackage) {
videoTrackPackage = new VideoTrackPackage(
undefined,
undefined,
videoType,
videoTrack
Expand All @@ -179,7 +181,7 @@ export class ImplHelper {
videoTrackPackage
);
} else {
videoTrackPackage.update({ track: videoTrack });
videoTrackPackage.track = videoTrack;
}

//设置屏幕共享特殊的事件
Expand Down
12 changes: 9 additions & 3 deletions packages/rtc/src/helper/TrackHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IMicrophoneAudioTrack,
IRemoteAudioTrack,
ITrack,
VideoPlayerConfig,
} from 'agora-rtc-sdk-ng';
import { CallIrisApiResult } from 'iris-web-core';

Expand All @@ -20,11 +21,16 @@ export class TrackHelper {
}

public play(
track: ITrack | IRemoteAudioTrack,
element?: string | HTMLElement
track: ITrack,
element?: string | HTMLElement,
config?: VideoPlayerConfig
): void {
try {
track?.play(element);
if (track.trackMediaType === 'video' && config) {
(track as ICameraVideoTrack)?.play(element!, config);
} else {
track?.play(element);
}
} catch (e) {
AgoraConsole.error(e);
Promise.resolve(
Expand Down
Loading

0 comments on commit 11b042b

Please sign in to comment.