nimeet Docs
中文

Cocos Creator SDK Guide

Cocos Creator public interface, installation and platform limits.

Interface sections generated from the public SDK definitions

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

Cocos Creator uses a TypeScript interface aligned with Agora's public Cocos Creator API, covering channel join, publish/subscribe, events and error handling. Media and rendering are provided through an injected bridge in your native project; the SDK does not bundle a media stack.

Prerequisites

  • Cocos Creator 3.8+ (TypeScript).
  • A platform bridge: CocosBridgePort.invoke(method, params). Web build targets use the browser RTC bridge; native build targets use the

Cocos2d-x binding (the same ni-meet C++ core).

Installation

bash
pnpm --filter @nimeet/rtc-cocos build      # source in sdk/cocos, output in sdk/cocos/build

Cocos Creator 3.x supports npm dependencies, so add sdk/cocos/build as a local package; it is not published to npm yet.

Get a token

Your backend issues the token with POST /v1/tokens; the client only receives { appId, rtcToken, rtcUid }. For the semantics see AccessToken2 Semantics and Privileges. initialize takes the App ID and joinChannel takes the token.

Join a channel

javascript
import { AgoraRtc } from '@nimeet/rtc-cocos';

const client = AgoraRtc.createAgoraRtcClient({ bridge }); // bridge = your CocosBridgePort
await client.initialize(appId);
await client.joinChannel(token, 'channel-a', 1234);
await client.setClientRole('broadcaster');
  • initialize(string | AgoraRtcEngineConfig): an empty App ID → protocol_error.
  • Calling an engine-backed member before initialize → bridge_unavailable (with the hint call initialize() first); the call never reaches the bridge.
  • joinChannel(token, channelId, uid, options?): an empty channel name or a non-integer uid → protocol_error.

Publishing and subscribing

The binding layer matches the Agora Cocos wrapper: it does not manage track objects; publish/subscribe intent is expressed with engine switches.

  • Audio: enableAudio / enableLocalAudio / muteLocalAudioStream / muteRemoteAudioStream / muteAllRemoteAudioStreams / setAudioProfile;
  • Video: enableVideo / enableLocalVideo / muteLocal* / muteRemote* / startPreview / stopPreview / switchCamera;
  • Rendering: setupLocalVideoView(canvas) / setupRemoteVideoView(uid, canvas) / update* / remove*, plus setRenderBackend('engine-texture');
  • Mixing and effects: startAudioMixing / pauseAudioMixing / resumeAudioMixing / stopAudioMixing / getAudioMixingCurrentPosition / setAudioMixingPosition / adjustAudioMixing*,

preloadEffect / playEffect / pauseEffect / resumeEffect / stopEffect / setEffectsVolume.

Every member forwards to the bridge under its documented method name; the bridge implementation lives in sdk/cocos2dx (native) or in the browser RTC bridge (Web).

Events

on(event, listener) returns an unsubscribe function and off(event, listener) removes exactly that listener. The event set is the 23 AgoraEventMap keys in the reference version:

uploadLogResult, joinChannelSuccess, leaveChannel, rejoinChannelSuccess, connectionInterrupted, connectionStateChanged, localVideoTextureReady, remoteVideoTextureReady, localVideoTextureReleased, remoteVideoTextureReleased, renderBackendState, userJoined, userOffline, remoteVideoStateChanged, localVideoStateChanged, firstLocalAudioFramePublished, audioMixingFinished, audioMixingStateChanged, remoteAudioStateChanged, volumeIndication, rtcStats, contentInspectResult, error.

Error handling

The error object is AgoraSdkError; code is the documented string code, and the native numeric code (if any) is in nativeCode:

codeMeaningTrigger
bridge_unavailableNo bridge / initialize not called / destroy already calledLifecycle guard
protocol_errorAn argument or state the documentation does not allowRole, channel profile, canvas size, encoding size, render backend, empty token, empty path
native_failureThe bridge-side call failedThe native layer returned a failure; nativeCode keeps the documented error code
timeoutRequest timed out (5000ms default)The bridge did not return within the timeout

Every public member on this platform is implemented; failures return the error codes in the table above and never a fake success.

Troubleshooting

SymptomCauseHandling
Every call returns bridge_unavailableNo bridge was passed at constructioncreateAgoraRtcClient({ bridge })
protocol_error: call initialize() firstWrong call orderCall initialize first, then joinChannel / the media switches
setVideoEncoderConfiguration was called but there is no pictureNo canvas and no preview were configuredstartPreview → setupLocalVideoView → setupRemoteVideoView
Events never arriveThe bridge does not implement onEventImplement onEvent(listener) on the bridge and forward the native events into it

Known limitations

  • Compatibility target: the Cocos Creator SDK aligns with Agora's public Cocos Creator API; Agora does not publish an official API reference for this platform, so the public declarations are the reference.
  • Events: event names are aligned; payload types are listed in the event table on this page.
  • Behaviour depends on the bridge: lifecycle, parameter validation, event dispatch, timeouts and error mapping are handled by the SDK; media, rendering and audio mixing are forwarded to the injected bridge.
  • Some exports are internal to the bridge: texture-slot caches and texture-view management are not part of the public API.

Next steps

Platform information

Itemvalue
PlatformCocos Creator
LanguageTypeScript
SDK packagenimeet-rtc-cocos
Interface version4.5.3
Compatible Agora APIAgora cocos API

The public interfaces are aligned with the Agora cocos 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
enable video and local previewAgoraRtcClientenableVideo1
Create instance / initializeAgoraRtcClientinitialize1
Join a channelAgoraRtcClientjoinChannel1
Leave a channelAgoraRtcClientleaveChannel1
subscribe to remote mediaAgoraRtcClientmuteRemoteAudioStream1
Renew the TokenAgoraRtcClientrenewToken1
Channel scenariosAgoraRtcClientsetChannelProfile1
switch rolesAgoraRtcClientsetClientRole1
typescript
enableVideo(enabled: boolean): Promise<void>
initialize(config: string|AgoraRtcEngineConfig): Promise<void>
joinChannel(token: string, channelId: string, uid: number, options?: AgoraChannelMediaOptions): Promise<void>
leaveChannel(options?: AgoraLeaveChannelOptions): Promise<void>
muteRemoteAudioStream(uid: number, muted: boolean): Promise<void>
renewToken(token: string): Promise<void>
setChannelProfile(profile: 'communication'|'liveBroadcasting'): Promise<void>
setClientRole(role: 'broadcaster'|'audience', options?: AgoraClientRoleOptions): Promise<void>

Events and callbacks

Interfaceevent namelistener parameters
AgoraRtcClientuploadLogResult{requestId:string;success:boolean;reason:number;}
AgoraRtcClientjoinChannelSuccess{channelId:string;uid:number;elapsed:number;}
AgoraRtcClientleaveChannelAgoraRtcStatsPayload
AgoraRtcClientrejoinChannelSuccess{channelId:string;uid:number;elapsed:number;}
AgoraRtcClientconnectionInterruptedRecord<string,never>
AgoraRtcClientconnectionStateChanged{state:number;reason:number;}
AgoraRtcClientlocalVideoTextureReady{slotId:number;width:number;height:number;}
AgoraRtcClientremoteVideoTextureReady{uid:number;slotId:number;width:number;height:number;}
AgoraRtcClientlocalVideoTextureReleased{slotId:number;}
AgoraRtcClientremoteVideoTextureReleased{uid:number;slotId:number;}
AgoraRtcClientrenderBackendState{backend:string;phase:string;result:number;uid:number;fallbackBackend?:string;platform?:string;}
AgoraRtcClientuserJoined{uid:number;elapsed:number;}
AgoraRtcClientuserOffline{uid:number;reason?:number;}
AgoraRtcClientremoteVideoStateChanged{uid:number;state:number;reason:number;elapsed:number;}
AgoraRtcClientlocalVideoStateChanged{sourceType:number;state:number;error:number;}
AgoraRtcClientfirstLocalAudioFramePublished{elapsed:number;}
AgoraRtcClientaudioMixingFinishedRecord<string,never>
AgoraRtcClientaudioMixingStateChanged{state:number;reason:number;}
AgoraRtcClientremoteAudioStateChanged{uid:number;state:number;reason:number;elapsed:number;}
AgoraRtcClientvolumeIndication{speakers:Array<{uid:number;volume:number;vad:number;voicePitch:number;}>;totalVolume:number;}
AgoraRtcClientrtcStatsAgoraRtcStatsPayload
AgoraRtcClientcontentInspectResult{result:number;}
AgoraRtcClienterror{code?:number|string;message:string;}

Error codes

Constantvalue
BridgeUnavailablenull
NativeFailurenull
ProtocolErrornull
Timeoutnull

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.