tencent cloud

Feedback

API Documentation

Last updated: 2024-01-18 15:13:51
    Note:
    Only 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.

    Integrating JQ

    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>

    Initialization APIs

    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.

    Initializing the SDK

    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).
    Note:
    The SDK must be initialized before a user can enter a room.

    Function prototype

    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.

    Sample code

    const cSdkAppId = () => document.getElementById("input-SdkAppId").value;
    const cOpenID = () => document.getElementById("input-OpenID").value;
    gmeAPI.Init(document, cSdkAppId(), cOpenID());

    Setting callbacks

    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.

    Function prototype

    WebGMEAPI.fn.SetTMGDelegate = function (delegate){...}
    Parameter
    Description
    onEvent
    SDK callback event

    Sample code

    gmeAPI.SetTMGDelegate(onEvent);

    Voice Chat APIs

    You should initialize and call the SDK to enter a room before voice chat can start.

    Entering a room

    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.

    Function prototype

    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.

    Sample code

    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);
    }
    });
    });

    Event Callbacks

    After the user enters the room, the message ITMG_MAIN_EVENT_TYPE_ENTER_ROOM will be sent and identified in the OnEvent function.

    Sample code

    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

    Exiting a room

    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.

    Function prototype

    WebGMEAPI.fn.ExitRoom = function (){...}

    Sample code

    gmeAPI.ExitRoom();

    Turning on/off the mic

    This API is used to turn on/off the mic. Mic and speaker are not turned on by default after room entry.

    Function prototype

    WebGMEAPI.fn.EnableMic = function (bEnable) {...}
    Parameter
    Description
    isEnabled
    To turn on the mic, set this parameter to true; otherwise, set it to false.

    Sample code

    gmeAPI.EnableMic(false);

    Setting the mic volume

    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.

    Function prototype

    WebGMEAPI.fn.SetMicVolume = function (volume){...}
    Parameter
    Description
    volume
    Sets the volume. Value range: 0-100.

    Sample code

    gmeAPI.SetMicVolume(100);

    Turning on/off the speaker

    This API is used to turn on/off the speaker.

    Function prototype

    WebGMEAPI.fn.EnableSpeaker = function (bEnable){...}
    Parameter
    Description
    isEnabled
    To turn off the speaker, set this parameter to false; otherwise, set it to true.

    Sample code

    gmeAPI.EnableSpeaker(true);
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support