支持hook
parent
7ce4f44caa
commit
2b0af3be14
|
@ -126,6 +126,9 @@ public class AblServerConfig {
|
||||||
@ConfigKeyId("on_stream_disconnect")
|
@ConfigKeyId("on_stream_disconnect")
|
||||||
private String onStreamDisconnect;
|
private String onStreamDisconnect;
|
||||||
|
|
||||||
|
@ConfigKeyId("on_stream_not_found")
|
||||||
|
private String onStreamNotFound;
|
||||||
|
|
||||||
@ConfigKeyId("on_record_mp4")
|
@ConfigKeyId("on_record_mp4")
|
||||||
private String onRecordMp4;
|
private String onRecordMp4;
|
||||||
|
|
||||||
|
@ -798,4 +801,12 @@ public class AblServerConfig {
|
||||||
public void setPictureMaxCount(Integer pictureMaxCount) {
|
public void setPictureMaxCount(Integer pictureMaxCount) {
|
||||||
this.pictureMaxCount = pictureMaxCount;
|
this.pictureMaxCount = pictureMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOnStreamNotFound() {
|
||||||
|
return onStreamNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnStreamNotFound(String onStreamNotFound) {
|
||||||
|
this.onStreamNotFound = onStreamNotFound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,6 @@ public class ZLMHttpHookListener {
|
||||||
* 服务器定时上报时间,上报间隔可配置,默认10s上报一次
|
* 服务器定时上报时间,上报间隔可配置,默认10s上报一次
|
||||||
*/
|
*/
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|
||||||
@PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8")
|
@PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8")
|
||||||
public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) {
|
public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) {
|
||||||
try {
|
try {
|
||||||
|
@ -164,26 +163,12 @@ public class ZLMHttpHookListener {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("[ZLM HOOK] 播放鉴权:{}->{}", param.getMediaServerId(), param);
|
logger.debug("[ZLM HOOK] 播放鉴权:{}->{}", param.getMediaServerId(), param);
|
||||||
}
|
}
|
||||||
String mediaServerId = param.getMediaServerId();
|
|
||||||
|
|
||||||
taskExecutor.execute(() -> {
|
|
||||||
JSONObject json = (JSONObject) JSON.toJSON(param);
|
|
||||||
ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_play, json);
|
|
||||||
if (subscribe != null) {
|
|
||||||
MediaServer mediaInfo = mediaServerService.getOne(mediaServerId);
|
|
||||||
if (mediaInfo != null) {
|
|
||||||
subscribe.response(mediaInfo, param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// TODO 此处逻辑适合迁移到MediaService中
|
|
||||||
if (!"rtp".equals(param.getApp())) {
|
|
||||||
Map<String, String> paramMap = urlParamToMap(param.getParams());
|
Map<String, String> paramMap = urlParamToMap(param.getParams());
|
||||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
|
// 对于播放流进行鉴权
|
||||||
if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) {
|
boolean authenticateResult = mediaService.authenticatePlay(param.getApp(), param.getStream(), paramMap.get("callId"));
|
||||||
|
if (!authenticateResult) {
|
||||||
return new HookResult(401, "Unauthorized");
|
return new HookResult(401, "Unauthorized");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return HookResult.SUCCESS();
|
return HookResult.SUCCESS();
|
||||||
}
|
}
|
||||||
|
@ -215,12 +200,14 @@ public class ZLMHttpHookListener {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (userSetting.getPushAuthority()) {
|
if (userSetting.getPushAuthority()) {
|
||||||
|
// 对于推流进行鉴权
|
||||||
|
Map<String, String> paramMap = urlParamToMap(param.getParams());
|
||||||
// 推流鉴权
|
// 推流鉴权
|
||||||
if (param.getParams() == null) {
|
if (param.getParams() == null) {
|
||||||
logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)");
|
logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)");
|
||||||
return new HookResultForOnPublish(401, "Unauthorized");
|
return new HookResultForOnPublish(401, "Unauthorized");
|
||||||
}
|
}
|
||||||
Map<String, String> paramMap = urlParamToMap(param.getParams());
|
|
||||||
String sign = paramMap.get("sign");
|
String sign = paramMap.get("sign");
|
||||||
if (sign == null) {
|
if (sign == null) {
|
||||||
logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)");
|
logger.info("推流鉴权失败: 缺少必要参数:sign=md5(user表的pushKey)");
|
||||||
|
@ -648,12 +635,6 @@ public class ZLMHttpHookListener {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// TODO 推流具有主动性,暂时不做处理
|
|
||||||
// StreamPushItem streamPushItem = streamPushService.getPush(app, streamId);
|
|
||||||
// if (streamPushItem != null) {
|
|
||||||
// // TODO 发送停止
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,11 @@ public interface IMediaService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
StreamInfo getStreamInfoByAppAndStream(MediaServer mediaServerItem, String app, String stream, MediaInfo mediaInfo, String addr, String callId, boolean isPlay);
|
StreamInfo getStreamInfoByAppAndStream(MediaServer mediaServerItem, String app, String stream, MediaInfo mediaInfo, String addr, String callId, boolean isPlay);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放鉴权
|
||||||
|
*/
|
||||||
|
boolean authenticatePlay(String app, String stream, String callId);
|
||||||
|
|
||||||
|
boolean authenticatePublish(String app, String stream, String callId, String sign);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,14 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||||
|
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookListener;
|
||||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
|
import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
|
||||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||||
|
import com.genersoft.iot.vmp.media.zlm.dto.hook.HookResultForOnPublish;
|
||||||
import com.genersoft.iot.vmp.service.IMediaService;
|
import com.genersoft.iot.vmp.service.IMediaService;
|
||||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
@ -17,6 +21,8 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class MediaServiceImpl implements IMediaService {
|
public class MediaServiceImpl implements IMediaService {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(MediaServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IRedisCatchStorage redisCatchStorage;
|
private IRedisCatchStorage redisCatchStorage;
|
||||||
|
|
||||||
|
@ -85,4 +91,16 @@ public class MediaServiceImpl implements IMediaService {
|
||||||
streamInfoResult.setMediaInfo(mediaInfo);
|
streamInfoResult.setMediaInfo(mediaInfo);
|
||||||
return streamInfoResult;
|
return streamInfoResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean authenticatePlay(String app, String stream, String callId) {
|
||||||
|
if (app == null || stream == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ("rtp".equals(app)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
||||||
|
return (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(callId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue