nimeet Docs
中文

Cocos2d-x SDK Guide

Cocos2d-x C++ binding, public interface and supported scenarios.

Interface sections generated from the public SDK definitions

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

The Cocos2d-x SDK ships as a C++ binding library: the public headers define member names and signatures aligned with the Agora C++ API, the implementation forwards through an IRtcEngineCore seam to the ni-meet C++ core, and media capability is injected by the host application.

cpp
#include <nimeet/cocos2dx/rtc_engine.h>   // public C++ interface
#include <nimeet/cocos2dx/core_seam.h>    // core seam (implemented by the host)

Prerequisites

  • Cocos2d-x 3.17+ (C++17); the Android NDK / Xcode come from the host project.
  • The ni-meet C++ core already present in the host application (the same nimeet::RtcEngineSession as the Windows / macOS SDKs),

plus a thin bridge that connects it to nimeet::cocos2dx::IRtcEngineCore (1:1 forwarding, no media logic).

Installation

bash
g++ -std=c++17 -I sdk/cocos2dx/include -I sdk/cocos2dx/src \
    sdk/cocos2dx/tests/adapter_test.cpp sdk/cocos2dx/src/rtc_engine_adapter.cpp -o adapter_test

Add sdk/cocos2dx/include to the header search path and sdk/cocos2dx/src/*.cpp to the source list; no package is published today (no vcpkg or Cocos extension artifact) — it ships as a source directory only.

Get a token

As on every platform: your backend issues the token with POST /v1/tokens. The binding's joinChannel(token, channelId, uid) takes the token string directly; for the semantics see AccessToken2 Semantics and Privileges.

Join a channel

cpp
#include "nimeet/cocos2dx/rtc_engine.h"
#include "nimeet/cocos2dx/core_seam.h"

class AppHandler : public nimeet::cocos2dx::IRtcEngineEventHandler
{
public:
    void onJoinChannelSuccess(const char* channel, nimeet::cocos2dx::uid_t uid, int elapsed) override { /* update UI */ }
    void onUserJoined(nimeet::cocos2dx::uid_t uid, int elapsed) override { /* attach remote view */ }
    void onError(int err, const char* msg) override { /* err is the documented error code */ }
};

nimeet::cocos2dx::RtcEngineAdapter engine(core);   // core implements nimeet::cocos2dx::IRtcEngineCore
AppHandler handler;
nimeet::cocos2dx::RtcEngineContext context;
context.appId = appId;
context.eventHandler = &handler;
engine.initialize(context);
engine.joinChannel(token, "channel-a", "info", 1234);

Only after initialize may you call joinChannel / leaveChannel: otherwise the documented error code -7 (ERR_NOT_INITIALIZED) is returned. An initialize call without an App ID returns -2 (ERR_INVALID_ARGUMENT).

Publishing and subscribing

The binding exposes only the documented switch semantics; it does not manage tracks:

  • Audio: enableAudio / disableAudio / enableLocalAudio / muteLocalAudioStream / muteRemoteAudioStream / muteAllRemoteAudioStreams;
  • Video: enableVideo / disableVideo / enableLocalVideo / muteLocalVideoStream / muteRemoteVideoStream / muteAllRemoteVideoStreams;
  • Preview and rendering: startPreview() / startPreview(VIDEO_SOURCE_TYPE) / stopPreview(…) / switchCamera /

setupLocalVideo(VideoCanvas) / setupRemoteVideo(VideoCanvas) (uid == 0 in setupRemoteVideo returns -2);

  • Encoding: setVideoEncoderConfiguration (a non-positive width or height returns -2).

Events

Callbacks live on IRtcEngineEventHandler; its 14 members match the frozen C++ reference version signature by signature:

onJoinChannelSuccess, onRejoinChannelSuccess, onLeaveChannel, onUserJoined, onUserOffline, onConnectionStateChanged, onError, onAudioVolumeIndication, onLocalAudioStateChanged, onRemoteAudioStateChanged, onLocalVideoStateChanged, onRemoteVideoStateChanged, onRtcStats, onRequestToken.

initialize hands the eventHandler to the core (IRtcEngineCore::SetEventHandler); the core pushes events and the binding does not interpret their content.

Error handling

Members return the documented Agora C++ error codes (0 success; negative failure), and the binding never rewrites a failure into a success:

codeMeaningTrigger
0Success—
-1General errorReturned by the core
-2Invalid argumentMissing App ID, empty channel name, empty token, a remote view with uid == 0, non-positive encoding size, out-of-range volume
-3Not ready yet—
-4Not supportedReturned by the core seam and passed through unchanged by the binding
-7Not initializedCalling an engine-backed member before initialize
-8Invalid stateReturned by the core

The projection has no error-code enum; notSupported is recorded as source: "cli" (see the SDK interface definition)

Troubleshooting

SymptomCauseHandling
The linker reports undefined referenceOnly the headers were added and sdk/cocos2dx/src/rtc_engine_adapter.cpp was not compiledAdd src/*.cpp to the build
Every call returns -7initialize never succeededCall initialize(context) and check the core seam's return value
No pictureOnly setVideoEncoderConfiguration was called, without setupLocalVideo / startPreviewFollow the documented order: preview → bind the canvas
A review says "aligned with the Agora Cocos2d-x SDK"Agora has no SDK for this platformThe correct statement is "the binding interface definition aligns with the documented subset of C++ members"

Next steps

Platform information

Itemvalue
PlatformCocos2d-x(C++ binding)
LanguageC++
SDK packagenimeet_rtc_cocos2dx
Interface version4.7.0
Compatible Agora APIAgora cocos2dx API

The public interfaces are aligned with the Agora cocos2dx 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 previewNimeetCocos2dxRtcEngineenableVideo1
Create instance / initializeNimeetCocos2dxRtcEngineinitialize1
Join a channelNimeetCocos2dxRtcEnginejoinChannel2
Leave a channelNimeetCocos2dxRtcEngineleaveChannel2
subscribe to remote mediaNimeetCocos2dxRtcEnginemuteRemoteAudioStream1
Renew the TokenNimeetCocos2dxRtcEnginerenewToken1
Channel scenariosNimeetCocos2dxRtcEnginesetChannelProfile1
switch rolesNimeetCocos2dxRtcEnginesetClientRole2
bind the local videoNimeetCocos2dxRtcEnginesetupLocalVideo1
typescript
enableVideo(): int
initialize(context: const RtcEngineContext&): int
joinChannel(token: const char*, channelId: const char*, info: const char*, uid: uid_t): int
leaveChannel(): int
muteRemoteAudioStream(uid: uid_t, mute: bool): int
renewToken(token: const char*): int
setChannelProfile(profile: CHANNEL_PROFILE_TYPE): int
setClientRole(role: CLIENT_ROLE_TYPE): int
setupLocalVideo(canvas: const VideoCanvas&): int

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: CONNECTION_STATE_TYPE, reason: CONNECTION_CHANGED_REASON_TYPE): voidjoin result / connection-state changes:update the UI accordingly and decide whether to reconnect.
onUserJoinedonUserJoined(uid: uid_t, elapsed: int): voidRemote user joined:allocate the frame container.
onRemoteVideoStateChangedonRemoteVideoStateChanged(uid: uid_t, state: REMOTE_VIDEO_STATE, reason: REMOTE_VIDEO_STATE_REASON, elapsed: int): voidRemote video status:it can render once the first frame is decoded.
onUserOfflineonUserOffline(uid: uid_t, reason: USER_OFFLINE_REASON_TYPE): voidRemote user left:release the container and subscription.
onRequestTokenonRequestToken(): voidToken expiring soon:call the server to renew, then `renewToken`.
onErroronError(err: int, msg: const char*): voidRuntime errors:`err` is an Agora error number, route by the error-code table.

Error codes

This SDK does not expose error-code constants. For platform errors see Error codes; for cross-platform SDK error identifiers see SDK error identifiers.

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.