实现注册流程
parent
508ee15066
commit
7a8edea181
|
@ -281,7 +281,7 @@ create table wvp_user_role (
|
|||
|
||||
create table wvp_sip_server (
|
||||
id serial primary key ,
|
||||
local_ip character varying(50) not null ,
|
||||
local_ip character varying(50) null ,
|
||||
local_port integer,
|
||||
server_ip character varying(50) not null ,
|
||||
server_port integer,
|
||||
|
|
|
@ -38,4 +38,7 @@ public interface SipServerAccountMapper {
|
|||
|
||||
@Select("SELECT * FROM wvp_sip_server_account")
|
||||
List<SipServerAccount> all(int id);
|
||||
|
||||
@Select("SELECT * FROM wvp_sip_server_account WHERE sip_server_id = #{serverId} AND username = #{username}")
|
||||
SipServerAccount getOneByUsername(int serverId, String username);
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ public interface SipServerMapper {
|
|||
@Select("SELECT * FROM wvp_sip_server WHERE id = #{sipServerId}")
|
||||
SipServer query(int sipServerId);
|
||||
|
||||
@Select("SELECT * FROM wvp_sip_server WHERE id = #{sipServerId}")
|
||||
@Select("SELECT * FROM wvp_sip_server")
|
||||
List<SipServer> all();
|
||||
|
||||
|
||||
|
||||
@Select("SELECT * FROM wvp_sip_server WHERE server_ip = #{host} AND server_port = #{port}")
|
||||
SipServer getOneByServerAddress(String host, int port);
|
||||
}
|
||||
|
|
|
@ -96,4 +96,11 @@ public interface ISipService {
|
|||
* 移除
|
||||
*/
|
||||
void removeSipVideo(Integer videoId);
|
||||
|
||||
/**
|
||||
* 使用地址信息获取服务
|
||||
*/
|
||||
SipServer getSipServerByServerAddress(String removeHost, int remotePort);
|
||||
|
||||
SipServerAccount getAccountByUsername(int serverId,String username);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public class SipListenerImpl implements SipListener {
|
|||
|
||||
private Map<String, ISIPResponseProcessor> responseProcessorMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
@Async("taskExecutor")
|
||||
public void processRequest(RequestEvent requestEvent) {
|
||||
|
@ -51,6 +52,9 @@ public class SipListenerImpl implements SipListener {
|
|||
if (((status >= Response.OK) && (status < Response.MULTIPLE_CHOICES)) || status == Response.UNAUTHORIZED) {
|
||||
CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);
|
||||
String method = cseqHeader.getMethod();
|
||||
// if (method.equalsIgnoreCase("REGISTER")) {
|
||||
// sipRegisterResponseProcessor.process(responseEvent);
|
||||
// }
|
||||
ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method);
|
||||
if (sipRequestProcessor != null) {
|
||||
sipRequestProcessor.process(responseEvent);
|
||||
|
@ -104,4 +108,8 @@ public class SipListenerImpl implements SipListener {
|
|||
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
|
||||
|
||||
}
|
||||
|
||||
public void addProcessor(String method, ISIPResponseProcessor processor) {
|
||||
responseProcessorMap.put(method, processor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,4 +132,9 @@ public class SipSdkImpl implements SipSdk {
|
|||
sipProviderMap.put(sipServer.getLocalIp() + ":" + sipServer.getLocalPort(), sipProvider);
|
||||
return sipProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SipProviderImpl getProvider(String ip, int port) {
|
||||
return sipProviderMap.get(ip + ":" + port);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,4 +159,14 @@ public class SipServiceImpl implements ISipService {
|
|||
public void removeSipVideo(Integer videoId) {
|
||||
videoMapper.remove(videoId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SipServer getSipServerByServerAddress(String host, int port) {
|
||||
return serverMapper.getOneByServerAddress(host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SipServerAccount getAccountByUsername(int serverId, String username) {
|
||||
return accountMapper.getOneByUsername(serverId, username);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package com.genersoft.iot.vmp.sip.service.Impl.response;
|
||||
|
||||
import com.genersoft.iot.vmp.sip.SipCommander;
|
||||
import com.genersoft.iot.vmp.sip.bean.SipServer;
|
||||
import com.genersoft.iot.vmp.sip.bean.SipServerAccount;
|
||||
import com.genersoft.iot.vmp.sip.service.ISIPResponseProcessor;
|
||||
import com.genersoft.iot.vmp.sip.service.ISipService;
|
||||
import com.genersoft.iot.vmp.sip.service.SipSdk;
|
||||
import com.genersoft.iot.vmp.sip.utils.SipUtils;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.WWWAuthenticateHeader;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* Register响应处理器
|
||||
*/
|
||||
@Component
|
||||
public class SipRegisterResponseProcessor implements ISIPResponseProcessor {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SipRegisterResponseProcessor.class);
|
||||
|
||||
@Autowired
|
||||
private SipCommander sipCommander;
|
||||
|
||||
@Autowired
|
||||
private ISipService sipService;
|
||||
|
||||
@Autowired
|
||||
private SipSdk sipSdk;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理Register响应
|
||||
*
|
||||
* @param evt 事件
|
||||
*/
|
||||
@Override
|
||||
public void process(ResponseEvent evt) {
|
||||
SIPResponse response = (SIPResponse) evt.getResponse();
|
||||
if (response.getStatusCode() == 401) {
|
||||
WWWAuthenticateHeader authenticateHeader = (WWWAuthenticateHeader) response.getHeader(WWWAuthenticateHeader.NAME);
|
||||
String removeHost = response.getRemoteAddress().getHostAddress();
|
||||
int remotePort = response.getRemotePort();
|
||||
SipServer server = sipService.getSipServerByServerAddress(removeHost, remotePort);
|
||||
String username = SipUtils.getUserFromToHeader(response.getToHeader());
|
||||
SipServerAccount account = sipService.getAccountByUsername(server.getId(), username);
|
||||
SipProviderImpl sipProvider = sipSdk.getProvider(removeHost, remotePort);
|
||||
try {
|
||||
sipCommander.register(server, account, sipProvider, authenticateHeader, true, (code1, msg1, data1)->{
|
||||
|
||||
|
||||
|
||||
}, (code2, msg2, data2)->{
|
||||
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException | NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.sip.service;
|
|||
import com.genersoft.iot.vmp.sip.bean.ResultCallback;
|
||||
import com.genersoft.iot.vmp.sip.bean.SipServer;
|
||||
import com.genersoft.iot.vmp.sip.bean.SipServerAccount;
|
||||
import gov.nist.javax.sip.SipProviderImpl;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.ObjectInUseException;
|
||||
|
@ -16,4 +17,6 @@ import java.util.TooManyListenersException;
|
|||
public interface SipSdk {
|
||||
|
||||
void register(SipServer sipServer, SipServerAccount account, ResultCallback<Object> callback) throws PeerUnavailableException, TransportNotSupportedException, InvalidArgumentException, ObjectInUseException, TooManyListenersException;
|
||||
|
||||
SipProviderImpl getProvider(String ip, int port);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import org.springframework.util.ObjectUtils;
|
|||
|
||||
import javax.sip.PeerUnavailableException;
|
||||
import javax.sip.SipFactory;
|
||||
import javax.sip.address.Address;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.ToHeader;
|
||||
import javax.sip.header.UserAgentHeader;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
|
@ -80,4 +83,19 @@ public class SipUtils {
|
|||
public static String getNewTag(){
|
||||
return String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public static String getUserFromToHeader(ToHeader toHeader) {
|
||||
Address address = toHeader.getAddress();
|
||||
String displayName = address.getDisplayName();
|
||||
boolean isSipURI = address.getURI().isSipURI();
|
||||
String user = null;
|
||||
if (isSipURI) {
|
||||
SipURI sipURI = (SipURI) address.getURI();
|
||||
user = sipURI.getUser();
|
||||
String host = sipURI.getHost();
|
||||
int port = sipURI.getPort();
|
||||
System.out.println(1111);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue