1package com.netease.nimlib.sdk;
3import android.text.TextUtils;
5import com.netease.nimlib.NimNosSceneKeyConstant;
7import java.util.HashMap;
33 private static final int MIN_CUSTOM_SCENE_COUNT = 10;
34 private static final int DEFAULT_CUSTOM_SCENE_COUNT = MIN_CUSTOM_SCENE_COUNT;
35 private final static HashMap<String, Long> DEFAULT_SCENE =
new HashMap<>();
37 private static int sDefaultSceneCount;
40 private HashMap<String, Long> mNosTokenScene;
42 private int maxCustomNosSceneCount = DEFAULT_CUSTOM_SCENE_COUNT;
45 DEFAULT_SCENE.put(NimNosSceneKeyConstant.NIM_DEFAULT_PROFILE,
NEVER_EXPIRE);
46 DEFAULT_SCENE.put(NimNosSceneKeyConstant.NIM_DEFAULT_IM,
NEVER_EXPIRE);
47 DEFAULT_SCENE.put(NimNosSceneKeyConstant.NIM_SYSTEM_NOS_SCENE,
NEVER_EXPIRE);
48 DEFAULT_SCENE.put(NimNosSceneKeyConstant.NIM_SECURITY_PREFIX,
NEVER_EXPIRE);
49 sDefaultSceneCount = DEFAULT_SCENE.size();
54 mNosTokenScene =
new HashMap<>();
55 mNosTokenScene.putAll(DEFAULT_SCENE);
63 return maxCustomNosSceneCount;
74 throw new IllegalArgumentException(
"expireTimeByDay must >= 0");
76 mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_PROFILE, expireTime *
DAY_SECOND);
87 throw new IllegalArgumentException(
"expireTimeByDay must >= 0");
89 mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_IM, expireTime *
DAY_SECOND);
105 if (expireTime < 0 || TextUtils.isEmpty(sceneKey)) {
106 throw new IllegalArgumentException(
"sceneKey must not empty and expireTimeByDay must >= 0");
108 if (mNosTokenScene.size() - sDefaultSceneCount >= maxCustomNosSceneCount) {
109 throw new IllegalStateException(
"the custom scene count must <= " + maxCustomNosSceneCount);
111 if (NimNosSceneKeyConstant.NIM_SYSTEM_NOS_SCENE.equals(sceneKey)) {
112 throw new IllegalArgumentException(
"the \"nim_system_nos_scene\" scene cannot be modified");
114 mNosTokenScene.put(sceneKey, expireTime);
124 HashMap<String, Long> copy =
new HashMap<>(mNosTokenScene.size());
125 copy.putAll(mNosTokenScene);
130 sDefault.mNosTokenScene = DEFAULT_SCENE;
SDK nos token场景配置,不配置的话,走默认值,默认值只有以下3种场景:
HashMap< String, Long > getNosTokenScene()
获取所有场景副本
static NosTokenSceneConfig defaultConfig()
void updateDefaultProfileSceneExpireTime(int expireTime)
更新默认场景 NimNosSceneKeyConstant#NIM_DEFAULT_PROFILE对应的过期时间
NosTokenSceneConfig appendCustomScene(String sceneKey, int expireTime)
增加自定义场景
static final long DAY_SECOND
int getMaxCustomNosSceneCount()
获取自定义NOS场景最大数量
static final long NEVER_EXPIRE
永不过期,资源一直在于服务器
void updateDefaultIMSceneExpireTime(int expireTime)
更新默认场景 NimNosSceneKeyConstant#NIM_DEFAULT_IM对应的过期时间
NosTokenSceneConfig appendCustomSceneByMilliseconds(String sceneKey, long expireTime)