Skip to content

Commit

Permalink
feat: support sdk v1.2.0.
Browse files Browse the repository at this point in the history
Overmind-id: OMNRTCG2-57214
  • Loading branch information
yanghui08 committed Jul 19, 2024
1 parent afd243c commit ad12953
Show file tree
Hide file tree
Showing 26 changed files with 127 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
{
"name": "app_name",
"value": "ohos_sample"
},
{
"name": "camera_auth_reason",
"value": "need to use camera"
},
{
"name": "microphone_auth_reason",
"value": "need to use microphone"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,41 @@

## SDK 接入流程

1.拷贝 sdk.har 到项目文件夹中,例如: entry/src/main/libs
### 线下集成

2.DEMO 工程下 oh-package.json5 配置 sdk.har 如下图所示:
1. 拷贝 sdk.har 到项目文件夹中,例如: entry/src/main/libs

2. DEMO 工程下 oh-package.json5 配置 sdk.har 如下图所示:

![WX20240222-105552.png](img%2FWX20240222-105552.png)

3.安装第三方包,点击 Run 'ohpm install'
3. 安装第三方包,点击 Run 'ohpm install'

### 依赖Openharmony仓库集成

1. Demo 工程下 oh-package.json5 配置

```json5
"dependencies": {
"@nertc/nertc_sdk": "1.1.0-beta"
}
```

2. 点击 Run 'ohpm install'

4.调用SDK相关接口,完成入会流程

调用SDK相关接口,完成入会流程

```typescript

//伪代码,具体实现参考 sample code

//从SDK中导入相关的interface或者class
//如果是线下集成的: import { NERtcSDK } from 'sdk'
//依赖openharmony仓库集成的: import { NERtcSDK } from '@nertc/nertc_sdk'
import { NERtcCallbackEx, NERtcConstants, NERtcSDK } from 'sdk';



//初始化引擎, 参数列表分别为: context: UIAbility Context 上下文对象, appkey, SDK回调callback, 初始化参数option(可选).
NERtcSDK.getInstance().init(context, key, new ChatCallback(), option)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": "4.1.0(11)",
"compatibleSdkVersion": "4.1.0(11)",
"targetSdkVersion": "4.1.0(11)",
//指定HarmonyOS应用/服务编译时的版本
"compatibleSdkVersion": "5.0.0(12)",
//指定HarmonyOS应用/服务兼容的最低版本。版本号需改为"5.0.0(12)",注意使用英文.和()
"targetSdkVersion": "5.0.0(12)",
//指定HarmonyOS应用/服务目标版本。若没有设置,默认为compatibleSdkVersion
"runtimeOS": "HarmonyOS"
//指定为HarmonyOS
}
],
"buildModeSet": [
Expand All @@ -17,6 +20,21 @@
{
"name": "release"
}
],
"signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "/Users/yanghui/.ohos/config/default_NERtcSample-GroupVideoCall-Harmony-Typescript_Nx_t0toQBuO8fzdTS9gVlufiDiyU5tVVTLpRNphn43E=.cer",
"storePassword": "0000001B8679A80097267B5C909804979972A1870E20694A7C1CAFD2C5A63DFB772D9F046BF5D387F51B78",
"keyAlias": "debugKey",
"keyPassword": "0000001BE40315DF50962AE7C9E0E173FA80F3A5836EBE3B6FDAF7F74883ACF2F17AD68E525F9525017F01",
"profile": "/Users/yanghui/.ohos/config/default_NERtcSample-GroupVideoCall-Harmony-Typescript_Nx_t0toQBuO8fzdTS9gVlufiDiyU5tVVTLpRNphn43E=.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "/Users/yanghui/.ohos/config/default_NERtcSample-GroupVideoCall-Harmony-Typescript_Nx_t0toQBuO8fzdTS9gVlufiDiyU5tVVTLpRNphn43E=.p12"
}
}
]
},
"modules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "",
"license": "",
"dependencies": {
'sdk': "file:./src/main/libs/nertc_sdk.har"
"@nertc/nertc_sdk": "1.1.0-beta"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import router from '@ohos.router';
import Delegate from '../../common/Delegate';
import { LoginInfo } from '../../common/Model'
import ChatPresenter from '../../common/Presenter'
import { NERtcStatsObserver, NERtcConstants} from 'sdk/Index';
import { NERtcStatsObserver, NERtcConstants} from '@nertc/nertc_sdk';
import prompt from '@ohos.promptAction';
let TAG: string = 'audioCall'

Expand Down Expand Up @@ -50,25 +50,37 @@ struct audioCall {
ChatPresenter.getInstance().join(this.login)
}
observer: NERtcStatsObserver = {

onRtcStats: (stats: NERtcConstants.NERtcStats): void => {

},

onLocalAudioStats: (stats: NERtcConstants.NERtcAudioSendStats): void => {

},

onRemoteAudioStats: (statsArray: Array<NERtcConstants.NERtcAudioRecvStats>): void => {

let volumeInfoTmp = ""
for(let i = 0;i < statsArray.length;i++){
volumeInfoTmp += "uid: " + statsArray[i].uid + " 音量: " + statsArray[i].layers[0].volume + "\n"
let layers = statsArray[i].layers
let volume: number = 0;
if(layers) {
volume = layers[0].volume
}
volumeInfoTmp += "uid: " + statsArray[i].uid + " 音量: " + volume + "\n"
}
this.volumeInfo = volumeInfoTmp;
},

onLocalVideoStats: (stats: NERtcConstants.NERtcVideoSendStats): void => {

},

onRemoteVideoStats: (statsArray: Array<NERtcConstants.NERtcVideoRecvStats>): void => {

},

onNetworkQuality: (statsArray: Array<NERtcConstants.NERtcNetworkQualityInfo>): void => {
let networkInfoTmp = ""
for(let i = 0;i < statsArray.length;i++){
Expand All @@ -78,6 +90,7 @@ struct audioCall {
}
this.networkInfo = networkInfoTmp;
}

}
delegate: Delegate = {
onJoin: (result: number, channelId: bigint): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NERtcConstants} from 'sdk';
import {NERtcConstants} from '@nertc/nertc_sdk';
import {LiveStreamEvent} from './Model'

export default interface Delegate {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NERtcCallbackEx, NERtcChannelCallback, NERtcConstants, NERtcSDK , NERtcStatsObserver} from 'sdk/Index';
import { NERtcCallbackEx, NERtcChannelCallback, NERtcConstants, NERtcSDK , NERtcStatsObserver} from '@nertc/nertc_sdk';
import Config from './Config';
import * as model from './Model';
import Delegate from './Delegate';
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class ChatPresenter {
join(login: model.LoginInfo): number {

this.login = login
let ret = NERtcConstants.ErrorCode.NO_ERROR
let ret: number = NERtcConstants.ErrorCode.NO_ERROR
if(login) {
ret = NERtcSDK.getInstance().joinChannel('', login?.cname, BigInt(login?.uid))
console.info(TAG, 'Join channel ret: ' + ret)
Expand All @@ -66,7 +66,7 @@ export default class ChatPresenter {
NERtcSDK.getInstance().setExternalSubStreamAudioSource(enable,sampleRate, channel)
}
pushExternalSubAudioFrame(uint8Array: Uint8Array, samplesPerChannel: number, sampleRate: number, channels: number, lastSyncTimestamp: bigint) {
let frame = new NERtcConstants.NERtcAudioExternalFrame()
let frame: NERtcConstants.NERtcAudioExternalFrame = new NERtcConstants.NERtcAudioExternalFrame()
frame.data = uint8Array
frame.sampleRate = sampleRate
frame.samplesPerChannel = samplesPerChannel
Expand All @@ -75,7 +75,7 @@ export default class ChatPresenter {
NERtcSDK.getInstance().pushExternalSubStreamAudioFrame(frame)
}
pushExternalAudioFrame(uint8Array: Uint8Array, samplesPerChannel: number, sampleRate: number, channels: number, lastSyncTimestamp: bigint) {
let frame = new NERtcConstants.NERtcAudioExternalFrame()
let frame: NERtcConstants.NERtcAudioExternalFrame = new NERtcConstants.NERtcAudioExternalFrame()
frame.data = uint8Array
frame.sampleRate = sampleRate
frame.samplesPerChannel = samplesPerChannel
Expand All @@ -87,23 +87,23 @@ export default class ChatPresenter {
let canvas: NERtcConstants.NERtcVideoCanvas = { canvasId: String(user.uid) }
let local = String(user.uid) === this.login?.uid
if(local) {
let ret = NERtcSDK.getInstance().setupLocalVideoCanvas(canvas)
let ret: number = NERtcSDK.getInstance().setupLocalVideoCanvas(canvas)
console.info(TAG, 'setLocalVideoCanvas ret:' + ret)
} else {
let ret = NERtcSDK.getInstance().setupRemoteVideoCanvas(canvas, user.uid)
let ret: number = NERtcSDK.getInstance().setupRemoteVideoCanvas(canvas, user.uid)
console.info(TAG, 'setupRemoteVideoCanvas ret:' + ret)
NERtcSDK.getInstance().subscribeRemoteVideo(user.uid, true, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain, NERtcConstants.NERtcRemoteVideoSubscribeType.kNERtcRemoteVideoSubscribeTypeHigh)
NERtcSDK.getInstance().subscribeRemoteVideo(user.uid, true, NERtcConstants.NERtcRemoteVideoSubscribeType.kNERtcRemoteVideoSubscribeTypeHigh)
}
}

attachSub(user: model.User) {
let canvas: NERtcConstants.NERtcVideoCanvas = { canvasId: String(user.uid + 'sub') }
let local = String(user.uid) === this.login?.uid
if(local) {
let ret = NERtcSDK.getInstance().setupLocalSubStreamVideoCanvas(canvas)
let ret: number = NERtcSDK.getInstance().setupLocalSubStreamVideoCanvas(canvas)
console.info(TAG, 'setupLocalSubStreamVideoCanvas ret:' + ret)
} else {
let ret = NERtcSDK.getInstance().setupRemoteSubStreamVideoCanvas(canvas, user.uid)
let ret: number = NERtcSDK.getInstance().setupRemoteSubStreamVideoCanvas(canvas, user.uid)
console.info(TAG, 'setupRemoteSubStreamVideoCanvas ret:' + ret)
NERtcSDK.getInstance().subscribeRemoteSubStreamVideo(user.uid, true)
}
Expand All @@ -113,59 +113,63 @@ export default class ChatPresenter {
NERtcSDK.getInstance().switchCamera()
}
enableVideo(enable: boolean) {
let ret = NERtcSDK.getInstance().enableLocalVideo(enable, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain)
let ret: number = NERtcSDK.getInstance().enableLocalVideo(enable, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain)
console.info(TAG, 'enableLocalVideo result:' + ret)
}
enableSubVideo(enable: boolean) {
let ret = NERtcSDK.getInstance().enableLocalVideo(enable, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeSub)
let ret: number = NERtcSDK.getInstance().enableLocalVideo(enable, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeSub)
console.info(TAG, 'enableLocalSubVideo result:' + ret)
}
setExternalVideoSouce(enable:boolean, streamType:NERtcConstants.NERtcVideoStreamType){
let ret = NERtcSDK.getInstance().setExternalVideoSource(enable,streamType)
let ret: number = NERtcSDK.getInstance().setExternalVideoSource(enable,streamType)
console.info(TAG, 'setExternalVideoSouce result:' + ret)
}

pushExternalVideoFrame(frame: NERtcConstants.NERtcVideoFrame, streamType: NERtcConstants.NERtcVideoStreamType){
let ret = NERtcSDK.getInstance().pushExternalVideoFrame(frame, streamType)
let ret: boolean = NERtcSDK.getInstance().pushExternalVideoFrame(frame, streamType)
}

setStatsObserver(statsObserver: NERtcStatsObserver) {
NERtcSDK.getInstance().setStatsObserver(statsObserver)
}
enableAudio(enable: boolean) {
let ret = NERtcSDK.getInstance().enableLocalAudio(enable)
let ret: number = NERtcSDK.getInstance().enableLocalAudio(enable)
console.info(TAG, 'enableLocalAudio result:' + ret)
}
startLastmileProbeTest(config: NERtcConstants.LastmileProbeConfig) {
let ret: number = NERtcSDK.getInstance().startLastmileProbeTest(config)
console.info(TAG, 'startLastmileProbeTest result:' + ret)
// 接口后序版本逐渐放开
// let ret: number = NERtcSDK.getInstance().startLastmileProbeTest(config)
// console.info(TAG, 'startLastmileProbeTest result:' + ret)
}
enableSubAudio(enable: boolean) {
let ret = NERtcSDK.getInstance().enableLocalSubStreamAudio(enable)
let ret: number = NERtcSDK.getInstance().enableLocalSubStreamAudio(enable)
console.info(TAG, 'enableLocalAudio result:' + ret)
}
setAudioProfile(profile: number, scenario: number) {
NERtcSDK.getInstance().setAudioProfile(profile, scenario);
}
setSpeakPhoneOn(enable: boolean) {
let ret = NERtcSDK.getInstance().setSpeakerphoneOn(enable)
let ret: number = NERtcSDK.getInstance().setSpeakerphoneOn(enable)
console.info(TAG, 'setSpeakPhoneOn result:' + ret)
}
leave() {
let ret: number = NERtcSDK.getInstance().leaveChannel()
console.info(TAG, `LeaveChannel ret:${ret}`)
}
setVoiceBeautifierPreset(preset: number) {
let ret: number = NERtcSDK.getInstance().setVoiceBeautifierPreset(preset)
console.info(TAG, `setVoiceBeautifierPreset ret:${ret}`)
//后序版本逐渐放开
// let ret: number = NERtcSDK.getInstance().setVoiceBeautifierPreset(preset)
// console.info(TAG, `setVoiceBeautifierPreset ret:${ret}`)
}
setAudioEffectPreset(preset: number) {
let ret: number = NERtcSDK.getInstance().setAudioEffectPreset(preset)
console.info(TAG, `setAudioEffectPreset ret:${ret}`)
//后序版本逐渐放开
// let ret: number = NERtcSDK.getInstance().setAudioEffectPreset(preset)
// console.info(TAG, `setAudioEffectPreset ret:${ret}`)
}
setCameraCaptureConfig(config: NERtcConstants.NERtcCameraCaptureConfiguration) {
let ret: number = NERtcSDK.getInstance().setCameraCaptureConfig(config, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain);
console.info(TAG, `setCameraCaptureConfig ret:${ret}`);
//后序版本逐渐放开
// let ret: number = NERtcSDK.getInstance().setCameraCaptureConfig(config, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain);
// console.info(TAG, `setCameraCaptureConfig ret:${ret}`);
}
setLocalVideoConfig(config: NERtcConstants.NERtcVideoEncodeConfiguration) {
let ret: number = NERtcSDK.getInstance().setLocalVideoConfig(config, NERtcConstants.NERtcVideoStreamType.kNERtcVideoStreamTypeMain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from '@ohos.file.fs';
import fileIo from '@ohos.file.fs';
import config from '../../common/Config'
import Utils from '../../common/Utils';
import { NERtcSDK, NERtcConstants } from 'sdk/Index';
import { NERtcSDK, NERtcConstants } from '@nertc/nertc_sdk';
import prompt from '@ohos.promptAction';
import { BusinessError } from '@ohos.base';
import buffer from '@ohos.buffer';
Expand Down Expand Up @@ -190,7 +190,7 @@ struct ExternalVideoSource {

//step6: 入会
let uid = Utils.getRandomNumber(1, 100000)
let ret = NERtcSDK.getInstance().joinChannel('', config.CHANNEL_NAME, BigInt(uid))
let ret: number = NERtcSDK.getInstance().joinChannel('', config.CHANNEL_NAME, BigInt(uid))
if (ret == 0) {
this.isJoined = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import router from '@ohos.router';
import prompt from '@ohos.promptAction';
import Delegate from '../common/Delegate';
import ChatPresenter from '../common/Presenter'
import { NERtcVideoView, NERtcConstants} from 'sdk';
import { NERtcVideoView, NERtcConstants} from '@nertc/nertc_sdk';
import * as model from '../common/Model';
import fs from '@ohos.file.fs';
import type resourceManager from '@ohos.resourceManager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import router from '@ohos.router';
import prompt from '@ohos.promptAction';
import Delegate from '../common/Delegate';
import ChatPresenter from '../common/Presenter'
import { NERtcVideoView, NERtcConstants} from 'sdk';
import { NERtcVideoView, NERtcConstants} from '@nertc/nertc_sdk';
import * as model from '../common/Model';
import fs from '@ohos.file.fs';
import type resourceManager from '@ohos.resourceManager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoadingDialog } from '@ohos.arkui.advanced.Dialog'
import Utils from '../common/Utils';
import config from '../common/Config'
import ChatPresenter from '../common/Presenter';
import { NERtcConstants } from 'sdk';
import { NERtcConstants } from '@nertc/nertc_sdk';
import router from '@ohos.router';
import * as model from '../common/Model'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Delegate from '../common/Delegate';
import { LiveStreamEvent } from '../common/Model';
import ChatPresenter from '../common/Presenter';
import Prompt from '@system.prompt';
import { NERtcConstants } from 'sdk';
import { NERtcConstants } from '@nertc/nertc_sdk';
import router from '@ohos.router';
import * as model from '../common/Model';

Expand Down Expand Up @@ -454,7 +454,7 @@ struct LiveStream {

buildLiveStreamTask(): NERtcConstants.NERtcLiveStreamTaskInfo {

let sampleRate = NERtcConstants.NERtcLiveStreamAudioSampleRate.kNERtcLiveStreamAudioSampleRate44100
let sampleRate: number = NERtcConstants.NERtcLiveStreamAudioSampleRate.kNERtcLiveStreamAudioSampleRate44100
if(this.audioSampleRate) {
if(this.audioSampleRate == 32000) {
sampleRate = NERtcConstants.NERtcLiveStreamAudioSampleRate.kNERtcLiveStreamAudioSampleRate32000
Expand All @@ -465,7 +465,7 @@ struct LiveStream {
}
}

let audioCodec = NERtcConstants.NERtcLiveStreamAudioCodecProfile.kNERtcLiveStreamAudioCodecProfileLCAAC
let audioCodec: number = NERtcConstants.NERtcLiveStreamAudioCodecProfile.kNERtcLiveStreamAudioCodecProfileLCAAC
if(this.audioCodecType) {
if(this.audioCodecType == 0) {
audioCodec = NERtcConstants.NERtcLiveStreamAudioCodecProfile.kNERtcLiveStreamAudioCodecProfileLCAAC
Expand Down Expand Up @@ -494,7 +494,7 @@ struct LiveStream {

//这里只是为了演示,只推自己
let userTranscodingList: NERtcConstants.NERtcLiveStreamUserTranscoding[] = []
let scaleMode = this.remoteAdaption == 0 ? NERtcConstants.NERtcLiveStreamVideoScaleMode.kNERtcLsModeVideoScaleFit : NERtcConstants.NERtcLiveStreamVideoScaleMode.kNERtcLsModeVideoScaleCropFill
let scaleMode: NERtcConstants.NERtcLiveStreamVideoScaleMode = this.remoteAdaption == 0 ? NERtcConstants.NERtcLiveStreamVideoScaleMode.kNERtcLsModeVideoScaleFit : NERtcConstants.NERtcLiveStreamVideoScaleMode.kNERtcLsModeVideoScaleCropFill
let userTranscoding: NERtcConstants.NERtcLiveStreamUserTranscoding = {
uid: BigInt(this.login?.uid!),
videoPush: this.remoteSubVideo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NERtcConstants, NERtcVideoView } from 'sdk';
import { NERtcConstants, NERtcVideoView } from '@nertc/nertc_sdk';
import ChatPresenter, { remoteUsers } from '../common/Presenter';
import router from '@ohos.router';
import * as model from '../common/Model';
Expand Down
Loading

0 comments on commit ad12953

Please sign in to comment.