Cocos Creator SDK Guide
Cocos Creator public interface, installation and platform limits.
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).
- An App ID and a token service (see Enable Services and Get Credentials).
Installation
pnpm --filter @nimeet/rtc-cocos build # source in sdk/cocos, output in sdk/cocos/buildCocos 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
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 hintcall 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*, plussetRenderBackend('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:
| code | Meaning | Trigger |
|---|---|---|
bridge_unavailable | No bridge / initialize not called / destroy already called | Lifecycle guard |
protocol_error | An argument or state the documentation does not allow | Role, channel profile, canvas size, encoding size, render backend, empty token, empty path |
native_failure | The bridge-side call failed | The native layer returned a failure; nativeCode keeps the documented error code |
timeout | Request 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
| Symptom | Cause | Handling |
|---|---|---|
Every call returns bridge_unavailable | No bridge was passed at construction | createAgoraRtcClient({ bridge }) |
protocol_error: call initialize() first | Wrong call order | Call initialize first, then joinChannel / the media switches |
setVideoEncoderConfiguration was called but there is no picture | No canvas and no preview were configured | startPreview → setupLocalVideoView → setupRemoteVideoView |
| Events never arrive | The bridge does not implement onEvent | Implement 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
- Full interfaces and overloads: API reference for this platform
- Error codes and troubleshooting: Error code table, FAQ
- Issue tokens on your server: Token authentication
Platform information
| Item | value |
|---|---|
| Platform | Cocos Creator |
| Language | TypeScript |
| SDK package | nimeet-rtc-cocos |
| Interface version | 4.5.3 |
| Compatible Agora API | Agora 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.
| Step | Interface | Method | Overload count |
|---|---|---|---|
| enable video and local preview | AgoraRtcClient | enableVideo | 1 |
| Create instance / initialize | AgoraRtcClient | initialize | 1 |
| Join a channel | AgoraRtcClient | joinChannel | 1 |
| Leave a channel | AgoraRtcClient | leaveChannel | 1 |
| subscribe to remote media | AgoraRtcClient | muteRemoteAudioStream | 1 |
| Renew the Token | AgoraRtcClient | renewToken | 1 |
| Channel scenarios | AgoraRtcClient | setChannelProfile | 1 |
| switch roles | AgoraRtcClient | setClientRole | 1 |
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
| Interface | event name | listener parameters |
|---|---|---|
AgoraRtcClient | uploadLogResult | {requestId:string;success:boolean;reason:number;} |
AgoraRtcClient | joinChannelSuccess | {channelId:string;uid:number;elapsed:number;} |
AgoraRtcClient | leaveChannel | AgoraRtcStatsPayload |
AgoraRtcClient | rejoinChannelSuccess | {channelId:string;uid:number;elapsed:number;} |
AgoraRtcClient | connectionInterrupted | Record<string,never> |
AgoraRtcClient | connectionStateChanged | {state:number;reason:number;} |
AgoraRtcClient | localVideoTextureReady | {slotId:number;width:number;height:number;} |
AgoraRtcClient | remoteVideoTextureReady | {uid:number;slotId:number;width:number;height:number;} |
AgoraRtcClient | localVideoTextureReleased | {slotId:number;} |
AgoraRtcClient | remoteVideoTextureReleased | {uid:number;slotId:number;} |
AgoraRtcClient | renderBackendState | {backend:string;phase:string;result:number;uid:number;fallbackBackend?:string;platform?:string;} |
AgoraRtcClient | userJoined | {uid:number;elapsed:number;} |
AgoraRtcClient | userOffline | {uid:number;reason?:number;} |
AgoraRtcClient | remoteVideoStateChanged | {uid:number;state:number;reason:number;elapsed:number;} |
AgoraRtcClient | localVideoStateChanged | {sourceType:number;state:number;error:number;} |
AgoraRtcClient | firstLocalAudioFramePublished | {elapsed:number;} |
AgoraRtcClient | audioMixingFinished | Record<string,never> |
AgoraRtcClient | audioMixingStateChanged | {state:number;reason:number;} |
AgoraRtcClient | remoteAudioStateChanged | {uid:number;state:number;reason:number;elapsed:number;} |
AgoraRtcClient | volumeIndication | {speakers:Array<{uid:number;volume:number;vad:number;voicePitch:number;}>;totalVolume:number;} |
AgoraRtcClient | rtcStats | AgoraRtcStatsPayload |
AgoraRtcClient | contentInspectResult | {result:number;} |
AgoraRtcClient | error | {code?:number|string;message:string;} |
Error codes
| Constant | value |
|---|---|
BridgeUnavailable | null |
NativeFailure | null |
ProtocolError | null |
Timeout | null |
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。