| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.MediaConfig; |
| | | import okhttp3.*; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(ZLMRESTfulUtils.class); |
| | | |
| | | @Value("${media.ip}") |
| | | private String mediaIp; |
| | | |
| | | @Value("${media.port}") |
| | | private int mediaPort; |
| | | |
| | | @Value("${media.secret}") |
| | | private String mediaSecret; |
| | | @Autowired |
| | | private MediaConfig mediaConfig; |
| | | |
| | | public interface RequestCallback{ |
| | | void run(JSONObject response); |
| | |
| | | |
| | | public JSONObject sendPost(String api, Map<String, Object> param, RequestCallback callback) { |
| | | OkHttpClient client = new OkHttpClient(); |
| | | String url = String.format("http://%s:%s/index/api/%s", mediaIp, mediaPort, api); |
| | | String url = String.format("http://%s:%s/index/api/%s", mediaConfig.getIp(), mediaConfig.getHttpPort(), api); |
| | | JSONObject responseJSON = null; |
| | | logger.debug(url); |
| | | |
| | | FormBody.Builder builder = new FormBody.Builder(); |
| | | builder.add("secret",mediaSecret); |
| | | builder.add("secret",mediaConfig.getSecret()); |
| | | if (param != null && param.keySet().size() > 0) { |
| | | for (String key : param.keySet()){ |
| | | if (param.get(key) != null) { |
| | |
| | | } |
| | | |
| | | public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms){ |
| | | System.out.println(src_url); |
| | | System.out.println(dst_url); |
| | | logger.info(src_url); |
| | | logger.info(dst_url); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("src_url", src_url); |
| | | param.put("dst_url", dst_url); |
| | |
| | | param.put("force", 1); |
| | | return sendPost("close_streams",param, null); |
| | | } |
| | | |
| | | public JSONObject getAllSession() { |
| | | return sendPost("getAllSession",null, null); |
| | | } |
| | | |
| | | public void kickSessions(String localPortSStr) { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("local_port", localPortSStr); |
| | | sendPost("kick_sessions",param, null); |
| | | } |
| | | } |