|
@@ -32,9 +32,13 @@ import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
|
|
+import reactor.core.publisher.FluxSink;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
+import reactor.core.publisher.UnicastProcessor;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @description:针对 ZLMediaServer的hook事件监听
|
|
* @description:针对 ZLMediaServer的hook事件监听
|
|
@@ -54,13 +58,22 @@ public class ZLMHttpHookListener {
|
|
|
private final ZLMMediaListManager zlmMediaListManager;
|
|
private final ZLMMediaListManager zlmMediaListManager;
|
|
|
private final LocalGbStreamService gbStreamService;
|
|
private final LocalGbStreamService gbStreamService;
|
|
|
private final StandaloneDeviceMessageBroker deviceMessageBroker;
|
|
private final StandaloneDeviceMessageBroker deviceMessageBroker;
|
|
|
- //todo
|
|
|
|
|
- private final String serverId="";
|
|
|
|
|
private final UserSetup userSetup;
|
|
private final UserSetup userSetup;
|
|
|
private final SipCommander sipCommander;
|
|
private final SipCommander sipCommander;
|
|
|
private final LocalPlayService localPlayService;
|
|
private final LocalPlayService localPlayService;
|
|
|
private final LocalMediaDeviceChannelService mediaDeviceChannelService;
|
|
private final LocalMediaDeviceChannelService mediaDeviceChannelService;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * ZLM服务器心跳消息处理
|
|
|
|
|
+ */
|
|
|
|
|
+ private final UnicastProcessor<JSONObject> keepAliveProcessor=UnicastProcessor.create();
|
|
|
|
|
+ private final FluxSink<JSONObject> keepAliveSink=keepAliveProcessor.sink();
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * ZLM心跳上线消息处理
|
|
|
|
|
+ */
|
|
|
|
|
+ private final UnicastProcessor<JSONObject> startProcessor=UnicastProcessor.create();
|
|
|
|
|
+ private final FluxSink<JSONObject> startSink=keepAliveProcessor.sink();
|
|
|
/**
|
|
/**
|
|
|
* 服务器定时上报时间,上报间隔可配置,默认10s上报一次
|
|
* 服务器定时上报时间,上报间隔可配置,默认10s上报一次
|
|
|
*
|
|
*
|
|
@@ -72,18 +85,12 @@ public class ZLMHttpHookListener {
|
|
|
if (log.isDebugEnabled()) {
|
|
if (log.isDebugEnabled()) {
|
|
|
log.debug("[ ZLM HOOK ]on_server_keepalive API调用,参数:" + json.toString());
|
|
log.debug("[ ZLM HOOK ]on_server_keepalive API调用,参数:" + json.toString());
|
|
|
}
|
|
}
|
|
|
- String mediaServerId = json.getStr("mediaServerId");
|
|
|
|
|
-
|
|
|
|
|
- List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_keepalive);
|
|
|
|
|
- if (subscribes != null && subscribes.size() > 0) {
|
|
|
|
|
- for (ZLMHttpHookSubscribe.Event subscribe : subscribes) {
|
|
|
|
|
- subscribe.accept(null, json);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(keepAliveProcessor.hasDownstreams()){
|
|
|
|
|
+ keepAliveSink.next(json);
|
|
|
}
|
|
}
|
|
|
- JSONObject ret = new JSONObject()
|
|
|
|
|
|
|
+ return Mono.just(ResponseEntity.ok(new JSONObject()
|
|
|
.putOpt("code", 0)
|
|
.putOpt("code", 0)
|
|
|
- .putOpt("msg", "success");
|
|
|
|
|
- return Mono.just(ResponseEntity.ok(ret.toString()));
|
|
|
|
|
|
|
+ .putOpt("msg", "success").toString()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// /**
|
|
// /**
|
|
@@ -330,7 +337,7 @@ public class ZLMHttpHookListener {
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
if (!"rtp".equals(app)){
|
|
if (!"rtp".equals(app)){
|
|
|
- result=result.flatMap(ingore->
|
|
|
|
|
|
|
+ result=result.flatMap(ignore->
|
|
|
mediaServerItemService.findById(mediaServerId)
|
|
mediaServerItemService.findById(mediaServerId)
|
|
|
.doOnNext(mediaServerItem -> {
|
|
.doOnNext(mediaServerItem -> {
|
|
|
String type = OriginType.values()[item.getOriginType()].getType();
|
|
String type = OriginType.values()[item.getOriginType()].getType();
|
|
@@ -379,7 +386,7 @@ public class ZLMHttpHookListener {
|
|
|
if (type != null) {
|
|
if (type != null) {
|
|
|
// 发送流变化redis消息
|
|
// 发送流变化redis消息
|
|
|
JSONObject jsonObject = new JSONObject()
|
|
JSONObject jsonObject = new JSONObject()
|
|
|
- .putOpt("serverId", serverId)
|
|
|
|
|
|
|
+ .putOpt("serverId", userSetup.getServerId())
|
|
|
.putOpt("app", app)
|
|
.putOpt("app", app)
|
|
|
.putOpt("stream", streamId)
|
|
.putOpt("stream", streamId)
|
|
|
.putOpt("register", regist)
|
|
.putOpt("register", regist)
|
|
@@ -395,18 +402,15 @@ public class ZLMHttpHookListener {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- JSONObject ret = new JSONObject()
|
|
|
|
|
- .putOpt("code", 0)
|
|
|
|
|
- .putOpt("msg", "success");
|
|
|
|
|
-
|
|
|
|
|
MediaMessageReply<MediaItem> mediaMessageReply = MediaMessageReply.of(null,item);
|
|
MediaMessageReply<MediaItem> mediaMessageReply = MediaMessageReply.of(null,item);
|
|
|
mediaMessageReply.setMessageId(ZLMKeyGenerate.getStreamChangedKey(ZLMHttpHookSubscribe.HookType.on_stream_changed,mediaServerId,app,regist,streamId));
|
|
mediaMessageReply.setMessageId(ZLMKeyGenerate.getStreamChangedKey(ZLMHttpHookSubscribe.HookType.on_stream_changed,mediaServerId,app,regist,streamId));
|
|
|
mediaMessageReply.setSuccess(true);
|
|
mediaMessageReply.setSuccess(true);
|
|
|
;
|
|
;
|
|
|
return result
|
|
return result
|
|
|
.mergeWith(deviceMessageBroker.reply(mediaMessageReply).thenReturn(1L))
|
|
.mergeWith(deviceMessageBroker.reply(mediaMessageReply).thenReturn(1L))
|
|
|
- .then(Mono.just(ResponseEntity.ok(ret.toString())));
|
|
|
|
|
|
|
+ .then(Mono.just(ResponseEntity.ok( new JSONObject()
|
|
|
|
|
+ .putOpt("code", 0)
|
|
|
|
|
+ .putOpt("msg", "success").toString())));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -532,15 +536,19 @@ public class ZLMHttpHookListener {
|
|
|
}
|
|
}
|
|
|
String remoteAddr = exchange.getRequest().getRemoteAddress().getAddress().toString();
|
|
String remoteAddr = exchange.getRequest().getRemoteAddress().getAddress().toString();
|
|
|
jsonObject.putOpt("ip", remoteAddr);
|
|
jsonObject.putOpt("ip", remoteAddr);
|
|
|
- JSONObject ret = new JSONObject()
|
|
|
|
|
- .putOpt("code", 0)
|
|
|
|
|
- .putOpt("msg", "success");
|
|
|
|
|
- List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_started);
|
|
|
|
|
- if (subscribes != null && subscribes.size() > 0) {
|
|
|
|
|
- for (ZLMHttpHookSubscribe.Event subscribe : subscribes) {
|
|
|
|
|
- subscribe.accept(null, jsonObject);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(startProcessor.hasDownstreams()){
|
|
|
|
|
+ startSink.next(jsonObject);
|
|
|
}
|
|
}
|
|
|
- return Mono.just(ResponseEntity.ok(ret.toString()));
|
|
|
|
|
|
|
+ return Mono.just(ResponseEntity.ok(new JSONObject()
|
|
|
|
|
+ .putOpt("code", 0)
|
|
|
|
|
+ .putOpt("msg", "success").toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Flux<JSONObject> handleKeepAlive(){
|
|
|
|
|
+ return keepAliveProcessor.map(Function.identity());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Flux<JSONObject> handleStart(){
|
|
|
|
|
+ return startProcessor.map(Function.identity());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|