Skip to content

Commit

Permalink
🔧 feat: handler处理,避免重复
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhangyue committed Jan 1, 2024
1 parent 9aaddae commit bd7bc0f
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -37,7 +38,7 @@ public DeviceControlMessageHandler(MessageProcessorClient messageProcessorClient

@Override
public String getRootType() {
return CONTROL;
return ClientMessageRequestProcessor.METHOD + CONTROL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.FromDevice;
import io.github.lunasaw.sip.common.entity.DeviceSession;
Expand Down Expand Up @@ -36,7 +37,7 @@ public BroadcastNotifyMessageHandler(MessageProcessorClient messageProcessorClie

@Override
public String getRootType() {
return NOTIFY;
return ClientMessageRequestProcessor.METHOD + NOTIFY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd;
import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.FromDevice;
Expand Down Expand Up @@ -39,7 +40,7 @@ public AlarmQueryMessageClientHandler(MessageProcessorClient messageProcessorCli

@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.sip.RequestEvent;

import io.github.lunasaw.gb28181.common.entity.response.DeviceResponse;
import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;

import lombok.Setter;
Expand Down Expand Up @@ -41,7 +42,7 @@ public CatalogQueryMessageClientHandler(MessageProcessorClient messageProcessorC

@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd;
import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.FromDevice;
import io.github.lunasaw.sip.common.entity.ToDevice;
Expand Down Expand Up @@ -41,7 +42,7 @@ public ConfigDownloadMessageHandler(MessageProcessorClient messageProcessorClien

@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;

Expand Down Expand Up @@ -40,7 +41,7 @@ public DeviceInfoQueryMessageClientHandler(MessageProcessorClient messageProcess

@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;

import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -42,7 +43,7 @@ public DeviceStatusQueryMessageClientHandler(MessageProcessorClient messageProce

@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import org.springframework.stereotype.Component;

import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.gb28181.common.entity.query.DeviceRecordQuery;
import io.github.lunasaw.gb28181.common.entity.response.DeviceRecord;
import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientSendCmd;
import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor;
import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract;
import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageProcessorClient;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.sip.common.entity.FromDevice;
import io.github.lunasaw.sip.common.entity.ToDevice;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -36,10 +36,9 @@ public RecordInfoQueryMessageClientHandler(MessageProcessorClient messageProcess
super(messageProcessorClient, sipUserGenerateClient);
}


@Override
public String getRootType() {
return QUERY;
return ClientMessageRequestProcessor.METHOD + QUERY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.stereotype.Component;

import gov.nist.javax.sip.message.SIPRequest;
import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.sip.common.transmit.event.message.MessageHandlerAbstract;
import io.github.lunasaw.sip.common.utils.SipUtils;
import lombok.Data;
Expand All @@ -32,7 +32,7 @@ public SubscribeClientHandlerAbstract(SubscribeProcessorClient subscribeProcesso

@Override
public String getRootType() {
return "Root";
return ClientSubscribeRequestProcessor.METHOD + "Root";
}

public DeviceSession getDeviceSession(RequestEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import javax.sip.RequestEvent;
import javax.sip.header.ContentTypeHeader;
import javax.sip.header.EventHeader;
import javax.sip.header.ExpiresHeader;
import javax.sip.message.Response;

import io.github.lunasaw.gbproxy.client.user.SipUserGenerateClient;
import io.github.lunasaw.sip.common.entity.Device;
import io.github.lunasaw.gb28181.common.entity.response.DeviceSubscribe;
import io.github.lunasaw.sip.common.enums.ContentTypeEnum;
import io.github.lunasaw.sip.common.service.SipUserGenerate;
import io.github.lunasaw.sip.common.transmit.ResponseCmd;
import io.github.lunasaw.sip.common.utils.SipRequestUtils;
import org.springframework.stereotype.Component;
Expand All @@ -36,11 +36,11 @@
@Slf4j
@Getter
@Setter
public class CatalogQueryMessageHandler extends SubscribeClientHandlerAbstract {
public class SubscribeCatalogQueryMessageHandler extends SubscribeClientHandlerAbstract {

public static final String CMD_TYPE = CmdTypeEnum.CATALOG.getType();

public CatalogQueryMessageHandler(SubscribeProcessorClient subscribeProcessorClient, SipUserGenerateClient sipUserGenerate) {
public SubscribeCatalogQueryMessageHandler(SubscribeProcessorClient subscribeProcessorClient, SipUserGenerateClient sipUserGenerate) {
super(subscribeProcessorClient, sipUserGenerate);
}

Expand All @@ -53,6 +53,13 @@ public String getRootType() {
@Override
public void handForEvt(RequestEvent event) {
DeviceSession deviceSession = getDeviceSession(event);

EventHeader header = (EventHeader) event.getRequest().getHeader(EventHeader.NAME);
if (header == null){
log.info("handForEvt::event = {}", event);
return;
}

// 订阅消息过来
String sipId = deviceSession.getSipId();
String userId = deviceSession.getUserId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ public String getCmdType() {
return cmdType;
}

@Override
public String getRootType() {
return super.getRootType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.sip.RequestEvent;

import io.github.lunasaw.gb28181.common.entity.notify.DeviceAlarmNotify;
import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;

import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -36,7 +37,7 @@ public AlarmNotifyMessageHandler(MessageProcessorServer messageProcessorServer,

@Override
public String getRootType() {
return NOTIFY;
return ServerMessageRequestProcessor.METHOD + NOTIFY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.sip.message.Response;

import gov.nist.javax.sip.message.SIPRequest;
import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;
import io.github.lunasaw.sip.common.entity.RemoteAddressInfo;
import io.github.lunasaw.sip.common.entity.ToDevice;
Expand Down Expand Up @@ -39,7 +40,7 @@ public KeepaliveNotifyMessageHandler(MessageProcessorServer messageProcessorServ

@Override
public String getRootType() {
return NOTIFY;
return ServerMessageRequestProcessor.METHOD + NOTIFY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;

import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -36,7 +37,7 @@ public MediaStatusNotifyMessageHandler(MessageProcessorServer messageProcessorSe

@Override
public String getRootType() {
return NOTIFY;
return ServerMessageRequestProcessor.METHOD + NOTIFY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;
import io.github.lunasaw.sip.common.entity.ToDevice;
import io.github.lunasaw.sip.common.entity.DeviceSession;
Expand Down Expand Up @@ -36,7 +37,7 @@ public MobilePositionNotifyMessageHandler(MessageProcessorServer messageProcesso

@Override
public String getRootType() {
return NOTIFY;
return ServerMessageRequestProcessor.METHOD + NOTIFY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.sip.common.entity.DeviceSession;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -34,7 +35,7 @@ public RecordInfoMessageHandler(MessageProcessorServer messageProcessorServer, S

@Override
public String getRootType() {
return RESPONSE;
return ServerMessageRequestProcessor.METHOD + RESPONSE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.server.transimit.request.message.ServerMessageRequestProcessor;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;
import io.github.lunasaw.sip.common.entity.ToDevice;
import io.github.lunasaw.sip.common.entity.DeviceSession;
Expand Down Expand Up @@ -55,6 +56,6 @@ public String getCmdType() {

@Override
public String getRootType() {
return RESPONSE;
return ServerMessageRequestProcessor.METHOD + RESPONSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import javax.sip.RequestEvent;

import io.github.lunasaw.gbproxy.server.transimit.request.notify.NotifyProcessorServer;
import io.github.lunasaw.gbproxy.server.user.SipUserGenerateServer;

import org.springframework.stereotype.Component;

import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.gb28181.common.entity.notify.DeviceOtherUpdateNotify;
import io.github.lunasaw.gbproxy.server.transimit.request.message.MessageProcessorServer;
import io.github.lunasaw.gbproxy.server.transimit.request.notify.NotifyServerHandlerAbstract;
import io.github.lunasaw.gbproxy.server.transimit.request.notify.ServerNotifyRequestProcessor;
import io.github.lunasaw.sip.common.entity.DeviceSession;
import io.github.lunasaw.sip.common.entity.ToDevice;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -28,7 +25,6 @@ public class CatalogNotifyHandler extends NotifyServerHandlerAbstract {

public static final String CMD_TYPE = "Catalog";


@Override
public void handForEvt(RequestEvent event) {
DeviceSession deviceSession = getDeviceSession(event);
Expand All @@ -52,6 +48,6 @@ public String getCmdType() {

@Override
public String getRootType() {
return RESPONSE;
return ServerNotifyRequestProcessor.METHOD + RESPONSE;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.lunasaw.sip.common.entity;

import io.github.lunasaw.sip.common.constant.Constant;
import io.github.lunasaw.sip.common.enums.StreamModeEnum;
import io.github.lunasaw.sip.common.enums.TransModeEnum;

import io.github.lunasaw.sip.common.utils.SipRequestUtils;
import lombok.Data;

Expand Down Expand Up @@ -31,8 +30,8 @@ public static FromDevice getInstance(String userId, String ip, int port) {
fromDevice.setUserId(userId);
fromDevice.setIp(ip);
fromDevice.setPort(port);
fromDevice.setTransport(TransModeEnum.UDP.getType());
fromDevice.setStreamMode(StreamModeEnum.TCP_PASSIVE.getType());
fromDevice.setTransport("UDP");
fromDevice.setStreamMode("TCP_PASSIVE");
fromDevice.setFromTag(SipRequestUtils.getNewFromTag());
fromDevice.setAgent(Constant.AGENT);
return fromDevice;
Expand Down
Loading

0 comments on commit bd7bc0f

Please sign in to comment.