package com.tencent.gme.audio.apiexample;

import android.text.TextUtils;

import com.gme.av.sig.AuthBuffer;

public class GMEAuthBufferHelper {
    private static GMEAuthBufferHelper mInstance;
    private String mAppId, mKey, mOpenId;



    private GMEAuthBufferHelper(){}

    public static GMEAuthBufferHelper getInstance()
    {
        if (mInstance == null)
        {
            synchronized (GMEAuthBufferHelper.class)
            {
                if (mInstance == null)
                {
                    mInstance = new GMEAuthBufferHelper();
                }
            }
        }
        return mInstance;
    }

    public void setGEMParams(String appId, String key, String openId)
    {
        mAppId = appId;
        mKey = key;
        mOpenId = openId;
    }

    public byte[] createAuthBuffer(String roomId)
    {
        byte[] authBuffer;
        // Generate AuthBuffer for encryption and authentication of relevant features. For release in the production environment,
        // please use the backend deployment key as detailed in https://intl.cloud.tencent.com/document/product/607/12218
        if (TextUtils.isEmpty(roomId))
        {
            authBuffer =  AuthBuffer.getInstance().genAuthBuffer(Integer.parseInt(mAppId), "0", mOpenId, mKey);
        }else
        {
            authBuffer =  AuthBuffer.getInstance().genAuthBuffer(Integer.parseInt(mAppId), roomId, mOpenId, mKey);
        }
        return authBuffer;
    }
}
