Skip to content

Commit

Permalink
chore: UT (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: guoxianzhe <guoxianzhe@users.noreply.github.com>
  • Loading branch information
guoxianzhe and guoxianzhe authored Oct 24, 2023
1 parent 604c535 commit 1bb8fda
Show file tree
Hide file tree
Showing 25 changed files with 1,494 additions and 91 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# IRIS_WEB

## [0.1.2-dev.4](https://github.com/AgoraIO-Extensions/iris_web/compare/v0.1.2-dev.3...v0.1.2-dev.4) (2023-10-24)

## [0.1.2-dev.3](https://github.com/AgoraIO-Extensions/iris_web/compare/v0.1.2-dev.2...v0.1.2-dev.3) (2023-10-23)


### Features

* onNetworkQuality ([a27ed1d](https://github.com/AgoraIO-Extensions/iris_web/commit/a27ed1d61a0745f517a32d8c0f1572122947117a))

## [0.1.2-dev.3](https://github.com/AgoraIO-Extensions/iris_web/compare/v0.1.2-dev.2...v0.1.2-dev.3) (2023-10-23)


### Features

* onNetworkQuality ([a27ed1d](https://github.com/AgoraIO-Extensions/iris_web/commit/a27ed1d61a0745f517a32d8c0f1572122947117a))

## [0.1.2-dev.2](https://github.com/AgoraIO-Extensions/iris_web/compare/v0.1.2-dev.1...v0.1.2-dev.2) (2023-10-19)


Expand Down
4 changes: 2 additions & 2 deletions packages/fake/rtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iris-web-rtc-fake",
"version": "0.1.2-dev.2",
"version": "0.1.2-dev.4",
"description": "wait",
"main": "./index.ts",
"scripts": {
Expand All @@ -14,7 +14,7 @@
"dependencies": {
"@iris/native-rtc-binding": "workspace: *",
"agora-rtc-sdk-ng": "^4.18.2",
"@agoraio-extensions/agora-rtc-sdk-ng-fake": "latest",
"@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.6",
"iris-web-rtc": "workspace: *"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/fake/rtc/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ config = {
output: {
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
filename: `iris-web-rtc-fake_${pkg.version}.js`,
filename: `${pkg.name}_${pkg.version}.js`,
environment: {
arrowFunction: false,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rtc/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: Config = {
silent: true,
testEnvironment: 'jsdom',
testMatch: ['**/test/impl/*.[jt]s?(x)', '**/test/binding/*.[jt]s?(x)'],
setupFilesAfterEnv: ['./test/setup.ts'],
setupFilesAfterEnv: ['./test/setup.ts', 'jest-canvas-mock'],
};

export default config;
5 changes: 3 additions & 2 deletions packages/rtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iris-web-rtc",
"version": "0.1.2-dev.2",
"version": "0.1.2-dev.4",
"description": "wait",
"main": "./src/index.ts",
"scripts": {
Expand All @@ -16,9 +16,9 @@
"author": "AgoraIO-Extensions",
"license": "MIT",
"dependencies": {
"@agoraio-extensions/agora-rtc-sdk-ng-fake": "^1.0.6",
"@iris/native-rtc-binding": "workspace: *",
"agora-rtc-sdk-ng": "^4.18.2",
"@agoraio-extensions/agora-rtc-sdk-ng-fake": "latest",
"iris-web-core": "workspace: *"
},
"files": [
Expand All @@ -32,6 +32,7 @@
"clean-webpack-plugin": "^4.0.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^22.1.0",
"ts-jest": "^29.1.1",
Expand Down
16 changes: 14 additions & 2 deletions packages/rtc/src/binding/IAgoraRtcEngineExDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,20 @@ export class IRtcEngineEventHandlerEx extends IRtcEngineEventHandler {
newRole: CLIENT_ROLE_TYPE,
newRoleOptions: ClientRoleOptions
): void {
AgoraConsole.warn('onClientRoleChanged not supported in this platform!');
this._engine.returnResult(false, -ERROR_CODE_TYPE.ERR_NOT_SUPPORTED);
let _obj = {
connection,
oldRole,
newRole,
newRoleOptions,
};
let _json = JSON.stringify(_obj);
let _key = this.eventKey('onClientRoleChangedEx');

let eventParam = new IrisCore.EventParam(_key, _json, 0, '', [], [], 0);
AgoraConsole.log(
`onClientRoleChangedEx eventParam ${JSON.stringify(eventParam)}`
);
this.notifyEvent(eventParam);
}

onClientRoleChangeFailedEx(
Expand Down
4 changes: 3 additions & 1 deletion packages/rtc/src/engine/IrisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ export class IrisClient {
remoteUserPackage.connection?.channelId == this.connection?.channelId &&
remoteUserPackage.connection?.localUid == this.connection?.localUid
) {
this._engine.irisClientManager.remoteUserPackages.splice(i, 1);
this._engine.irisClientManager.removeRemoteUserPackage(
remoteUserPackage.uid
);
i--;
}
}
Expand Down
36 changes: 33 additions & 3 deletions packages/rtc/src/engine/IrisClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AgoraConsole } from '../util';

import { IrisClient } from './IrisClient';
import { IrisClientObserver } from './IrisClientObserver';
import { IrisRtcEngine } from './IrisRtcEngine';
import { IrisIntervalType, IrisRtcEngine } from './IrisRtcEngine';

export type WalkILocalVideoPackageTrackFun = (track: VideoTrackPackage) => void;

Expand Down Expand Up @@ -330,9 +330,32 @@ export class IrisClientManager {
})[0];
}

addRemoteUserPackage(remoteUserPackage: RemoteUserPackage) {
addRemoteUserPackage(
remoteUserPackage: RemoteUserPackage,
agoraRTCClient: IAgoraRTCClient
) {
this.remoteUserPackages.push(remoteUserPackage);
this.irisClientObserver.addRemoteUserPackageObserver(remoteUserPackage);
if (agoraRTCClient) {
let intervalFunction = setInterval(() => {
let stats = agoraRTCClient.getRemoteNetworkQuality();
let connection: NATIVE_RTC.RtcConnection = {
channelId: agoraRTCClient.channelName,
localUid: agoraRTCClient.uid as number,
};
this._engine.rtcEngineEventHandler.onNetworkQualityEx(
connection,
remoteUserPackage.uid as number,
stats[remoteUserPackage.uid].downlinkNetworkQuality,
stats[remoteUserPackage.uid].uplinkNetworkQuality
);
}, this._engine.globalState.networkQualityInterval);
this._engine.addIrisInterval(
IrisIntervalType.networkQuality,
intervalFunction,
remoteUserPackage.uid
);
}
}

removeRemoteUserPackage(uid: UID) {
Expand All @@ -342,6 +365,7 @@ export class IrisClientManager {
this.remoteUserPackages.splice(i, 1);
i--;
this.irisClientObserver.removeRemoteUserPackageObserver(userPackage);
this._engine.removeIrisIntervalByUid(uid);
userPackage.dispose();

break;
Expand Down Expand Up @@ -515,7 +539,11 @@ export class IrisClientManager {
agoraRTCClient: IAgoraRTCClient
) {
let track = bufferSourceAudioTrackPackage.track;
if (agoraRTCClient && agoraRTCClient.localTracks.indexOf(track) != -1) {
if (
agoraRTCClient &&
agoraRTCClient.localTracks &&
agoraRTCClient.localTracks.indexOf(track) != -1
) {
try {
await agoraRTCClient.unpublish(track);
AgoraConsole.log('unpublish success');
Expand All @@ -539,6 +567,7 @@ export class IrisClientManager {
let audioTrack = audioTrackPackage.track as ILocalAudioTrack;
if (
agoraRTCClient &&
agoraRTCClient.localTracks &&
agoraRTCClient.localTracks.indexOf(audioTrack) != -1
) {
try {
Expand Down Expand Up @@ -566,6 +595,7 @@ export class IrisClientManager {
let videoTrack = videoTrackPackage.track as ILocalVideoTrack;
if (
agoraRTCClient &&
agoraRTCClient.localTracks &&
agoraRTCClient.localTracks.indexOf(videoTrack) != -1
) {
try {
Expand Down
5 changes: 4 additions & 1 deletion packages/rtc/src/engine/IrisClientObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ export class IrisClientObserver {
}

//发布轨道必须保证该client的options满足条件,并且client已经加入频道,并且该轨道没有被发布过
if (irisClient.agoraRTCClient?.channelName) {
if (
irisClient.agoraRTCClient?.channelName &&
irisClient.agoraRTCClient.localTracks
) {
for (let i = 0; i < irisClient.agoraRTCClient.localTracks.length; i++) {
let localTrack = irisClient.agoraRTCClient.localTracks[i];
if (localTrack === publishTrack) {
Expand Down
41 changes: 36 additions & 5 deletions packages/rtc/src/engine/IrisRtcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { IrisClientManager } from './IrisClientManager';

export enum IrisIntervalType {
enableAudioVolumeIndication = 0,
networkQuality = 1,
}

export class IrisRtcEngine implements ApiInterceptor {
Expand All @@ -71,6 +72,7 @@ export class IrisRtcEngine implements ApiInterceptor {
public irisIntervalList: {
type: IrisIntervalType;
interval: NodeJS.Timeout;
uid: UID;
}[] = [];
public irisRtcErrorHandler: IrisRtcErrorHandler = new IrisRtcErrorHandler(
this
Expand Down Expand Up @@ -193,11 +195,15 @@ export class IrisRtcEngine implements ApiInterceptor {

public returnResult(
isSuccess: boolean = true,
code: number = NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK,
code?: number,
data: string = '{"result": 0}'
): Promise<CallIrisApiResult> {
if (!isSuccess && typeof code !== 'number') {
code = -NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED;
if (isSuccess) {
code = NATIVE_RTC.ERROR_CODE_TYPE.ERR_OK;
} else {
if (typeof code !== 'number') {
code = -NATIVE_RTC.ERROR_CODE_TYPE.ERR_FAILED;
}
}
return Promise.resolve(new CallIrisApiResult(code, data));
}
Expand All @@ -207,19 +213,44 @@ export class IrisRtcEngine implements ApiInterceptor {
await this.irisClientManager.release();
}

public addIrisInterval(type: IrisIntervalType, interval: NodeJS.Timeout) {
public addIrisInterval(
type: IrisIntervalType,
interval: NodeJS.Timeout,
uid: UID
) {
//如果添加的是远端用户的轮询,uid用远端的
//如果添加的是本地用户的轮询,uid固定为0
this.irisIntervalList.push({
type,
interval,
uid,
});
}

public getIrisIntervalByType(type: IrisIntervalType) {
this.irisIntervalList.filter((a) => type == a.type);
}

public removeIrisIntervalByUid(uid: UID) {
for (let i = 0; i < this.irisIntervalList.length; i++) {
let item = this.irisIntervalList[i];
if (item.uid == uid) {
item.interval && clearInterval(item.interval);
this.irisIntervalList.splice(i, 1);
break;
}
}
}

public removeIrisIntervalByType(type: IrisIntervalType) {
this.irisIntervalList.filter((a) => type != a.type);
for (let i = 0; i < this.irisIntervalList.length; i++) {
let item = this.irisIntervalList[i];
if (item.type == type) {
item.interval && clearInterval(item.interval);
this.irisIntervalList.splice(i, 1);
i--;
}
}
}

public clearIrisInterval() {
Expand Down
17 changes: 14 additions & 3 deletions packages/rtc/src/event_handler/IrisClientEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ export class IrisClientEventHandler {
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE,
IrisAudioSourceType.kAudioSourceTypeRemote
);
this._engine.irisClientManager.addRemoteUserPackage(userPackage);
this._engine.irisClientManager.addRemoteUserPackage(
userPackage,
this.agoraRTCClient
);
} else {
userPackage.update({
uid: user.uid,
Expand Down Expand Up @@ -444,8 +447,16 @@ export class IrisClientEventHandler {
}

onEventNetworkQuality(stats: NetworkQuality): void {
//不能对应 onNetworkQuality, 因为这里是得到自己的网络状况,而 onNetworkQuality 是别人的网络状况
//暂时没有找到对应的回调
let connection: NATIVE_RTC.RtcConnection = {
channelId: this.agoraRTCClient.channelName,
localUid: this.agoraRTCClient.uid as number,
};
this._engine.rtcEngineEventHandler.onNetworkQualityEx(
connection,
0,
stats.downlinkNetworkQuality,
stats.uplinkNetworkQuality
);
}

//todo 后边再做
Expand Down
2 changes: 1 addition & 1 deletion packages/rtc/src/helper/ImplHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ImplHelper {
let conf: ScreenVideoTrackInitConfig = this.generateScreenVideoTrackInitConfig();
let result = await this._engine.globalState.AgoraRTC.createScreenVideoTrack(
conf,
captureParams.captureAudio ? 'disable' : 'auto'
captureParams.captureAudio ? 'auto' : 'disable'
);
if (Array.isArray(result)) {
screenTrack = result;
Expand Down
4 changes: 2 additions & 2 deletions packages/rtc/src/impl/IAgoraMediaEngineImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ export class IMediaEngineImpl implements NATIVE_RTC.IMediaEngine {
let processFunc = async (): Promise<CallIrisApiResult> => {
if (this._engine.globalState.enabledVideo == false) {
AgoraConsole.error('call enableVideo(true) before startPreview');
return this._engine.returnResult(false);
return this._engine.returnResult();
}
if (!this._engine.globalState.pushVideoFrameEnabled) {
AgoraConsole.error(
'pushVideoFrameEnabled is disabled , call setExternalVideoSource first'
);
return this._engine.returnResult(false);
return this._engine.returnResult();
}
//创建custom track的html element
let irisContainer = this._engine.irisElement.getIrisElement();
Expand Down
8 changes: 7 additions & 1 deletion packages/rtc/src/impl/IAgoraRtcEngineExImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ export class IRtcEngineExImpl implements NATIVE_RTC.IRtcEngineEx {
canvas.uid,
NATIVE_RTC.VIDEO_SOURCE_TYPE.VIDEO_SOURCE_REMOTE
);
this._engine.irisClientManager.addRemoteUserPackage(userPackage);
let irisClient = this._engine.irisClientManager.getIrisClientByConnection(
connection
);
this._engine.irisClientManager.addRemoteUserPackage(
userPackage,
irisClient?.agoraRTCClient
);
}

return this._engine.returnResult();
Expand Down
Loading

0 comments on commit 1bb8fda

Please sign in to comment.