parent
1a827a4dd4
commit
3d2aeb890b
|
@ -113,6 +113,7 @@ public class SipLayer implements SipListener {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void processRequest(RequestEvent evt) {
|
public void processRequest(RequestEvent evt) {
|
||||||
|
logger.debug(evt.getRequest().toString());
|
||||||
// 由于jainsip是单线程程序,为提高性能并发处理
|
// 由于jainsip是单线程程序,为提高性能并发处理
|
||||||
processThreadPool.execute(() -> {
|
processThreadPool.execute(() -> {
|
||||||
processorFactory.createRequestProcessor(evt).process();
|
processorFactory.createRequestProcessor(evt).process();
|
||||||
|
@ -122,6 +123,7 @@ public class SipLayer implements SipListener {
|
||||||
@Override
|
@Override
|
||||||
public void processResponse(ResponseEvent evt) {
|
public void processResponse(ResponseEvent evt) {
|
||||||
Response response = evt.getResponse();
|
Response response = evt.getResponse();
|
||||||
|
logger.debug(evt.getResponse().toString());
|
||||||
int status = response.getStatusCode();
|
int status = response.getStatusCode();
|
||||||
if ((status >= 200) && (status < 300)) { // Success!
|
if ((status >= 200) && (status < 300)) { // Success!
|
||||||
ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt);
|
ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt);
|
||||||
|
|
|
@ -84,8 +84,7 @@ public class SIPRequestHeaderProvider {
|
||||||
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, host.getAddress());
|
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, host.getAddress());
|
||||||
//via
|
//via
|
||||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||||
// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag);
|
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag);
|
||||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getHost().getIp(), device.getHost().getPort(), device.getTransport(), viaTag);
|
|
||||||
viaHeader.setRPort();
|
viaHeader.setRPort();
|
||||||
viaHeaders.add(viaHeader);
|
viaHeaders.add(viaHeader);
|
||||||
//from
|
//from
|
||||||
|
|
|
@ -21,14 +21,12 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
|
||||||
* 处理 ACK请求
|
* 处理 ACK请求
|
||||||
*
|
*
|
||||||
* @param evt
|
* @param evt
|
||||||
* @param layer
|
|
||||||
* @param transaction
|
|
||||||
* @param config
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void process(RequestEvent evt) {
|
public void process(RequestEvent evt) {
|
||||||
Request request = evt.getRequest();
|
Request request = evt.getRequest();
|
||||||
Dialog dialog = evt.getDialog();
|
Dialog dialog = evt.getDialog();
|
||||||
|
if (dialog == null) return;
|
||||||
try {
|
try {
|
||||||
Request ackRequest = null;
|
Request ackRequest = null;
|
||||||
CSeq csReq = (CSeq) request.getHeader(CSeq.NAME);
|
CSeq csReq = (CSeq) request.getHeader(CSeq.NAME);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import javax.sip.header.ViaHeader;
|
||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
import javax.sip.message.Response;
|
import javax.sip.message.Response;
|
||||||
|
|
||||||
|
import gov.nist.javax.sip.header.CSeq;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -49,49 +50,11 @@ public class InviteResponseProcessor implements ISIPResponseProcessor {
|
||||||
// 成功响应
|
// 成功响应
|
||||||
// 下发ack
|
// 下发ack
|
||||||
if (statusCode == Response.OK) {
|
if (statusCode == Response.OK) {
|
||||||
// ClientTransaction clientTransaction = evt.getClientTransaction();
|
|
||||||
// if(clientTransaction == null){
|
|
||||||
// logger.error("回复ACK时,clientTransaction为null >>> {}",response);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// Dialog clientDialog = clientTransaction.getDialog();
|
|
||||||
|
|
||||||
// CSeqHeader clientCSeqHeader = (CSeqHeader)
|
|
||||||
// response.getHeader(CSeqHeader.NAME);
|
|
||||||
// long cseqId = clientCSeqHeader.getSeqNumber();
|
|
||||||
// /*
|
|
||||||
// createAck函数,创建的ackRequest,会采用Invite响应的200OK,中的contact字段中的地址,作为目标地址。
|
|
||||||
// 有的终端传上来的可能还是内网地址,会造成ack发送不出去。接受不到音视频流
|
|
||||||
// 所以在此处统一替换地址。和响应消息的Via头中的地址保持一致。
|
|
||||||
// */
|
|
||||||
// Request ackRequest = clientDialog.createAck(cseqId);
|
|
||||||
// SipURI requestURI = (SipURI) ackRequest.getRequestURI();
|
|
||||||
// ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME);
|
|
||||||
// try {
|
|
||||||
// requestURI.setHost(viaHeader.getHost());
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// requestURI.setPort(viaHeader.getPort());
|
|
||||||
// clientDialog.sendAck(ackRequest);
|
|
||||||
|
|
||||||
Dialog dialog = evt.getDialog();
|
Dialog dialog = evt.getDialog();
|
||||||
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
|
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
|
||||||
Request reqAck = dialog.createAck(cseq.getSeqNumber());
|
Request reqAck = dialog.createAck(cseq.getSeqNumber());
|
||||||
|
|
||||||
SipURI requestURI = (SipURI) reqAck.getRequestURI();
|
|
||||||
ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME);
|
|
||||||
// String viaHost =viaHeader.getHost();
|
|
||||||
//getHost()函数取回的IP地址是“[xxx.xxx.xxx.xxx:yyyy]”的格式,需用正则表达式截取为“xxx.xxx.xxx.xxx"格式
|
|
||||||
// Pattern p = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+");
|
|
||||||
// Matcher matcher = p.matcher(viaHeader.getHost());
|
|
||||||
// if (matcher.find()) {
|
|
||||||
// requestURI.setHost(matcher.group());
|
|
||||||
// }
|
|
||||||
requestURI.setHost(viaHeader.getHost());
|
|
||||||
requestURI.setPort(viaHeader.getPort());
|
|
||||||
reqAck.setRequestURI(requestURI);
|
|
||||||
dialog.sendAck(reqAck);
|
dialog.sendAck(reqAck);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (InvalidArgumentException | SipException e) {
|
} catch (InvalidArgumentException | SipException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -20,6 +21,7 @@ import java.math.BigInteger;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:针对 ZLMediaServer的hook事件订阅
|
* @Description:针对 ZLMediaServer的hook事件订阅
|
||||||
|
@ -50,7 +52,7 @@ public class ZLMHttpHookSubscribe {
|
||||||
void response(JSONObject response);
|
void response(JSONObject response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<HookType, Map<JSONObject, ZLMHttpHookSubscribe.Event>> allSubscribes = new HashMap<>();
|
private Map<HookType, Map<JSONObject, ZLMHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public void addSubscribe(HookType type, JSONObject hookResponse, ZLMHttpHookSubscribe.Event event) {
|
public void addSubscribe(HookType type, JSONObject hookResponse, ZLMHttpHookSubscribe.Event event) {
|
||||||
Map<JSONObject, Event> eventMap = allSubscribes.get(type);
|
Map<JSONObject, Event> eventMap = allSubscribes.get(type);
|
||||||
|
|
Loading…
Reference in New Issue