This document describes how to get started with the GME APIs for Cocos2d.
This document only describes the most important APIs to help you get started with GME. For more information on APIs, please see the API documentation.
Important API | Description |
---|---|
Init | Initializes GME |
Poll | Triggers event callback |
EnterRoom | Enters room |
EnableMic | Enables mic |
EnableSpeaker | Enables speaker |
AV_OK
will be returned with the value being 0.Poll
API should be called periodically for GME to trigger event callbacks.To use the voice feature, get the ITMGContext
object first.
ITMGContext* context = ITMGContextGetInstance();
context->SetTMGDelegate(this);
For more information on how to get parameters, please see Access Guide.
This API requires the AppID
from the Tencent Cloud Console and the openID
as parameters. The openID
uniquely identifies a user with the rules stipulated by the application developer and must be unique in the application (currently, only INT64 is supported).
Note:The SDK must be initialized so that a room can be entered
ITMGContext virtual int Init(const char* sdkAppId, const char* openID)
Parameter | Type | Description |
---|---|---|
sdkAppId | char* | AppId from the Tencent Cloud Console |
openId | char* | OpenID can only be in Int64 type (converted to char*) with a value greater than 10,000, which is used to identify the user |
#define SDKAPPID3RD "1400089356"
cosnt char* openId="10001";
ITMGContext* context = ITMGContextGetInstance();
context->Init(SDKAPPID3RD, openId);
Event callbacks can be triggered by periodically calling the Poll
API in update
.
class ITMGContext {
protected:
virtual ~ITMGContext() {}
public:
virtual void Poll()= 0;
}
ITMGContextGetInstance()->Poll();
Generate AuthBuffer
for encryption and authentication of relevant features. For release in the production environment, please use the backend deployment key as detailed in Authentication Key.
To get authentication for voice messaging and speech-to-text, the room ID parameter must be set to null
.
int QAVSDK_AuthBuffer_GenAuthBuffer(unsigned int dwSdkAppID, const char* strRoomID, const char* strOpenID,
const char* strKey, unsigned char* strAuthBuffer, unsigned int bufferLength);
Parameter | Type | Description |
---|---|---|
dwSdkAppID | int | AppId from the Tencent Cloud Console. |
strRoomID | char* | Room ID, which can contain up to 127 characters (for voice messaging and speech-to-text feature, enter null ). |
strOpenID | char* | User ID, which is the same as openID during initialization. |
strKey | char* | Permission key from the Tencent Cloud Console. |
strAuthBuffer | char* | Returned authbuff . |
bufferLength | int | Length of the authbuff passed in. 500 is recommended. |
unsigned int bufferLen = 512;
unsigned char retAuthBuff[512] = {0};
QAVSDK_AuthBuffer_GenAuthBuffer(atoi(SDKAPPID3RD), roomId, "10001", AUTHKEY,retAuthBuff,bufferLen);
When a client enters a room with the generated authentication information, the ITMG_MAIN_EVENT_TYPE_ENTER_ROOM
message will be received as a callback. Mic and speaker are not enabled by default after room entry. The returned value of AV_OK
indicates a success.
For entering a common voice chat room that does not involve range voice, use the common room entry API. For more information, please see Range Voice.
ITMGContext virtual int EnterRoom(const char* roomID, ITMG_ROOM_TYPE roomType, const char* authBuffer, int buffLen)
Parameter | Type | Description |
---|---|---|
roomID | char* | Room ID, which can contain up to 127 characters |
roomType | ITMG_ROOM_TYPE | Room audio type |
authBuffer | char* | Authentication key |
buffLen | int | Authentication key length |
For more information on how to choose a room audio type, please see Sound Quality Selection.
ITMGContext* context = ITMGContextGetInstance();
context->EnterRoom(roomID, ITMG_ROOM_TYPE_STANDARD, (char*)retAuthBuff,bufferLen);
After the client enters the room, the message ITMG_MAIN_EVENT_TYPE_ENTER_ROOM
will be sent and identified in the OnEvent
function.
void TMGTestScene::OnEvent(ITMG_MAIN_EVENT_TYPE eventType,const char* data){
switch (eventType) {
case ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:
{
// Process
break;
}
}
}
This API is used to enable/disable the mic. Mic and speaker are not enabled by default after room entry.
ITMGAudioCtrl virtual int EnableMic(bool bEnabled)
Parameter | Type | Description |
---|---|---|
bEnabled | bool | To enable the mic, set this parameter to true ; otherwise, set it to false . |
ITMGContextGetInstance()->GetAudioCtrl()->EnableMic(true);
This API is used to enable/disable the speaker.
ITMGAudioCtrl virtual int EnableSpeaker(bool enable )
Parameter | Type | Description |
---|---|---|
enable | bool | To disable the speaker, set this parameter to false ; otherwise, set it to true . |
ITMGContextGetInstance()->GetAudioCtrl()->EnableSpeaker(true);
Was this page helpful?