invite 请求解析
This commit is contained in:
parent
3cb65ddbb4
commit
7a89ac8184
@ -5,6 +5,8 @@ import cn.skcks.docking.gb28181.core.sip.listener.SipListener;
|
|||||||
import cn.skcks.docking.gb28181.core.sip.message.processor.MessageProcessor;
|
import cn.skcks.docking.gb28181.core.sip.message.processor.MessageProcessor;
|
||||||
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
|
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
|
||||||
import cn.skcks.docking.gb28181.mocking.core.sip.gb28181.sdp.GB28181DescriptionParser;
|
import cn.skcks.docking.gb28181.mocking.core.sip.gb28181.sdp.GB28181DescriptionParser;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.core.sip.response.SipResponseBuilder;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.core.sip.sender.SipSender;
|
||||||
import gov.nist.javax.sip.message.SIPRequest;
|
import gov.nist.javax.sip.message.SIPRequest;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -12,16 +14,24 @@ import lombok.SneakyThrows;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.sdp.Media;
|
||||||
|
import javax.sdp.MediaDescription;
|
||||||
|
import javax.sdp.SdpParseException;
|
||||||
import javax.sip.RequestEvent;
|
import javax.sip.RequestEvent;
|
||||||
import javax.sip.header.CallIdHeader;
|
import javax.sip.header.CallIdHeader;
|
||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
|
import javax.sip.message.Response;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Component
|
@Component
|
||||||
public class InviteRequestProcessor implements MessageProcessor {
|
public class InviteRequestProcessor implements MessageProcessor {
|
||||||
private final SipListener sipListener;
|
private final SipListener sipListener;
|
||||||
|
|
||||||
|
private final SipSender sender;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
@ -37,10 +47,30 @@ public class InviteRequestProcessor implements MessageProcessor {
|
|||||||
String deviceId = SipUtil.getUserIdFromFromHeader(request);
|
String deviceId = SipUtil.getUserIdFromFromHeader(request);
|
||||||
CallIdHeader callIdHeader = request.getCallIdHeader();
|
CallIdHeader callIdHeader = request.getCallIdHeader();
|
||||||
String senderIp = request.getLocalAddress().getHostAddress();
|
String senderIp = request.getLocalAddress().getHostAddress();
|
||||||
|
String transport = request.getTopmostViaHeader().getTransport();
|
||||||
String content = new String(request.getRawContent());
|
String content = new String(request.getRawContent());
|
||||||
log.info("{}", content);
|
|
||||||
|
|
||||||
GB28181Description gb28181Description = new GB28181DescriptionParser(content).parse();
|
GB28181Description gb28181Description = new GB28181DescriptionParser(content).parse();
|
||||||
log.info("{}", gb28181Description);
|
log.info("解析的 sdp信息: \n{}", gb28181Description);
|
||||||
|
Vector<?> mediaDescriptions = gb28181Description.getMediaDescriptions(true);
|
||||||
|
log.info("mediaDescriptions {}",mediaDescriptions);
|
||||||
|
mediaDescriptions.stream().filter(item->{
|
||||||
|
MediaDescription mediaDescription = (MediaDescription)item;
|
||||||
|
Media media = mediaDescription.getMedia();
|
||||||
|
try {
|
||||||
|
Vector<?> mediaFormats = media.getMediaFormats(false);
|
||||||
|
return mediaFormats.contains("98");
|
||||||
|
} catch (SdpParseException e) {
|
||||||
|
log.error("sdp media 解析异常: {}", e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).findFirst().ifPresentOrElse((ignore)->{
|
||||||
|
log.info("{}", ignore);
|
||||||
|
},()->{
|
||||||
|
log.info("未找到支持的媒体类型");
|
||||||
|
sender.sendResponse(senderIp,transport, ((provider, ip, port) ->
|
||||||
|
SipResponseBuilder.response(request,
|
||||||
|
Response.UNSUPPORTED_MEDIA_TYPE,
|
||||||
|
"Unsupported Media Type")));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user