Compare commits

...

5 Commits

Author SHA1 Message Date
阿斌
e866959451
Pre Merge pull request !41 from 阿斌/N/A 2025-09-16 02:53:35 +00:00
lin
c1672728d3 优化zlm结果封装完成 2025-09-16 10:52:58 +08:00
lin
576feec514 临时提交 2025-09-15 18:01:00 +08:00
lin
5c83bf2a41 临时提交 2025-09-15 17:59:18 +08:00
阿斌
34d1dbb399
修复两次密码不一致时,任然可以修改密码,且成功提交,密码用*代替
还有以下一处需要修改web\src\layout\components\dialog\changePassword.vue

Signed-off-by: 阿斌 <38912748@qq.com>
2025-08-23 15:03:02 +00:00
12 changed files with 708 additions and 291 deletions

View File

@ -398,6 +398,8 @@ public class PlatformServiceImpl implements IPlatformService, CommandLineRunner
SipTransactionInfo transactionInfo = statusTaskRunner.getRegisterTransactionInfo(platformInDb.getServerGBId());
// 注销后出发平台离线 如果是启用的平台那么下次丢失检测会检测到并重新注册上线
sendUnRegister(platformInDb, transactionInfo);
}else if (platform.isEnable()) {
sendRegister(platform, null);
}
return false;

View File

@ -209,7 +209,7 @@ public class AssistRESTfulUtils {
if (response.isSuccessful()) {
try {
String responseStr = Objects.requireNonNull(response.body()).string();
callback.run(JSON.parseObject(responseStr));
callback.run(responseStr);
} catch (IOException e) {
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
}

View File

@ -11,7 +11,7 @@ import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
import com.genersoft.iot.vmp.media.bean.MediaInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
@ -71,9 +71,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
if (mediaServer == null) {
return false;
}
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (responseJSON != null) {
JSONArray data = responseJSON.getJSONArray("data");
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (mediaServerConfig != null) {
List<JSONObject> data = mediaServerConfig.getData();
if (data != null && !data.isEmpty()) {
ZLMServerConfig zlmServerConfig= JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
return zlmServerConfig.getGeneralMediaServerId().equals(mediaServer.getId());
@ -100,15 +100,15 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
mediaServer.setFlvPort(port);
mediaServer.setWsFlvPort(port);
mediaServer.setSecret(secret);
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (responseJSON == null) {
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (mediaServerConfigResult == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
}
JSONArray data = responseJSON.getJSONArray("data");
if (data == null) {
List<JSONObject> configList = mediaServerConfigResult.getData();
if (configList == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
}
ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(configList.get(0)), ZLMServerConfig.class);
if (zlmServerConfig == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
}
@ -138,12 +138,12 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
if (!ObjectUtils.isEmpty(ssrc)) {
param.put("ssrc", ssrc);
}
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
if (jsonObject.getInteger("code") != null && jsonObject.getInteger("code") == 0) {
ZLMResult<?> zlmResult = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
if (zlmResult.getCode() == 0) {
log.info("[停止发流] 成功: 参数:{}", JSON.toJSONString(param));
return true;
}else {
log.info("停止发流结果: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
log.info("停止发流结果: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
return false;
}
}
@ -157,9 +157,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
if (!ObjectUtils.isEmpty(ssrc)) {
param.put("ssrc", ssrc);
}
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
log.error("停止发流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
ZLMResult<?> zlmResult = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
if (zlmResult.getCode() != 0 ) {
log.error("停止发流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
return false;
}
return true;
@ -168,12 +168,12 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public boolean deleteRecordDirectory(MediaServer mediaServer, String app, String stream, String date, String fileName) {
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件, server: {} {}:{}->{}/{}", mediaServer.getId(), app, stream, date, fileName);
JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServer, app,
ZLMResult<?> zlmResult = zlmresTfulUtils.deleteRecordDirectory(mediaServer, app,
stream, date, fileName);
if (jsonObject.getInteger("code") == 0) {
if (zlmResult.getCode() == 0) {
return true;
}else {
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件错误, server: {} {}:{}->{}/{}, 结果: {}", mediaServer.getId(), app, stream, date, fileName, jsonObject);
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件错误, server: {} {}:{}->{}/{}, 结果: {}", mediaServer.getId(), app, stream, date, fileName, zlmResult);
throw new ControllerException(ErrorCode.ERROR100.getCode(), "删除磁盘文件失败");
}
}
@ -181,15 +181,14 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public List<StreamInfo> getMediaList(MediaServer mediaServer, String app, String stream, String callId) {
List<StreamInfo> streamInfoList = new ArrayList<>();
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaServer, app, stream);
if (mediaList != null) {
if (mediaList.getInteger("code") == 0) {
JSONArray dataArray = mediaList.getJSONArray("data");
if (dataArray == null) {
ZLMResult<JSONArray> zlmResult = zlmresTfulUtils.getMediaList(mediaServer, app, stream);
if (zlmResult != null) {
if (zlmResult.getCode() == 0) {
if (zlmResult.getData() == null) {
return streamInfoList;
}
for (int i = 0; i < dataArray.size(); i++) {
JSONObject mediaJSON = dataArray.getJSONObject(0);
for (int i = 0; i < zlmResult.getData().size(); i++) {
JSONObject mediaJSON = zlmResult.getData().getJSONObject(0);
MediaInfo mediaInfo = MediaInfo.getInstance(mediaJSON, mediaServer, userSetting.getServerId());
StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServer, mediaInfo.getApp(), mediaInfo.getStream(), mediaInfo, callId, true);
if (streamInfo != null) {
@ -249,9 +248,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public Boolean connectRtpServer(MediaServer mediaServer, String address, int port, String stream) {
JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServer, address, port, stream);
log.info("[TCP主动连接对方] 结果: {}", jsonObject);
return jsonObject.getInteger("code") == 0;
ZLMResult<?> zlmResult = zlmresTfulUtils.connectRtpServer(mediaServer, address, port, stream);
log.info("[TCP主动连接对方] 结果: {}", zlmResult);
return zlmResult.getCode() == 0;
}
@Override
@ -267,34 +266,34 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream) {
JSONObject jsonObject = zlmresTfulUtils.getMediaInfo(mediaServer, app, "rtsp", stream);
if (jsonObject.getInteger("code") != 0) {
ZLMResult<JSONObject> zlmResult = zlmresTfulUtils.getMediaInfo(mediaServer, app, "rtsp", stream);
if (zlmResult.getCode() != 0) {
return null;
}
return MediaInfo.getInstance(jsonObject, mediaServer, userSetting.getServerId());
return MediaInfo.getInstance(zlmResult.getData(), mediaServer, userSetting.getServerId());
}
@Override
public Boolean pauseRtpCheck(MediaServer mediaServer, String streamKey) {
JSONObject jsonObject = zlmresTfulUtils.pauseRtpCheck(mediaServer, streamKey);
return jsonObject.getInteger("code") == 0;
ZLMResult<?> zlmResult = zlmresTfulUtils.pauseRtpCheck(mediaServer, streamKey);
return zlmResult.getCode() == 0;
}
@Override
public Boolean resumeRtpCheck(MediaServer mediaServer, String streamKey) {
JSONObject jsonObject = zlmresTfulUtils.resumeRtpCheck(mediaServer, streamKey);
return jsonObject.getInteger("code") == 0;
ZLMResult<?> zlmResult = zlmresTfulUtils.resumeRtpCheck(mediaServer, streamKey);
return zlmResult.getCode() == 0;
}
@Override
public String getFfmpegCmd(MediaServer mediaServer, String cmdKey) {
JSONObject jsonObject = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (jsonObject.getInteger("code") != 0) {
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (mediaServerConfigResult == null || mediaServerConfigResult.getCode() != 0) {
log.warn("[getFfmpegCmd] 获取流媒体配置失败");
throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取流媒体配置失败");
}
JSONArray dataArray = jsonObject.getJSONArray("data");
JSONObject mediaServerConfig = dataArray.getJSONObject(0);
List<JSONObject> data = mediaServerConfigResult.getData();
JSONObject mediaServerConfig = data.get(0);
if (ObjectUtils.isEmpty(cmdKey)) {
cmdKey = "ffmpeg.cmd";
}
@ -304,42 +303,42 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public WVPResult<String> addStreamProxy(MediaServer mediaServer, String app, String stream, String url,
boolean enableAudio, boolean enableMp4, String rtpType, Integer timeout) {
JSONObject jsonObject = zlmresTfulUtils.addStreamProxy(mediaServer, app, stream, url, enableAudio, enableMp4, rtpType, timeout);
if (jsonObject.getInteger("code") != 0) {
ZLMResult<StreamProxyResult> zlmResult = zlmresTfulUtils.addStreamProxy(mediaServer, app, stream, url, enableAudio, enableMp4, rtpType, timeout);
if (zlmResult.getCode() != 0) {
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "添加代理失败");
}else {
JSONObject data = jsonObject.getJSONObject("data");
StreamProxyResult data = zlmResult.getData();
if (data == null) {
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "代理结果异常 " + jsonObject);
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "代理结果异常");
}else {
return WVPResult.success(data.getString("key"));
return WVPResult.success(data.getKey());
}
}
}
@Override
public Boolean delFFmpegSource(MediaServer mediaServer, String streamKey) {
JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(mediaServer, streamKey);
return jsonObject.getInteger("code") == 0;
ZLMResult<FlagData> flagDataZLMResult = zlmresTfulUtils.delFFmpegSource(mediaServer, streamKey);
return flagDataZLMResult != null && flagDataZLMResult.getCode() == 0;
}
@Override
public Boolean delStreamProxy(MediaServer mediaServer, String streamKey) {
JSONObject jsonObject = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
return jsonObject.getInteger("code") == 0;
ZLMResult<FlagData> flagDataZLMResult = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
return flagDataZLMResult != null && flagDataZLMResult.getCode() == 0;
}
@Override
public Map<String, String> getFFmpegCMDs(MediaServer mediaServer) {
Map<String, String> result = new HashMap<>();
JSONObject mediaServerConfigResuly = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (mediaServerConfigResuly != null && mediaServerConfigResuly.getInteger("code") == 0
&& mediaServerConfigResuly.getJSONArray("data").size() > 0){
JSONObject mediaServerConfig = mediaServerConfigResuly.getJSONArray("data").getJSONObject(0);
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
if (mediaServerConfigResult != null && mediaServerConfigResult.getCode() == 0
&& !mediaServerConfigResult.getData().isEmpty()){
JSONObject jsonObject = mediaServerConfigResult.getData().get(0);
for (String key : mediaServerConfig.keySet()) {
for (String key : jsonObject.keySet()) {
if (key.startsWith("ffmpeg.cmd")){
result.put(key, mediaServerConfig.getString(key));
result.put(key, jsonObject.getString(key));
}
}
}
@ -372,15 +371,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
param.put("dst_port", sendRtpItem.getPort());
}
JSONObject jsonObject = zlmServerFactory.startSendRtpPassive(mediaServer, param, null);
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
log.error("启动监听TCP被动推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
ZLMResult<?> zlmResult = zlmServerFactory.startSendRtpPassive(mediaServer, param, null);
if (zlmResult.getCode() != 0 ) {
log.error("启动监听TCP被动推流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
log.info("调用ZLM-TCP被动推流接口, 结果: {}", jsonObject);
log.info("启动监听TCP被动推流成功[ {}/{} ]{}->{}:{}, " , sendRtpItem.getApp(), sendRtpItem.getStream(),
jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
return jsonObject.getInteger("local_port");
log.info("调用ZLM-TCP被动推流接口成功 本地端口: {}", zlmResult.getLocal_port());
return zlmResult.getLocal_port();
}
@Override
@ -402,13 +399,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
}
param.put("dst_url", sendRtpItem.getIp());
param.put("dst_port", sendRtpItem.getPort());
JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServer, param);
if (jsonObject == null ) {
ZLMResult<?> zlmResult = zlmresTfulUtils.startSendRtp(mediaServer, param);
if (zlmResult == null ) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接zlm失败");
}else if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
}else if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
log.info("[推流结果]{} ,参数: {}",jsonObject, JSONObject.toJSONString(param));
log.info("[推流结果]{} ,参数: {}", zlmResult, JSONObject.toJSONString(param));
}
@Override
@ -423,15 +420,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
param.put("recv_stream_id", sendRtpItem.getReceiveStream());
param.put("enable_origin_recv_limit", "1");
JSONObject jsonObject = zlmServerFactory.startSendRtpTalk(mediaServer, param, null);
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
log.error("启动监听TCP被动推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
ZLMResult<?> zlmResult = zlmServerFactory.startSendRtpTalk(mediaServer, param, null);
if (zlmResult.getCode() != 0 ) {
log.error("启动监听TCP被动推流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
log.info("调用ZLM-TCP被动推流接口, 结果: {}", jsonObject);
log.info("启动监听TCP被动推流成功[ {}/{} ]{}->{}:{}, " , sendRtpItem.getApp(), sendRtpItem.getStream(),
jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
return jsonObject.getInteger("local_port");
log.info("调用ZLM-TCP被动推流接口, 成功 本地端口: {}", zlmResult.getLocal_port());
return zlmResult.getLocal_port();
}
@Override
@ -486,28 +481,26 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
closeStreams(mediaServer, streamProxy.getApp(), streamProxy.getStream());
}
JSONObject jsonObject = null;
ZLMResult<StreamProxyResult> zlmResult = null;
if ("ffmpeg".equalsIgnoreCase(streamProxy.getType())){
if (streamProxy.getTimeout() == 0) {
streamProxy.setTimeout(15);
}
jsonObject = zlmresTfulUtils.addFFmpegSource(mediaServer, streamProxy.getSrcUrl().trim(), dstUrl,
zlmResult = zlmresTfulUtils.addFFmpegSource(mediaServer, streamProxy.getSrcUrl().trim(), dstUrl,
streamProxy.getTimeout(), streamProxy.isEnableAudio(), streamProxy.isEnableMp4(),
streamProxy.getFfmpegCmdKey());
}else {
jsonObject = zlmresTfulUtils.addStreamProxy(mediaServer, streamProxy.getApp(), streamProxy.getStream(), streamProxy.getSrcUrl().trim(),
zlmResult = zlmresTfulUtils.addStreamProxy(mediaServer, streamProxy.getApp(), streamProxy.getStream(), streamProxy.getSrcUrl().trim(),
streamProxy.isEnableAudio(), streamProxy.isEnableMp4(), streamProxy.getRtspType(), streamProxy.getTimeout());
}
if (jsonObject == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
}else if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}else {
JSONObject data = jsonObject.getJSONObject("data");
StreamProxyResult data = zlmResult.getData();
if (data == null) {
throw new ControllerException(jsonObject.getInteger("code"), "代理结果异常: " + jsonObject);
throw new ControllerException(zlmResult.getCode(), "代理结果异常: " + zlmResult);
}else {
return data.getString("key");
return data.getKey();
}
}
}
@ -533,62 +526,61 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
@Override
public void stopProxy(MediaServer mediaServer, String streamKey, String type) {
JSONObject jsonObject = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
if (jsonObject == null) {
ZLMResult<FlagData> zlmResult = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
if (zlmResult == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
}else if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
}else if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
}
@Override
public List<String> listRtpServer(MediaServer mediaServer) {
JSONObject jsonObject = zlmresTfulUtils.listRtpServer(mediaServer);
ZLMResult<List<RtpServerResult>> zlmResult = zlmresTfulUtils.listRtpServer(mediaServer);
List<String> result = new ArrayList<>();
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
if (zlmResult.getCode() != 0) {
return result;
}
JSONArray data = jsonObject.getJSONArray("data");
List<RtpServerResult> data = zlmResult.getData();
if (data == null || data.isEmpty()) {
return result;
}
for (int i = 0; i < data.size(); i++) {
JSONObject dataJSONObject = data.getJSONObject(i);
result.add(dataJSONObject.getString("stream_id"));
for (RtpServerResult datum : data) {
result.add(datum.getStream_id());
}
return result;
}
@Override
public void loadMP4File(MediaServer mediaServer, String app, String stream, String datePath) {
JSONObject jsonObject = zlmresTfulUtils.loadMP4File(mediaServer, app, stream, datePath);
if (jsonObject == null) {
ZLMResult<?> zlmResult = zlmresTfulUtils.loadMP4File(mediaServer, app, stream, datePath);
if (zlmResult == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
}
if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
}
@Override
public void seekRecordStamp(MediaServer mediaServer, String app, String stream, Double stamp, String schema) {
JSONObject jsonObject = zlmresTfulUtils.seekRecordStamp(mediaServer, app, stream, stamp, schema);
if (jsonObject == null) {
ZLMResult<?> zlmResult = zlmresTfulUtils.seekRecordStamp(mediaServer, app, stream, stamp, schema);
if (zlmResult == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
}
if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
}
@Override
public void setRecordSpeed(MediaServer mediaServer, String app, String stream, Integer speed, String schema) {
JSONObject jsonObject = zlmresTfulUtils.setRecordSpeed(mediaServer, app, stream, speed, schema);
if (jsonObject == null) {
ZLMResult<?> zlmResult = zlmresTfulUtils.setRecordSpeed(mediaServer, app, stream, speed, schema);
if (zlmResult == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
}
if (jsonObject.getInteger("code") != 0) {
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
if (zlmResult.getCode() != 0) {
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
}
}
}

View File

@ -1,7 +1,6 @@
package com.genersoft.iot.vmp.media.zlm;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
@ -9,6 +8,7 @@ import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerDeleteEvent;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.media.zlm.dto.ZLMResult;
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent;
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent;
@ -23,6 +23,7 @@ import org.springframework.util.ObjectUtils;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@ -136,13 +137,13 @@ public class ZLMMediaServerStatusManager {
continue;
}
log.info("[ZLM-尝试连接] ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
ZLMServerConfig zlmServerConfig = null;
if (responseJson == null) {
if (mediaServerConfigResult == null) {
log.info("[ZLM-尝试连接]失败, ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
continue;
}
JSONArray data = responseJson.getJSONArray("data");
List<JSONObject> data = mediaServerConfigResult.getData();
if (data == null || data.isEmpty()) {
log.info("[ZLM-尝试连接]失败, ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
}else {
@ -158,14 +159,14 @@ public class ZLMMediaServerStatusManager {
continue;
}
log.info("[ZLM-尝试连接] ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
ZLMServerConfig zlmServerConfig = null;
if (responseJson == null) {
if (mediaServerConfig == null) {
log.info("[ZLM-尝试连接]失败, ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
continue;
}
JSONArray data = responseJson.getJSONArray("data");
List<JSONObject> data = mediaServerConfig.getData();
if (data == null || data.isEmpty()) {
log.info("[ZLM-尝试连接]失败, ID{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
@ -190,8 +191,8 @@ public class ZLMMediaServerStatusManager {
eventPublisher.mediaServerOnlineEventPublish(mediaServerItem);
if(mediaServerItem.isAutoConfig()) {
if (config == null) {
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
JSONArray data = responseJSON.getJSONArray("data");
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
List<JSONObject> data = mediaServerConfig.getData();
if (data != null && !data.isEmpty()) {
config = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
}
@ -298,9 +299,9 @@ public class ZLMMediaServerStatusManager {
param.put("record.appName", recordPathFile.getName());
}
JSONObject responseJSON = zlmresTfulUtils.setServerConfig(mediaServerItem, param);
ZLMResult<?> zlmResult = zlmresTfulUtils.setServerConfig(mediaServerItem, param);
if (responseJSON != null && responseJSON.getInteger("code") == 0) {
if (zlmResult != null && zlmResult.getCode() == 0) {
if (restart) {
log.info("[媒体服务节点] 设置成功,开始重启以保证配置生效 {} -> {}:{}",
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());

View File

@ -1,8 +1,11 @@
package com.genersoft.iot.vmp.media.zlm;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.zlm.dto.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import okhttp3.logging.HttpLoggingInterceptor;
@ -16,6 +19,7 @@ import java.math.BigDecimal;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@ -28,7 +32,10 @@ public class ZLMRESTfulUtils {
public interface RequestCallback{
void run(JSONObject response);
void run(String response);
}
public interface ResultCallback{
void run(ZLMResult<?> response);
}
private OkHttpClient getClient(){
@ -62,26 +69,22 @@ public class ZLMRESTfulUtils {
}
public JSONObject sendPost(MediaServer mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
return sendPost(mediaServerItem, api, param, callback, null);
public String sendPost(MediaServer mediaServer, String api, Map<String, Object> param, RequestCallback callback) {
return sendPost(mediaServer, api, param, callback, null);
}
public JSONObject sendPost(MediaServer mediaServerItem, String api, Map<String, Object> param, RequestCallback callback, Integer readTimeOut) {
public String sendPost(MediaServer mediaServer, String api, Map<String, Object> param, RequestCallback callback, Integer readTimeOut) {
OkHttpClient client = getClient(readTimeOut);
if (mediaServerItem == null) {
if (mediaServer == null) {
return null;
}
String url = String.format("http://%s:%s/index/api/%s", mediaServerItem.getIp(), mediaServerItem.getHttpPort(), api);
JSONObject responseJSON = new JSONObject();
//-2自定义流媒体 调用错误码
responseJSON.put("code",-2);
responseJSON.put("msg","流媒体调用失败");
String url = String.format("http://%s:%s/index/api/%s", mediaServer.getIp(), mediaServer.getHttpPort(), api);
String result = null;
FormBody.Builder builder = new FormBody.Builder();
builder.add("secret",mediaServerItem.getSecret());
if (param != null && param.keySet().size() > 0) {
builder.add("secret",mediaServer.getSecret());
if (param != null && !param.isEmpty()) {
for (String key : param.keySet()){
if (param.get(key) != null) {
builder.add(key, param.get(key).toString());
@ -101,8 +104,7 @@ public class ZLMRESTfulUtils {
if (response.isSuccessful()) {
ResponseBody responseBody = response.body();
if (responseBody != null) {
String responseStr = responseBody.string();
responseJSON = JSON.parseObject(responseStr);
result = responseBody.string();
}
}else {
response.close();
@ -131,7 +133,7 @@ public class ZLMRESTfulUtils {
if (response.isSuccessful()) {
try {
String responseStr = Objects.requireNonNull(response.body()).string();
callback.run(JSON.parseObject(responseStr));
callback.run(responseStr);
} catch (IOException e) {
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
}
@ -158,20 +160,18 @@ public class ZLMRESTfulUtils {
});
}
return responseJSON;
return result;
}
public void sendGetForImg(MediaServer mediaServerItem, String api, Map<String, Object> params, String targetPath, String fileName) {
String url = String.format("http://%s:%s/index/api/%s", mediaServerItem.getIp(), mediaServerItem.getHttpPort(), api);
public void sendGetForImg(MediaServer mediaServer, String api, Map<String, Object> params, String targetPath, String fileName) {
String url = String.format("http://%s:%s/index/api/%s", mediaServer.getIp(), mediaServer.getHttpPort(), api);
HttpUrl parseUrl = HttpUrl.parse(url);
if (parseUrl == null) {
return;
}
HttpUrl.Builder httpBuilder = parseUrl.newBuilder();
httpBuilder.addQueryParameter("secret", mediaServerItem.getSecret());
httpBuilder.addQueryParameter("secret", mediaServer.getSecret());
if (params != null) {
for (Map.Entry<String, Object> param : params.entrySet()) {
httpBuilder.addQueryParameter(param.getKey(), param.getValue().toString());
@ -217,7 +217,7 @@ public class ZLMRESTfulUtils {
}
}
public JSONObject isMediaOnline(MediaServer mediaServerItem, String app, String stream, String schema){
public ZLMResult<?> isMediaOnline(MediaServer mediaServer, String app, String stream, String schema){
Map<String, Object> param = new HashMap<>();
if (app != null) {
param.put("app",app);
@ -229,10 +229,20 @@ public class ZLMRESTfulUtils {
param.put("schema",schema);
}
param.put("vhost","__defaultVhost__");
return sendPost(mediaServerItem, "isMediaOnline", param, null);
String response = sendPost(mediaServer, "isMediaOnline", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject getMediaList(MediaServer mediaServerItem, String app, String stream, String schema, RequestCallback callback){
public ZLMResult<JSONArray> getMediaList(MediaServer mediaServer, String app, String stream, String schema, ResultCallback callback){
Map<String, Object> param = new HashMap<>();
if (app != null) {
param.put("app",app);
@ -244,106 +254,325 @@ public class ZLMRESTfulUtils {
param.put("schema",schema);
}
param.put("vhost","__defaultVhost__");
return sendPost(mediaServerItem, "getMediaList",param, callback);
String response = sendPost(mediaServer, "getMediaList",param, (responseStr -> {
if (callback == null) {
return;
}
if (responseStr == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
ZLMResult<JSONArray> zlmResult = JSON.parseObject(responseStr, new TypeReference<ZLMResult<JSONArray>>() {});
if (zlmResult == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
callback.run(zlmResult);
}
}
}));
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<JSONArray> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<JSONArray>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject getMediaList(MediaServer mediaServerItem, String app, String stream){
return getMediaList(mediaServerItem, app, stream,null, null);
public ZLMResult<JSONArray> getMediaList(MediaServer mediaServer, String app, String stream){
return getMediaList(mediaServer, app, stream,null, null);
}
public JSONObject getMediaList(MediaServer mediaServerItem, RequestCallback callback){
return sendPost(mediaServerItem, "getMediaList",null, callback);
}
public JSONObject getMediaInfo(MediaServer mediaServerItem, String app, String schema, String stream){
public ZLMResult<JSONObject> getMediaInfo(MediaServer mediaServer, String app, String schema, String stream){
Map<String, Object> param = new HashMap<>();
param.put("app",app);
param.put("schema",schema);
param.put("stream",stream);
param.put("vhost","__defaultVhost__");
return sendPost(mediaServerItem, "getMediaInfo",param, null);
String response = sendPost(mediaServer, "getMediaInfo",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
JSONObject jsonObject = JSON.parseObject(response);
if (jsonObject == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<JSONObject> zlmResult = new ZLMResult<>();
zlmResult.setCode(0);
zlmResult.setData(jsonObject);
return zlmResult;
}
}
}
public JSONObject getRtpInfo(MediaServer mediaServerItem, String stream_id){
public ZLMResult<?> getRtpInfo(MediaServer mediaServer, String stream_id){
Map<String, Object> param = new HashMap<>();
param.put("stream_id",stream_id);
return sendPost(mediaServerItem, "getRtpInfo",param, null);
String response = sendPost(mediaServer, "getRtpInfo",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject addFFmpegSource(MediaServer mediaServerItem, String src_url, String dst_url, Integer timeout_sec,
public ZLMResult<StreamProxyResult> addFFmpegSource(MediaServer mediaServer, String src_url, String dst_url, Integer timeout_sec,
boolean enable_audio, boolean enable_mp4, String ffmpeg_cmd_key){
log.info(src_url);
log.info(dst_url);
Map<String, Object> param = new HashMap<>();
param.put("src_url", src_url);
param.put("dst_url", dst_url);
param.put("timeout_ms", timeout_sec*1000);
param.put("enable_mp4", enable_mp4);
param.put("ffmpeg_cmd_key", ffmpeg_cmd_key);
return sendPost(mediaServerItem, "addFFmpegSource",param, null);
String response = sendPost(mediaServer, "addFFmpegSource",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<StreamProxyResult> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject delFFmpegSource(MediaServer mediaServerItem, String key){
public ZLMResult<FlagData> delFFmpegSource(MediaServer mediaServer, String key){
Map<String, Object> param = new HashMap<>();
param.put("key", key);
return sendPost(mediaServerItem, "delFFmpegSource",param, null);
String response = sendPost(mediaServer, "delFFmpegSource",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject delStreamProxy(MediaServer mediaServerItem, String key){
public ZLMResult<FlagData> delStreamProxy(MediaServer mediaServer, String key){
Map<String, Object> param = new HashMap<>();
param.put("key", key);
return sendPost(mediaServerItem, "delStreamProxy",param, null);
String response = sendPost(mediaServer, "delStreamProxy",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject getMediaServerConfig(MediaServer mediaServerItem){
return sendPost(mediaServerItem, "getServerConfig",null, null);
public ZLMResult<List<JSONObject>> getMediaServerConfig(MediaServer mediaServer ){
String response = sendPost(mediaServer, "getServerConfig",null, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<List<JSONObject>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<JSONObject>>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject setServerConfig(MediaServer mediaServerItem, Map<String, Object> param){
return sendPost(mediaServerItem,"setServerConfig",param, null);
public ZLMResult<?> setServerConfig(MediaServer mediaServer, Map<String, Object> param){
String response = sendPost(mediaServer, "setServerConfig",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject openRtpServer(MediaServer mediaServerItem, Map<String, Object> param){
return sendPost(mediaServerItem, "openRtpServer",param, null);
public ZLMResult<?> openRtpServer(MediaServer mediaServer, Map<String, Object> param){
String response = sendPost(mediaServer, "openRtpServer",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject closeRtpServer(MediaServer mediaServerItem, Map<String, Object> param) {
return sendPost(mediaServerItem, "closeRtpServer",param, null);
public ZLMResult<?> closeRtpServer(MediaServer mediaServer, Map<String, Object> param) {
String response = sendPost(mediaServer, "closeRtpServer",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public void closeRtpServer(MediaServer mediaServerItem, Map<String, Object> param, RequestCallback callback) {
sendPost(mediaServerItem, "closeRtpServer",param, callback);
public void closeRtpServer(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
sendPost(mediaServer, "closeRtpServer",param, (response -> {
if (callback == null) {
return;
}
if (response == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
callback.run(JSON.parseObject(response, ZLMResult.class));
}
}));
}
public JSONObject listRtpServer(MediaServer mediaServerItem) {
return sendPost(mediaServerItem, "listRtpServer",null, null);
public ZLMResult<List<RtpServerResult>> listRtpServer(MediaServer mediaServer) {
String response = sendPost(mediaServer, "listRtpServer",null, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<List<RtpServerResult>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<RtpServerResult>>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject startSendRtp(MediaServer mediaServerItem, Map<String, Object> param) {
return sendPost(mediaServerItem, "startSendRtp",param, null);
public ZLMResult<?> startSendRtp(MediaServer mediaServer, Map<String, Object> param) {
String response = sendPost(mediaServer, "startSendRtp",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param) {
return sendPost(mediaServerItem, "startSendRtpPassive",param, null);
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServer, Map<String, Object> param) {
String response = sendPost(mediaServer, "startSendRtpPassive",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param, RequestCallback callback) {
return sendPost(mediaServerItem, "startSendRtpPassive",param, callback);
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
String response = sendPost(mediaServer, "startSendRtpPassive",param, (responseStr -> {
if (callback == null) {
return;
}
if (responseStr == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
ZLMResult<?> zlmResult = JSON.parseObject(responseStr, ZLMResult.class);
if (zlmResult == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
callback.run(zlmResult);
}
}
}));
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject startSendRtpTalk(MediaServer mediaServerItem, Map<String, Object> param, RequestCallback callback) {
return sendPost(mediaServerItem, "startSendRtpTalk",param, callback);
public ZLMResult<?> startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
String response = sendPost(mediaServer, "startSendRtpTalk",param, (responseStr -> {
if (callback == null) {
return;
}
if (responseStr == null) {
callback.run(ZLMResult.getFailForMediaServer());
}else {
callback.run(JSON.parseObject(responseStr, ZLMResult.class));
}
}));
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject stopSendRtp(MediaServer mediaServerItem, Map<String, Object> param) {
return sendPost(mediaServerItem, "stopSendRtp",param, null);
public ZLMResult<?> stopSendRtp(MediaServer mediaServer, Map<String, Object> param) {
String response = sendPost(mediaServer, "stopSendRtp",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject restartServer(MediaServer mediaServerItem) {
return sendPost(mediaServerItem, "restartServer",null, null);
public ZLMResult<?> restartServer(MediaServer mediaServer) {
String response = sendPost(mediaServer, "restartServer",null, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject addStreamProxy(MediaServer mediaServerItem, String app, String stream, String url, boolean enable_audio, boolean enable_mp4, String rtp_type, Integer timeOut) {
public ZLMResult<StreamProxyResult> addStreamProxy(MediaServer mediaServer, String app, String stream, String url, boolean enable_audio, boolean enable_mp4, String rtp_type, Integer timeOut) {
Map<String, Object> param = new HashMap<>();
param.put("vhost", "__defaultVhost__");
param.put("app", app);
@ -355,95 +584,198 @@ public class ZLMRESTfulUtils {
param.put("timeout_sec", timeOut);
// 拉流重试次数,默认为3
param.put("retry_count", 3);
return sendPost(mediaServerItem, "addStreamProxy",param, null, 20);
String response = sendPost(mediaServer, "addStreamProxy",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<StreamProxyResult> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject closeStreams(MediaServer mediaServerItem, String app, String stream) {
public ZLMResult<FlagData> closeStreams(MediaServer mediaServer, String app, String stream) {
Map<String, Object> param = new HashMap<>();
param.put("vhost", "__defaultVhost__");
param.put("app", app);
param.put("stream", stream);
param.put("force", 1);
return sendPost(mediaServerItem, "close_streams",param, null);
String response = sendPost(mediaServer, "close_streams",param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject getAllSession(MediaServer mediaServerItem) {
return sendPost(mediaServerItem, "getAllSession",null, null);
public ZLMResult<List<SessionData>> getAllSession(MediaServer mediaServer) {
String response = sendPost(mediaServer, "getAllSession",null, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<List<SessionData>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<SessionData>>>() {});
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public void kickSessions(MediaServer mediaServerItem, String localPortSStr) {
public void kickSessions(MediaServer mediaServer, String localPortSStr) {
Map<String, Object> param = new HashMap<>();
param.put("local_port", localPortSStr);
sendPost(mediaServerItem, "kick_sessions",param, null);
sendPost(mediaServer, "kick_sessions",param, null);
}
public void getSnap(MediaServer mediaServerItem, String streamUrl, int timeout_sec, int expire_sec, String targetPath, String fileName) {
public void getSnap(MediaServer mediaServer, String streamUrl, int timeout_sec, int expire_sec, String targetPath, String fileName) {
Map<String, Object> param = new HashMap<>(3);
param.put("url", streamUrl);
param.put("timeout_sec", timeout_sec);
param.put("expire_sec", expire_sec);
param.put("async", 1);
sendGetForImg(mediaServerItem, "getSnap", param, targetPath, fileName);
sendGetForImg(mediaServer, "getSnap", param, targetPath, fileName);
}
public JSONObject pauseRtpCheck(MediaServer mediaServerItem, String streamId) {
public ZLMResult<?> pauseRtpCheck(MediaServer mediaServer, String streamId) {
Map<String, Object> param = new HashMap<>(1);
param.put("stream_id", streamId);
return sendPost(mediaServerItem, "pauseRtpCheck",param, null);
String response = sendPost(mediaServer, "pauseRtpCheck", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject resumeRtpCheck(MediaServer mediaServerItem, String streamId) {
public ZLMResult<?> resumeRtpCheck(MediaServer mediaServer, String streamId) {
Map<String, Object> param = new HashMap<>(1);
param.put("stream_id", streamId);
return sendPost(mediaServerItem, "resumeRtpCheck",param, null);
String response = sendPost(mediaServer, "resumeRtpCheck", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject connectRtpServer(MediaServer mediaServerItem, String dst_url, int dst_port, String stream_id) {
public ZLMResult<?> connectRtpServer(MediaServer mediaServer, String dst_url, int dst_port, String stream_id) {
Map<String, Object> param = new HashMap<>(1);
param.put("dst_url", dst_url);
param.put("dst_port", dst_port);
param.put("stream_id", stream_id);
return sendPost(mediaServerItem, "connectRtpServer",param, null);
String response = sendPost(mediaServer, "connectRtpServer", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject updateRtpServerSSRC(MediaServer mediaServerItem, String streamId, String ssrc) {
public ZLMResult<?> updateRtpServerSSRC(MediaServer mediaServer, String streamId, String ssrc) {
Map<String, Object> param = new HashMap<>(1);
param.put("ssrc", ssrc);
param.put("stream_id", streamId);
return sendPost(mediaServerItem, "updateRtpServerSSRC",param, null);
String response = sendPost(mediaServer, "updateRtpServerSSRC", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject deleteRecordDirectory(MediaServer mediaServerItem, String app, String stream, String date, String fileName) {
public ZLMResult<?> deleteRecordDirectory(MediaServer mediaServer, String app, String stream, String date, String fileName) {
Map<String, Object> param = new HashMap<>(1);
param.put("vhost", "__defaultVhost__");
param.put("app", app);
param.put("stream", stream);
param.put("period", date);
param.put("name", fileName);
return sendPost(mediaServerItem, "deleteRecordDirectory",param, null);
String response = sendPost(mediaServer, "deleteRecordDirectory", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject loadMP4File(MediaServer mediaServer, String app, String stream, String datePath) {
public ZLMResult<?> loadMP4File(MediaServer mediaServer, String app, String stream, String datePath) {
Map<String, Object> param = new HashMap<>(1);
param.put("vhost", "__defaultVhost__");
param.put("app", app);
param.put("stream", stream);
param.put("file_path", datePath);
param.put("file_repeat", "0");
return sendPost(mediaServer, "loadMP4File",param, null);
String response = sendPost(mediaServer, "loadMP4File", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject setRecordSpeed(MediaServer mediaServer, String app, String stream, int speed, String schema) {
public ZLMResult<?> setRecordSpeed(MediaServer mediaServer, String app, String stream, int speed, String schema) {
Map<String, Object> param = new HashMap<>(1);
param.put("vhost", "__defaultVhost__");
param.put("app", app);
param.put("stream", stream);
param.put("speed", speed);
param.put("schema", schema);
return sendPost(mediaServer, "setRecordSpeed",param, null);
String response = sendPost(mediaServer, "setRecordSpeed", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
public JSONObject seekRecordStamp(MediaServer mediaServer, String app, String stream, Double stamp, String schema) {
public ZLMResult<?> seekRecordStamp(MediaServer mediaServer, String app, String stream, Double stamp, String schema) {
Map<String, Object> param = new HashMap<>(1);
param.put("vhost", "__defaultVhost__");
param.put("app", app);
@ -451,6 +783,17 @@ public class ZLMRESTfulUtils {
BigDecimal bigDecimal = new BigDecimal(stamp);
param.put("stamp", bigDecimal);
param.put("schema", schema);
return sendPost(mediaServer, "seekRecordStamp",param, null);
String response = sendPost(mediaServer, "seekRecordStamp", param, null);
if (response == null) {
return ZLMResult.getFailForMediaServer();
}else {
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
if (zlmResult == null) {
return ZLMResult.getFailForMediaServer();
}else {
return zlmResult;
}
}
}
}

View File

@ -1,9 +1,10 @@
package com.genersoft.iot.vmp.media.zlm;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONArray;
import com.genersoft.iot.vmp.common.CommonCallback;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.zlm.dto.ZLMResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -31,18 +32,18 @@ public class ZLMServerFactory {
public int createRTPServer(MediaServer mediaServerItem, String app, String streamId, long ssrc, Integer port, Boolean onlyAuto, Boolean disableAudio, Boolean reUsePort, Integer tcpMode) {
int result = -1;
// 查询此rtp server 是否已经存在
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
if(rtpInfo.getInteger("code") == 0){
if (rtpInfo.getBoolean("exist")) {
result = rtpInfo.getInteger("local_port");
ZLMResult<?> rtpInfoResult = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
if(rtpInfoResult.getCode() == 0){
if (rtpInfoResult.getExist() != null && rtpInfoResult.getExist()) {
result = rtpInfoResult.getLocal_port();
if (result == 0) {
// 此时说明rtpServer已经创建但是流还没有推上来
// 此时重新打开rtpServer
Map<String, Object> param = new HashMap<>();
param.put("stream_id", streamId);
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
ZLMResult<?> zlmResult = zlmresTfulUtils.closeRtpServer(mediaServerItem, param);
if (zlmResult != null ) {
if (zlmResult.getCode() == 0) {
return createRTPServer(mediaServerItem, streamId, app, ssrc, port,onlyAuto, reUsePort,disableAudio, tcpMode);
}else {
log.warn("[开启rtpServer], 重启RtpServer错误");
@ -51,7 +52,7 @@ public class ZLMServerFactory {
}
return result;
}
}else if(rtpInfo.getInteger("code") == -2){
}else if(rtpInfoResult.getCode() == -2){
return result;
}
@ -83,12 +84,12 @@ public class ZLMServerFactory {
param.put("ssrc", ssrc);
}
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
if (openRtpServerResultJson != null) {
if (openRtpServerResultJson.getInteger("code") == 0) {
result= openRtpServerResultJson.getInteger("port");
ZLMResult<?> zlmResult = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
if (zlmResult != null) {
if (zlmResult.getCode() == 0) {
result= zlmResult.getPort();
}else {
log.error("创建RTP Server 失败 {}: ", openRtpServerResultJson.getString("msg"));
log.error("创建RTP Server 失败 {}: ", zlmResult.getMsg());
}
}else {
// 检查ZLM状态
@ -102,13 +103,12 @@ public class ZLMServerFactory {
if (serverItem !=null){
Map<String, Object> param = new HashMap<>();
param.put("stream_id", streamId);
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param);
log.info("关闭RTP Server " + jsonObject);
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
result = jsonObject.getInteger("hit") >= 1;
ZLMResult<?> zlmResult = zlmresTfulUtils.closeRtpServer(serverItem, param);
if (zlmResult != null ) {
if (zlmResult.getCode() == 0) {
result = zlmResult.getHit() >= 1;
}else {
log.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
log.error("关闭RTP Server 失败: " + zlmResult.getMsg());
}
}else {
// 检查ZLM状态
@ -127,19 +127,14 @@ public class ZLMServerFactory {
}
Map<String, Object> param = new HashMap<>();
param.put("stream_id", streamId);
zlmresTfulUtils.closeRtpServer(serverItem, param, jsonObject -> {
if (jsonObject != null ) {
if (jsonObject.getInteger("code") == 0) {
if (callback != null) {
callback.run(jsonObject.getInteger("hit") == 1);
}
return;
}else {
log.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
zlmresTfulUtils.closeRtpServer(serverItem, param, zlmResult -> {
if (zlmResult.getCode() == 0) {
if (callback != null) {
callback.run(zlmResult.getHit() >= 1);
}
return;
}else {
// 检查ZLM状态
log.error("关闭RTP Server 失败: 请检查ZLM服务");
log.error("关闭RTP Server 失败: " + zlmResult.getMsg());
}
if (callback != null) {
callback.run(false);
@ -151,22 +146,22 @@ public class ZLMServerFactory {
/**
* 调用zlm RESTFUL API startSendRtp
*/
public JSONObject startSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) {
public ZLMResult<?> startSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) {
return zlmresTfulUtils.startSendRtp(mediaServerItem, param);
}
/**
* 调用zlm RESTFUL API startSendRtpPassive
*/
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param) {
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param) {
return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param);
}
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param, ZLMRESTfulUtils.RequestCallback callback) {
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param, ZLMRESTfulUtils.ResultCallback callback) {
return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param, callback);
}
public JSONObject startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ZLMRESTfulUtils.RequestCallback callback) {
public ZLMResult<?> startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ZLMRESTfulUtils.ResultCallback callback) {
return zlmresTfulUtils.startSendRtpTalk(mediaServer, param, callback);
}
@ -174,38 +169,17 @@ public class ZLMServerFactory {
* 查询待转推的流是否就绪
*/
public Boolean isStreamReady(MediaServer mediaServerItem, String app, String streamId) {
JSONObject mediaInfo = zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId);
if (mediaInfo == null || (mediaInfo.getInteger("code") == -2)) {
ZLMResult<?> zlmResult = zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId);
if (zlmResult == null || zlmResult.getCode() == -2) {
return null;
}
return (mediaInfo.getInteger("code") == 0
&& mediaInfo.getJSONArray("data") != null
&& mediaInfo.getJSONArray("data").size() > 0);
ZLMResult<JSONArray> result = (ZLMResult<JSONArray>) zlmResult;
return (result.getCode() == 0
&& result.getData() != null
&& !result.getData().isEmpty());
}
/**
* 查询转推的流是否有其它观看者
* @param streamId
* @return
*/
public int totalReaderCount(MediaServer mediaServerItem, String app, String streamId) {
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtsp", streamId);
if (mediaInfo == null) {
return 0;
}
Integer code = mediaInfo.getInteger("code");
if (code < 0) {
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
if ( code == 0 && mediaInfo.getBoolean("online") != null && ! mediaInfo.getBoolean("online")) {
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
return -1;
}
return mediaInfo.getInteger("totalReaderCount");
}
public JSONObject startSendRtp(MediaServer mediaInfo, SendRtpInfo sendRtpItem) {
public ZLMResult<?> startSendRtp(MediaServer mediaInfo, SendRtpInfo sendRtpItem) {
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
log.info("rtp/{}开始推流, 目标={}:{}SSRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
Map<String, Object> param = new HashMap<>(12);
@ -226,45 +200,43 @@ public class ZLMServerFactory {
return null;
}
// 如果是非严格模式需要关闭端口占用
JSONObject startSendRtpStreamResult = null;
ZLMResult<?> zlmResult = null;
if (sendRtpItem.getLocalPort() != 0) {
if (sendRtpItem.isTcpActive()) {
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
zlmResult = startSendRtpPassive(mediaInfo, param);
}else {
param.put("is_udp", is_Udp);
param.put("dst_url", sendRtpItem.getIp());
param.put("dst_port", sendRtpItem.getPort());
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
zlmResult = startSendRtpStream(mediaInfo, param);
}
}else {
if (sendRtpItem.isTcpActive()) {
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
zlmResult = startSendRtpPassive(mediaInfo, param);
}else {
param.put("is_udp", is_Udp);
param.put("dst_url", sendRtpItem.getIp());
param.put("dst_port", sendRtpItem.getPort());
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
zlmResult = startSendRtpStream(mediaInfo, param);
}
}
return startSendRtpStreamResult;
return zlmResult;
}
public Boolean updateRtpServerSSRC(MediaServer mediaServerItem, String streamId, String ssrc) {
boolean result = false;
JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
if (jsonObject == null) {
log.error("[更新RTPServer] 失败: 请检查ZLM服务");
} else if (jsonObject.getInteger("code") == 0) {
ZLMResult<?> zlmResult = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
if (zlmResult.getCode() == 0) {
result= true;
log.info("[更新RTPServer] 成功");
} else {
log.error("[更新RTPServer] 失败: {}, streamId{}ssrc{}->\r\n{}",jsonObject.getString("msg"),
streamId, ssrc, jsonObject);
log.error("[更新RTPServer] 失败: {}, streamId{}ssrc{}", zlmResult.getMsg(),
streamId, ssrc);
}
return result;
}
public JSONObject stopSendRtpStream(MediaServer mediaServerItem, SendRtpInfo sendRtpItem) {
public ZLMResult<?> stopSendRtpStream(MediaServer mediaServerItem, SendRtpInfo sendRtpItem) {
Map<String, Object> param = new HashMap<>();
param.put("vhost", "__defaultVhost__");
param.put("app", sendRtpItem.getApp());

View File

@ -0,0 +1,8 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import lombok.Data;
@Data
public class FlagData {
private boolean flag;
}

View File

@ -0,0 +1,10 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import lombok.Data;
@Data
public class RtpServerResult {
private Integer port;
private String stream_id;
}

View File

@ -0,0 +1,14 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import lombok.Data;
@Data
public class SessionData {
private String id;
private String local_ip;
private Integer local_port;
private String peer_ip;
private Integer peer_port;
private String typeid;
}

View File

@ -0,0 +1,9 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import lombok.Data;
@Data
public class StreamProxyResult {
private String key;
}

View File

@ -0,0 +1,58 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import lombok.Data;
@Data
public class ZLMResult<T> {
private int code;
private String msg;
private T data;
private Boolean online;
private Boolean exist;
private String peer_ip;
private Integer peer_port;
private String local_ip;
private Integer local_port;
private Integer changed;
private Integer port;
private Integer hit;
public static <T> ZLMResult<T> getFailForMediaServer() {
ZLMResult<T> zlmResult = new ZLMResult<>();
zlmResult.setCode(-2);
zlmResult.setMsg("流媒体调用失败");
return zlmResult;
}
public static <T> ZLMResult<T> getMediaServer(int code, String msg) {
return getMediaServer(code, msg, null);
}
public static <T> ZLMResult<T> getMediaServer(int code, String msg, T data) {
ZLMResult<T> zlmResult = new ZLMResult<>();
zlmResult.setCode(code);
zlmResult.setMsg(msg);
zlmResult.setData(data);
return zlmResult;
}
@Override
public String toString() {
return "ZLMResult{" +
"code=" + code +
", msg='" + msg + '\'' +
", data=" + data +
(online != null ? (", online=" + online) : "") +
(exist != null ? (", exist=" + exist) : "") +
(peer_ip != null ? (", peer_ip=" + peer_ip) : "") +
(peer_port != null ? (", peer_port=" + peer_port) : "") +
(local_ip != null ? (", local_ip=" + local_ip) : "") +
(local_port != null ? (", local_port=" + local_port) : "") +
(changed != null ? (", changed=" + changed) : "") +
(port != null ? (", port=" + port) : "") +
(hit != null ? (", hit=" + hit) : "") +
'}';
}
}

View File

@ -13,10 +13,10 @@
<div id="shared" style="margin-right: 20px;">
<el-form ref="passwordForm" :rules="rules" status-icon label-width="80px">
<el-form-item label="新密码" prop="newPassword">
<el-input v-model="newPassword" autocomplete="off" />
<el-input v-model="newPassword" autocomplete="off" type="password" />
</el-form-item>
<el-form-item label="确认密码" prop="confirmPassword">
<el-input v-model="confirmPassword" autocomplete="off" />
<el-input v-model="confirmPassword" autocomplete="off" type="password" />
</el-form-item>
<el-form-item>
@ -88,6 +88,14 @@ export default {
}
},
onSubmit: function() {
if (this.newPassword !== this.confirmPassword) {
this.$message({
showClose: true,
message: '两次输入密码不一致!',
type: 'error'
})
return
}
this.$store.dispatch('user/changePasswordForAdmin', {
password: this.newPassword,
userId: this.form.id