package ai.suanzi.rtmpclient;
-import android.widget.Toast;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
public class UserInfo {
- public String server = "";
- public String user = "";
- public String macAddr = "";
- public String cameraId = "";
- private static String configPath;
private static Logger gLogger = Logger.getLogger("UserInfo");
+ public static String server = "rtmp://gpussh.suanzi.ai:1935/myapp";
+ public static String user = "yunzhi";
+ public static String macAddr = "";
+ public static String cameraId = "";
+ public static String configPath;
- private static UserInfo instance = null;
private UserInfo () {}
- public static void setConfigPath(String fname){
+ public static void readConfig(String fname, String addr){
+ gLogger.debug("readConfig - fname " + fname + ", macaddr " + addr);
configPath = fname;
- File file = new File(configPath);
- if(!file.exists()) {
- gLogger.error("Config file: " + configPath + " not exists! Create it");
- try {
- file.createNewFile();
- }catch (IOException e){
- gLogger.error("Create file error: " + e.getMessage());
- e.printStackTrace();
- }
- }
- }
- public static UserInfo getConfig() {
- if (instance != null) return instance;
-
- File file = new File(configPath);
- if (!file.exists()){
- gLogger.error("getConfig - file configpath: " + configPath + " not exists");
- return new UserInfo();
+ File file = new File (fname);
+ if(!file.exists()){
+ gLogger.debug(fname + " does not exist!.");
+ macAddr = addr;
+ return;
}
StringBuilder text = new StringBuilder();
}
String json = text.toString();
-
- UserInfo info = new UserInfo();
-
try {
JSONObject jobj = new JSONObject(json);
- info.server = jobj.getString("server");
- info.user = jobj.getString("user");
- info.macAddr = jobj.getString("macAddr");
- info.cameraId = jobj.getString("cameraId");
+ server = jobj.getString("server");
+ user = jobj.getString("user");
+ macAddr = jobj.getString("macAddr");
+ if(!macAddr.equals(addr)){
+ gLogger.debug("Mac address changed from " + macAddr + " to " + addr);
+ macAddr = addr;
+ }
+ cameraId = jobj.getString("cameraId");
} catch (JSONException e){
- gLogger.error("getConfig - error: " + e.getMessage());
+ gLogger.error("readConfig - error: " + e.getMessage());
+ macAddr = addr;
e.printStackTrace();
}
- instance = info;
- return info;
}
public boolean saveConfig() {
return true;
}
- public void update(String server, String user, String macAddr, String cameraId) {
- this.server = server;
- this.user = user;
- this.macAddr = macAddr;
- this.cameraId = cameraId;
- }
+// public void update(String server, String user, String macAddr, String cameraId) {
+// server = server;
+// user = user;
+// macAddr = macAddr;
+// cameraId = cameraId;
+// }
public String toString () {
JSONObject obj = toJsonObj();
private JSONObject toJsonObj () {
try {
JSONObject obj = new JSONObject();
- obj.put("server", this.server);
- obj.put("user", this.user);
- obj.put("macAddr", this.macAddr);
- obj.put("cameraId", this.cameraId);
+ obj.put("server", server);
+ obj.put("user", user);
+ obj.put("macAddr", macAddr);
+ obj.put("cameraId", cameraId);
return obj;
} catch (JSONException e) {
e.printStackTrace();
}
}
- public String toUrl () {
+ public static String toUrl () {
//rtmp://gpussh.suanzi.ai:1935/myapp/suanzi_ac83f34ead90_cameraid
- return server + "/" + user + "_" + macAddr + "_" + cameraId;
+ //return server + "/" + user + "_" + macAddr + "_" + cameraId;
+ return server + "/" + user + "_" + macAddr;
+
+
}
+
+// public String getValue(String key){
+// if(key.equals("server")) return server;
+// if(key.equals("user")) return user;
+// if(key.equals("macAddr")) return macAddr;
+// if(key.equals("cameraId")) return cameraId;
+// return "";
+// }
+
}