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