NIMSDK-AOS  9.16.0
NosTokenSceneConfig.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk;
2 
3 import android.text.TextUtils;
4 import com.netease.nimlib.NimNosSceneKeyConstant;
5 import java.util.HashMap;
6 
23 public class NosTokenSceneConfig {
24 
28  public static final long NEVER_EXPIRE = 0L;
29 
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<>();
34 
35  private static int sDefaultSceneCount;
36  private static NosTokenSceneConfig sDefault = new NosTokenSceneConfig();
37 
38  private HashMap<String, Long> mNosTokenScene;
39 
40  private int maxCustomNosSceneCount = DEFAULT_CUSTOM_SCENE_COUNT;
41 
42  static {
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();
48  }
49 
50 
52  mNosTokenScene = new HashMap<>();
53  mNosTokenScene.putAll(DEFAULT_SCENE);
54  }
55 
61  return maxCustomNosSceneCount;
62  }
63 
70  public void updateDefaultProfileSceneExpireTime(int expireTime) {
71  if (expireTime < 0) {
72  throw new IllegalArgumentException("expireTimeByDay must >= 0");
73  }
74  mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_PROFILE, expireTime * DAY_SECOND);
75  }
76 
83  public void updateDefaultIMSceneExpireTime(int expireTime) {
84  if (expireTime < 0) {
85  throw new IllegalArgumentException("expireTimeByDay must >= 0");
86  }
87  mNosTokenScene.put(NimNosSceneKeyConstant.NIM_DEFAULT_IM, expireTime * DAY_SECOND);
88  }
89 
90 
98  public NosTokenSceneConfig appendCustomScene(String sceneKey, int expireTime) {
99  if (expireTime < 0 || TextUtils.isEmpty(sceneKey)) {
100  throw new IllegalArgumentException("sceneKey must not empty and expireTimeByDay must >= 0");
101  }
102  if (mNosTokenScene.size() - sDefaultSceneCount >= maxCustomNosSceneCount) {
103  throw new IllegalStateException("the custom scene count must <= " + maxCustomNosSceneCount);
104  }
105  if (NimNosSceneKeyConstant.NIM_SYSTEM_NOS_SCENE.equals(sceneKey)) {
106  throw new IllegalArgumentException("the \"nim_system_nos_scene\" scene cannot be modified");
107  }
108  mNosTokenScene.put(sceneKey, expireTime * DAY_SECOND);
109  return this;
110  }
111 
117  public HashMap<String, Long> getNosTokenScene() {
118  HashMap<String, Long> copy = new HashMap<>(mNosTokenScene.size());
119  copy.putAll(mNosTokenScene);
120  return copy;
121  }
122 
124  sDefault.mNosTokenScene = DEFAULT_SCENE;
125  return sDefault;
126  }
127 }
void updateDefaultProfileSceneExpireTime(int expireTime)
更新默认场景 NimNosSceneKeyConstant#NIM_DEFAULT_PROFILE对应的过期时间
static final long NEVER_EXPIRE
永不过期,资源一直在于服务器
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对应的过期时间