tencent cloud

Feedback

Custom Message Channel

Last updated: 2023-04-27 17:30:57
    This document provides a detailed description of using custom audio package attached with message that makes it easy for developers to debug and integrate the APIs for Game Multimedia Engine (GME).

    Use Cases

    The feature of custom audio package attached with message allows you to attach custom messages in the GME audio package as a signaling broadcast to users in the same room.

    Prerequisites

    You have activated the voice chat service. For more information, see Activating Services.
    You have integrated the GME SDK, including core APIs and voice chat APIs. For more information, see Quick Integration of Native SDK, Quick Integration of SDK for Unity, and Quick Integration of SDK for Unreal Engine.

    Use Limits

    Calling this API must meet two requirements: The room type should be Standard or HD (ITMG_ROOM_TYPE_STANDARD or ITMG_ROOM_TYPE_HIGHQUALITY); the mic of the sender and the speaker of the receiver are both on.

    Integrating the Custom Message Feature

    Sending custom messages

    API prototype

    iOS
    Android
    Unity
    -(int) SendCustomData:(NSData *)data repeatCout:(int)reaptCout;
    public abstract int SendCustomData(byte[] data,int repeatCout);
    public abstract int SendCustomData(byte[] customdata,int repeatCout);

    Field description

    Parameter
    Type
    Description
    data
    NSData * or byte[]
    Message to be delivered
    reaptCout
    int
    Number of repeat times. -1 indicates to send the message repeatedly for unlimited times.

    Returned values

    A returned value of QAV_OK indicates the call is successful.
    Callback returning 1004 indicates parameter error, please check parameter. Returning 1201 indicates non-existent room, please check room number.
    For more error codes, see Error Codes.

    Sample code

    Executed statements
    iOS
    Android
    Unity
    -(IBAction)SendCustData:(UIButton*)sender {
    int ret = 0;
    NSString *typeString;
    switch (sender.tag) {
    case 1:
    ret = [[[ITMGContext GetInstance] GetRoom] SendCustomData:[NSData dataWithBytes:_shareRoomID.text.UTF8String length:_roomIdText.text.length] repeatCout:_shareOpenID.text.intValue];
    typeString = @"sendCustData";
    break;
    case 2:
    ret = [[[ITMGContext GetInstance] GetRoom] StopSendCustomData];
    typeString = @"recvCustData";
    break;
    default:
    break;
    }
    if(ret != 0){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"set fail" message:[NSString stringWithFormat:@"%@:errorcode :%d",typeString,ret] delegate:NULL cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    }
    }
    String strData = mEditData.getText().toString();
    String repeatCount = mEditRepeatCount.getText().toString();
    int nRet = ITMGContext.GetInstance(getActivity()).GetRoom().SendCustomData(strData.getBytes(), Integer.parseInt(repeatCount));
    
    InputField SendCustom_Count_InputField = transform.Find("inroomPanel/imPanel/SendCustom_Count_InputField").GetComponent<InputField>();
    InputField SendCustom_Data_InputField = transform.Find("inroomPanel/imPanel/SendCustom_Data_InputField").GetComponent<InputField>();
    
    transform.Find("inroomPanel/imPanel/SendCustom_Btn").GetComponent<Button>().onClick.AddListener(delegate ()
    {
    string data = SendCustom_Data_InputField.text;
    string str_count = SendCustom_Count_InputField.text;
    int count = 0;
    if (int.TryParse(str_count, out count)) {
    Debug.Log(data+ count.ToString());
    byte[] byteData = Encoding.Default.GetBytes(data);
    int ret = ITMGContext.GetInstance().GetRoom().SendCustomData(byteData, count);
    if(ret != 0 ) {
    ShowWarnning(string.Format("send customdata failed err:{0}",ret));
    }
    }
    });
    }
    Callback
    iOS
    Android
    Unity
    -(IBAction)SendCustData:(UIButton*)sender {
        int ret = ret = [[[ITMGContext GetInstance] GetRoom] SendCustomData:[NSData dataWithBytes:dataInput_textfiled_.text.UTF8String length:dataInput_textfiled_.text.length] repeatCout:-1];
    
        if(ret != 0){
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"set fail" message:[NSString stringWithFormat:@"SendCustomData:errorcode :%d",ret] delegate:NULL cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }
    }
    if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_CUSTOMDATA_UPDATE == type) {
    int subtype = data.getIntExtra("sub_event",-1);
    if (subtype == 0) {
    String content = data.getStringExtra("content");
    String sender = data.getStringExtra("senderid");
    Toast.makeText(getActivity(), String.format("recv content =%s, from:%s", content,
    sender), Toast.LENGTH_SHORT).show();
    }
    void OnEvent(int eventType,int subEventType,string data)
    {
    Debug.Log (data);
    switch (eventType) {
    case (int)ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_CUSTOMDATA_UPDATE:
    {
    if(subEventType == (int)ITMG_CUSTOMDATA_SUB_EVENT.ITMG_CUSTOMDATA_AV_SUB_EVENT_UPDATE) {
    _customData = JsonUtility.FromJson<CustomDataInfo>(data);
    ShowWarnning(string.Format("recve customdata {0} from {1}",_customData.content,_customData.senderid));
    }
    }
    break;
    }

    Stopping sending custom messages

    Call this API to stop sending custom messages

    API prototype

    iOS
    Android
    Unity
    -(int) StopSendCustomData;
    public abstract int StopSendCustomData();
    public abstract int StopSendCustomData();

    Returned values

    If StopSendCustomData returns error code 1003, this API has been called and its operation is being performed by the SDK, so there is no need to call it again.
    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