Skip to content

Commit

Permalink
refactor: 优化配置设置
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jun 14, 2024
1 parent 56ff4d3 commit 1a3d851
Showing 1 changed file with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public class ZLMediaConfigs {
/**
* 自定义密钥
*/
private String secret = UUID.randomUUID().toString().replace("-","");
private String secret = UUID.randomUUID().toString().replace("-", "");

public Map<String, String> createConfigs() {
Map<String, String> configs = new HashMap<>();

configs.put("api.secret",secret);
configs.put("api.secret", secret);

if (others != null) {
configs.putAll(others);
Expand Down Expand Up @@ -120,6 +120,21 @@ public Map<String, String> createConfigs() {
return configs;
}

public void setConfig(String key, String value) {
if (ports.setConfig(key, value)) {
return;
}
switch (key) {
case "api.secret":
secret = value;
break;
case "general.mediaServerId":
serverId = value;
break;

}
}

@Getter
@Setter
public static class Ports {
Expand All @@ -131,6 +146,34 @@ public static class Ports {
private int rtc = 8000;
private int srt = 9000;

public boolean setConfig(String key, String value) {
switch (key) {
case "rtsp.port":
setRtsp(Integer.parseInt(value));
return true;
case "rtmp.port":
setRtmp(Integer.parseInt(value));
return true;
case "http.port":
setHttp(Integer.parseInt(value));
return true;
case "rtp_proxy.port":
setRtp(Integer.parseInt(value));
return true;
case "rtp_proxy.port_range":
String[] range = value.split("-");
setRtpRange(new int[]{Integer.parseInt(range[0]), Integer.parseInt(range[1])});
return true;
case "rtc.port":
setRtc(Integer.parseInt(value));
return true;
case "srt.port":
setSrt(Integer.parseInt(value));
return true;
}
return false;
}

public void applyConfig(Map<String, String> config) {
config.put("http.port", String.valueOf(http));

Expand Down

0 comments on commit 1a3d851

Please sign in to comment.