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, mUserID;

    private GMEAuthBufferHelper() {
    }

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

    public void setGMEParams(String appId, String key, String userID) {
        mAppId = appId;
        mKey = key;
        mUserID = userID;
    }

    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", mUserID, mKey);
        } else {
            authBuffer = AuthBuffer.getInstance().genAuthBuffer(Integer.parseInt(mAppId), roomId, mUserID, mKey);
        }
        return authBuffer;
    }
}
