NoteOnly some GME features are supported by the SDK for HTML5. Please refer to this document for the supported APIs and evaluate whether the SDK for HTML5 is appropriate for your business scenario.
API | Description |
---|---|
Init | Initializes API |
SetTMGDelegate | Sets delegation |
EnterRoom | Enters audio room |
EnableMic | Turns on/off the capturing device |
EnableSpeaker | Turns on/off the playback device |
SetMicVolume | Sets mic volume |
ExitRoom | Exits audio room |
Note
- After a GME API is called successfully,
QAVError.OK
will be returned with the value being 0.- Authentication is required for room entry in GME. For more information, see the authentication section in relevant documentation.
- Operation on devices should be performed after successful room entry.
- Starting from Chrome 74,
navigator.mediaDevices
can only be used in an HTTPS environment; therefore, please use HTTPS.
You need to integrate JQ to use the demo.
<!--Step 2: Add the audio container-->
<!--Container, which is used to carry audio tags and cannot be omitted.-->
<div id="gme-audio-wrap"></div>
Before initialization, the SDK is in the uninitialized state. A room can be entered only after the initialization authentication is performed and the SDK is initialized.
For more information on how to get parameters, see Access Guide.
This API requires the SDKAppID
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).
NoteThe SDK must be initialized before a user can enter a room.
WebGMEAPI.fn.Init = function (document, SdkAppId, openId) {...}
Parameter | Description |
---|---|
document | HTML DOM Document object |
SdkAppId | SdkAppId from the Tencent Cloud console |
openId | Developer-defined user account with a value greater than 10,000, which is used to identify the user. |
const cSdkAppId = () => document.getElementById("input-SdkAppId").value;
const cOpenID = () => document.getElementById("input-OpenID").value;
gmeAPI.Init(document, cSdkAppId(), cOpenID());
The API class uses the Delegate
method to send callback notifications to the application. Register the callback function to the SDK to receive callback messages. The callback function should be registered to the SDK before room entry.
WebGMEAPI.fn.SetTMGDelegate = function (delegate){...}
Parameter | Description |
---|---|
onEvent | SDK callback event |
gmeAPI.SetTMGDelegate(onEvent);
You should initialize and call the SDK to enter a room before voice chat can start.
When a user 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 turned on by default after room entry.
WebGMEAPI.fn.EnterRoom = function (roomId, roomType, authBuffer) {...}
Parameter | Description |
---|---|
roomId | Room ID, which can contain up to 127 characters |
roomType | Room audio type |
authBuffer | Authentication key. For more information on how to get it, see Project Configuration. |
function bindButtonEvents() {
$("#start_btn").click(function () {
console.log('start!');
// Step 1: Get the `AuthBuffer`
var FetchSigCgi = 'http://134.175.146.244:10005/';
$.ajax({
type: "POST",
url: FetchSigCgi,
dataType: 'json',
data: {
sdkappid: cSdkAppId(),
roomid: cRoomNum(),
openid: cOpenID(),
},
success: function (json) {
// Step 2: `AuthBuffer` is obtained successfully
if (json && json.errorCode === 0) {
let userSig = json.userSig;
gmeAPI.Init(document, cSdkAppId(), cOpenID());
gmeAPI.SetTMGDelegate(onEvent);
gmeAPI.EnterRoom(cRoomNum(), 1, userSig);
} else {
console.error(json);
}
},
error: function (err) {
console.error(err);
}
});
});
After the user enters the room, the message ITMG_MAIN_EVENT_TYPE_ENTER_ROOM
will be sent and identified in the OnEvent
function.
onEvent = function (eventType, result) {
if (eventType === gmeAPI.event.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM)
{
// Entered room successfully
}
else if (eventType === gmeAPI.event.ITMG_MAIN_EVENT_TYPE_USER_UPDATE)
{
app._data.downStreamInfoList = result.PeerInfo;// Received peer information. For more information, see the table below
app._data.brSend = result.UploadBRSend;// Bitrate of the uploaded audio data
app._data.rtt = result.UploadRTT;// Upload RTT
}
else if (eventType === gmeAPI.event.ITMG_MAIN_EVENT_TYPE_EXIT_ROOM)
{
// Exited room successfully
}
else if (eventType === gmeAPI.event.ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT)
{
// Room disconnected
}
};
The received peer information is as follows (downStreamInfoList):
Parameter | Description |
---|---|
brRecv | The received bitrate |
delay | Receipt delay |
jitterBufferMs | Delay caused by jitter |
jitterReceived | The received Jitter |
This API is called to exit the current room. It is an async API. There will be a callback after room exit. The returned value of AV_OK
indicates a successful async delivery.
WebGMEAPI.fn.ExitRoom = function (){...}
gmeAPI.ExitRoom();
This API is used to turn on/off the mic. Mic and speaker are not turned on by default after room entry.
WebGMEAPI.fn.EnableMic = function (bEnable) {...}
Parameter | Description |
---|---|
isEnabled | To turn on the mic, set this parameter to true ; otherwise, set it to false . |
gmeAPI.EnableMic(false);
This API is used to set the mic volume. The corresponding parameter is volume
. 0 indicates that the audio is mute, while 100 indicates that the volume remains unchanged. The default value is 100.
WebGMEAPI.fn.SetMicVolume = function (volume){...}
Parameter | Description |
---|---|
volume | Sets the volume. Value range: 0-100. |
gmeAPI.SetMicVolume(100);
This API is used to turn on/off the speaker.
WebGMEAPI.fn.EnableSpeaker = function (bEnable){...}
Parameter | Description |
---|---|
isEnabled | To turn off the speaker, set this parameter to false ; otherwise, set it to true . |
gmeAPI.EnableSpeaker(true);
Was this page helpful?