NIMSDK-AOS  10.5.0
NosTokenSceneConfig.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk;
2 
3 import android.text.TextUtils;
4 
5 import com.netease.nimlib.NimNosSceneKeyConstant;
6 
7 import java.util.HashMap;
8 
25 public class NosTokenSceneConfig {
26 
30  public static final long NEVER_EXPIRE = 0L;
31 
32  public static final long DAY_SECOND = 60 * 60 * 24L;
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<>();
36 
37  private static int sDefaultSceneCount;
38  private static NosTokenSceneConfig sDefault = new NosTokenSceneConfig();
39 
40  private HashMap<String, Long> mNosTokenScene;
41 
42  private int maxCustomNosSceneCount = DEFAULT_CUSTOM_SCENE_COUNT;
43 
44  static {
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();
50  }
51 
52 
54  mNosTokenScene = new HashMap<>();
55  mNosTokenScene.putAll(DEFAULT_SCENE);
56  }
57 
63  return maxCustomNosSceneCount;
64  }
65 
72  public void updateDefaultProfileSceneExpireTime(int expireTime) {
73  if (expireTime < 0) {
74  throw new IllegalArgumentException("expireTimeByDay must >= 0");
75  }
76  mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_PROFILE, expireTime * DAY_SECOND);
77  }
78 
85  public void updateDefaultIMSceneExpireTime(int expireTime) {
86  if (expireTime < 0) {
87  throw new IllegalArgumentException("expireTimeByDay must >= 0");
88  }
89  mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_IM, expireTime * DAY_SECOND);
90  }
91 
92 
100  public NosTokenSceneConfig appendCustomScene(String sceneKey, int expireTime) {
101  return appendCustomSceneByMilliseconds(sceneKey, expireTime * DAY_SECOND);
102  }
103 
104  public NosTokenSceneConfig appendCustomSceneByMilliseconds(String sceneKey, long expireTime) {
105  if (expireTime < 0 || TextUtils.isEmpty(sceneKey)) {
106  throw new IllegalArgumentException("sceneKey must not empty and expireTimeByDay must >= 0");
107  }
108  if (mNosTokenScene.size() - sDefaultSceneCount >= maxCustomNosSceneCount) {
109  throw new IllegalStateException("the custom scene count must <= " + maxCustomNosSceneCount);
110  }
111  if (NimNosSceneKeyConstant.NIM_SYSTEM_NOS_SCENE.equals(sceneKey)) {
112  throw new IllegalArgumentException("the \"nim_system_nos_scene\" scene cannot be modified");
113  }
114  mNosTokenScene.put(sceneKey, expireTime);
115  return this;
116  }
117 
123  public HashMap<String, Long> getNosTokenScene() {
124  HashMap<String, Long> copy = new HashMap<>(mNosTokenScene.size());
125  copy.putAll(mNosTokenScene);
126  return copy;
127  }
128 
130  sDefault.mNosTokenScene = DEFAULT_SCENE;
131  return sDefault;
132  }
133 }
void updateDefaultProfileSceneExpireTime(int expireTime)
更新默认场景 NimNosSceneKeyConstant#NIM_DEFAULT_PROFILE对应的过期时间
static final long NEVER_EXPIRE
永不过期,资源一直在于服务器
NosTokenSceneConfig appendCustomSceneByMilliseconds(String sceneKey, long expireTime)
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对应的过期时间