nimeet Docs
中文

HarmonyOS SDK Guide

HarmonyOS Next SDK install, join and capability boundaries.

Interface sections generated from the public SDK definitions

Version v1.1.0 · Updated 2026-10-26 · revision 1

The HarmonyOS SDK has the ArkTS RtcEngine shape; it is isomorphic to Android (joinChannel + IRtcEngineEventHandler callbacks) but runs on the ArkTS runtime of HarmonyOS NEXT.

Prerequisites

  • DevEco Studio 5.0+, HarmonyOS SDK API 12+, the ohpm package manager.
  • Declare ohos.permission.CAMERA and ohos.permission.MICROPHONE in module.json5; the user grants them on first use.
  • An appId and a token service (see Enable Services and Get Credentials).

Installation

text
# planned ohpm coordinates (not published yet)
ohpm install @nimeet/rtc-harmonyos

Get a token

Your backend issues the token; the ArkTS client only holds { appId, rtcToken, rtcUid }. Never package appCertificate or customerSecret into the HAP (a HAP can be unpacked and read).

Join a channel

typescript
import { RtcEngine, RtcEngineConfig, ChannelProfileType, ClientRoleType } from '@nimeet/rtc-harmonyos';

const engine: RtcEngine = createRtcEngine();
engine.initialize(new RtcEngineConfig(appId));

engine.registerEventHandler({
  onJoinChannelSuccess: (connection, elapsed) => console.info('joined'),
  onUserJoined: (connection, uid, elapsed) => console.info('remote', uid),
  onUserOffline: (connection, uid, reason) => console.info('left', uid),
  onTokenPrivilegeWillExpire: (token) => refreshToken(),
  onError: (err, msg) => console.error(`rtc ${err}: ${msg}`),
});

engine.setChannelProfile(ChannelProfileType.ChannelProfileLiveBroadcasting);
engine.enableVideo();
engine.startPreview();
engine.joinChannelWithOptions(token, 'weekly-sync', 10001, {
  clientRoleType: ClientRoleType.ClientRoleBroadcaster,
  autoSubscribeAudio: true,
  autoSubscribeVideo: true,
});

Publishing and subscribing

typescript
engine.muteLocalAudioStream(true);
engine.muteLocalVideoStream(true);
engine.enableLocalVideo(false);
engine.updateChannelMediaOptions(options);

Screen sharing: startScreenCapture(parameters) / stopScreenCapture() / updateScreenCaptureParameters(parameters); it needs the screen-recording permission (granted through a system dialog).

Events

IRtcEngineEventHandler exposes 51 on* methods: onJoinChannelSuccess, onUserJoined, onUserOffline, onFirstRemoteVideoDecoded, onTokenPrivilegeWillExpire, onError, onConnectionStateChanged.

Error handling

  • Synchronous methods return a numeric error code; 0 means success and a negative value is an Agora error number;
  • Asynchronous errors arrive through onError;
  • Unimplemented capabilities return -4 (ERR_NOT_SUPPORTED).

Troubleshooting

SymptomCauseHandling
Module not found at compile timeohpm is not installed / not syncedSync the project in DevEco
Crash on capture because of permissionsCAMERA/MICROPHONE were not requestedAdd the permissions to module.json5 and handle the user's refusal
Screen sharing failsScreen recording was not authorized by the systemSend the user to the system settings to grant it
Callbacks never fireThe handler was never registered or has been collectedRegister in the page's aboutToAppear and unregister in aboutToDisappear
The app is frozen in the backgroundApplication lifecycle limitsUse a long-running task / foreground service capability

Next steps

Platform information

Itemvalue
PlatformHarmonyOS(ArkTS)
LanguageArkTS
SDK package@nimeet/rtc-harmonyos
Interface version4.6.3
Compatible Agora APIAgora harmonyos API

The public interfaces are aligned with the Agora harmonyos API; installation and runtime requirements are listed under Prerequisites above.

Availability

This platform's SDK: Generally available. The examples use the public API; runtime capability follows the published SDK package.

join-channel flow

The method names, parameter types and return values match the API reference for the same platform. Where a method has several overloads, the most common one is shown here; see the API reference for all overloads.

StepInterfaceMethodOverload count
Create instance / initialize__unattributed__create1
Renew the TokenIAgoraMusicContentCenterrenewToken1
enable video and local previewRtcEngineenableVideo1
Join a channelRtcEnginejoinChannel1
Leave a channelRtcEngineleaveChannel1
subscribe to remote mediaRtcEnginemuteRemoteAudioStream1
Channel scenariosRtcEnginesetChannelProfile1
switch rolesRtcEnginesetClientRole1
bind the local videoRtcEnginesetupLocalVideo1
typescript
create(config: RtcEngineConfig): RtcEngine
renewToken(token: string): number
enableVideo(): number
joinChannel(key: string, channel: string, optionalInfo: string, uid: number): number
leaveChannel(options?: LeaveChannelOptions): number
muteRemoteAudioStream(uid: number, muted: boolean): number
setChannelProfile(profile: number): number
setClientRole(role: number, options?: ClientRoleOptions): number
setupLocalVideo(canvas: VideoCanvas): number

Events and callbacks

Callbacks are registered on IRtcEngineEventHandler; naming differs by platform, and the full list is in the API reference for the same platform.

CallbacksSignaturePurpose
onConnectionStateChangedonConnectionStateChanged(state: Constants.ConnectionState, reason: Constants.ConnectionChangedReason): voidjoin result / connection-state changes:update the UI accordingly and decide whether to reconnect.
onUserJoinedonUserJoined(uid: number, elapse: number): voidRemote user joined:allocate the frame container.
onRemoteVideoStateChangedonRemoteVideoStateChanged(uid: number, state: Constants.RemoteVideoStreamState, reason: Constants.RemoteVideoStreamReason, elapsed: number): voidRemote video status:it can render once the first frame is decoded.
onUserOfflineonUserOffline(uid: number, reason: number): voidRemote user left:release the container and subscription.
onRequestTokenonRequestToken(): voidToken expiring soon:call the server to renew, then `renewToken`.
onErroronError(err: Constants.ErrorCode, message: string): voidRuntime errors:`err` is an Agora error number, route by the error-code table.
onNetworkQualityonNetworkQuality(uid: number, txQuality: Constants.NetworkQuality, rxQuality: Constants.NetworkQuality): voidNetwork quality:report to Analytics or prompt the user.
Interfaceevent namelistener parameters
IMediaPlayerObserveronPlayerCacheStatsonPlayerCacheStats?:(stats:CacheStatistics

Error codes

Constantvalue
ERR_ABORTED20
ERR_ADM_GENERAL_ERROR1005
ERR_ADM_INIT_PLAYOUT1008
ERR_ADM_INIT_RECORDING1011
ERR_ADM_START_PLAYOUT1009
ERR_ADM_START_RECORDING1012
ERR_ADM_STOP_PLAYOUT1010
ERR_ADM_STOP_RECORDING1013
ERR_ALREADY_IN_USE19
ERR_BITRATE_LIMIT115
ERR_BUFFER_TOO_SMALL6
ERR_CONNECTION_INTERRUPTED111
ERR_CONNECTION_LOST112
ERR_DATASTREAM_DECRYPTION_FAILED122
ERR_DECRYPTION_FAILED120
ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH130
ERR_FAILED1
ERR_INIT_NET_ENGINE21
ERR_INVALID_APP_ID101
ERR_INVALID_ARGUMENT2
ERR_INVALID_CHANNEL_NAME102
ERR_INVALID_TOKEN110
ERR_INVALID_USER_ACCOUNT134
ERR_JOIN_CHANNEL_REJECTED17
ERR_LEAVE_CHANNEL_REJECTED18
ERR_LOAD_MEDIA_ENGINE1001
ERR_NOT_INITIALIZED7
ERR_NOT_IN_CHANNEL113
ERR_NOT_READY3
ERR_NOT_SUPPORTED4
ERR_NO_PERMISSION9
ERR_OK0
ERR_REFUSED5
ERR_RESOURCE_LIMITED22
ERR_SIZE_TOO_LARGE114
ERR_TIMEDOUT10
ERR_TOKEN_EXPIRED109
ERR_TOO_MANY_DATA_STREAMS116
ERR_VDM_CAMERA_NOT_AUTHORIZED1501
RtcEnginenull

the platform REST layer uses REST error codes;the SDK layer maps connection/authentication failures to Agora error numbers, for the mapping table see SDK error identifiers per platform。

Generated by the documentation build pipeline · 2026-10-31 01:24:02 UTC · Documentation center v1.1.0.

Content follows the public API definitions.

ni-meet is a self-hosted RTC PaaS with a LiveKit-based media plane (Apache-2.0) and an Agora-compatible API.