openvidu-server: add property ip to Connection entity

pull/648/head
pabloFuente 2021-08-10 17:54:00 +02:00
parent 3d46a2c473
commit 7d17c05409
5 changed files with 22 additions and 10 deletions

View File

@ -70,7 +70,8 @@ public class FinalUser {
public JsonObject toJson() { public JsonObject toJson() {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("id", id); json.addProperty("id", id);
json.addProperty("location", this.location != null ? this.location.toString() : "unknown"); json.addProperty("ip", this.location.getIp());
json.addProperty("location", this.location.toString());
json.addProperty("platform", platform); json.addProperty("platform", platform);
JsonObject connectionsJson = new JsonObject(); JsonObject connectionsJson = new JsonObject();

View File

@ -1133,6 +1133,7 @@ public class KurentoSessionManager extends SessionManager {
// Generate the location for the IpCam // Generate the location for the IpCam
GeoLocation location = null; GeoLocation location = null;
URL url = null; URL url = null;
InetAddress ipAddress = null;
String protocol = null; String protocol = null;
try { try {
Pattern pattern = Pattern.compile("^(file|rtsp)://"); Pattern pattern = Pattern.compile("^(file|rtsp)://");
@ -1149,13 +1150,14 @@ public class KurentoSessionManager extends SessionManager {
} }
try { try {
location = this.geoLocationByIp.getLocationByIp(InetAddress.getByName(url.getHost())); ipAddress = InetAddress.getByName(url.getHost());
location = this.geoLocationByIp.getLocationByIp(ipAddress);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
location = null; location = new GeoLocation(ipAddress.getHostAddress());
} catch (Exception e) { } catch (Exception e) {
log.warn("Error getting address location: {}", e.getMessage()); log.warn("Error getting address location: {}", e.getMessage());
location = null; location = new GeoLocation(ipAddress.getHostAddress());
} }
String rtspConnectionId = kMediaOptions.getTypeOfVideo() + "_" + protocol + "_" String rtspConnectionId = kMediaOptions.getTypeOfVideo() + "_" + protocol + "_"
@ -1204,7 +1206,8 @@ public class KurentoSessionManager extends SessionManager {
boolean initByServer, boolean forciblyReconnect) { boolean initByServer, boolean forciblyReconnect) {
KurentoParticipant kParticipant = (KurentoParticipant) participant; KurentoParticipant kParticipant = (KurentoParticipant) participant;
KurentoSession kSession = kParticipant.getSession(); KurentoSession kSession = kParticipant.getSession();
reconnectSubscriber(kSession, kParticipant, streamId, sdpString, transactionId, initByServer, forciblyReconnect); reconnectSubscriber(kSession, kParticipant, streamId, sdpString, transactionId, initByServer,
forciblyReconnect);
} }
private String mungeSdpOffer(Session kSession, Participant participant, String sdpOffer, boolean isPublisher) { private String mungeSdpOffer(Session kSession, Participant participant, String sdpOffer, boolean isPublisher) {

View File

@ -205,11 +205,11 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
location = this.geoLocationByIp.getLocationByIp(remoteAddress); location = this.geoLocationByIp.getLocationByIp(remoteAddress);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
location = null; location = new GeoLocation(remoteAddress.getHostAddress());
} catch (Exception e) { } catch (Exception e) {
log.warn("Couldn't locate IP address {} in geolocation database: {}", remoteAddress.getHostAddress(), log.warn("Couldn't locate IP address {} in geolocation database: {}", remoteAddress.getHostAddress(),
e.getMessage()); e.getMessage());
location = null; location = new GeoLocation(remoteAddress.getHostAddress());
} }
} }

View File

@ -9,6 +9,11 @@ public class GeoLocation {
private Double latitude; private Double latitude;
private Double longitude; private Double longitude;
public GeoLocation(String ip) {
super();
this.ip = ip;
}
public GeoLocation(String ip, String country, String city, String timezone, Double latitude, Double longitude) { public GeoLocation(String ip, String country, String city, String timezone, Double latitude, Double longitude) {
super(); super();
this.ip = ip; this.ip = ip;
@ -45,6 +50,9 @@ public class GeoLocation {
@Override @Override
public String toString() { public String toString() {
if (this.country == null) {
return "unknown";
}
String location = this.country; String location = this.country;
if (this.city != null) { if (this.city != null) {
location = this.city + ", " + location; location = this.city + ", " + location;

View File

@ -47,9 +47,9 @@ import io.openvidu.test.browsers.utils.RecordingUtils;
public class AbstractOpenViduTestAppE2eTest { public class AbstractOpenViduTestAppE2eTest {
final protected String DEFAULT_JSON_SESSION = "{'id':'STR','object':'session','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultRecordingProperties':{'hasVideo':true,'frameRate':25,'hasAudio':true,'shmSize':536870912,'name':'','outputMode':'COMPOSED','resolution':'1280x720','recordingLayout':'BEST_FIT'},'customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false,'forcedVideoCodec':'STR','allowTranscoding':false}"; final protected String DEFAULT_JSON_SESSION = "{'id':'STR','object':'session','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultRecordingProperties':{'hasVideo':true,'frameRate':25,'hasAudio':true,'shmSize':536870912,'name':'','outputMode':'COMPOSED','resolution':'1280x720','recordingLayout':'BEST_FIT'},'customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false,'forcedVideoCodec':'STR','allowTranscoding':false}";
final protected String DEFAULT_JSON_PENDING_CONNECTION = "{'id':'STR','object':'connection','type':'WEBRTC','status':'pending','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':null,'location':null,'platform':null,'token':'STR','serverData':'STR','record':true,'role':'STR','kurentoOptions':null,'rtspUri':null,'adaptativeBitrate':null,'onlyPlayWithSubscribers':null,'networkCache':null,'clientData':null,'publishers':null,'subscribers':null}"; final protected String DEFAULT_JSON_PENDING_CONNECTION = "{'id':'STR','object':'connection','type':'WEBRTC','status':'pending','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':null,'location':null,'ip':null,'platform':null,'token':'STR','serverData':'STR','record':true,'role':'STR','kurentoOptions':null,'rtspUri':null,'adaptativeBitrate':null,'onlyPlayWithSubscribers':null,'networkCache':null,'clientData':null,'publishers':null,'subscribers':null}";
final protected String DEFAULT_JSON_ACTIVE_CONNECTION = "{'id':'STR','object':'connection','type':'WEBRTC','status':'active','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':0,'location':'STR','platform':'STR','token':'STR','serverData':'STR','record':true,'role':'STR','kurentoOptions':null,'rtspUri':null,'adaptativeBitrate':null,'onlyPlayWithSubscribers':null,'networkCache':null,'clientData':'STR','publishers':[],'subscribers':[]}"; final protected String DEFAULT_JSON_ACTIVE_CONNECTION = "{'id':'STR','object':'connection','type':'WEBRTC','status':'active','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':0,'location':'STR','ip':'STR','platform':'STR','token':'STR','serverData':'STR','record':true,'role':'STR','kurentoOptions':null,'rtspUri':null,'adaptativeBitrate':null,'onlyPlayWithSubscribers':null,'networkCache':null,'clientData':'STR','publishers':[],'subscribers':[]}";
final protected String DEFAULT_JSON_IPCAM_CONNECTION = "{'id':'STR','object':'connection','type':'IPCAM','status':'active','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':0,'location':'STR','platform':'IPCAM','token':null,'serverData':'STR','record':true,'role':null,'kurentoOptions':null,'rtspUri':'STR','adaptativeBitrate':true,'onlyPlayWithSubscribers':true,'networkCache':2000,'clientData':null,'publishers':[],'subscribers':[]}"; final protected String DEFAULT_JSON_IPCAM_CONNECTION = "{'id':'STR','object':'connection','type':'IPCAM','status':'active','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':0,'location':'STR','ip':'STR','platform':'IPCAM','token':null,'serverData':'STR','record':true,'role':null,'kurentoOptions':null,'rtspUri':'STR','adaptativeBitrate':true,'onlyPlayWithSubscribers':true,'networkCache':2000,'clientData':null,'publishers':[],'subscribers':[]}";
final protected String DEFAULT_JSON_TOKEN = "{'id':'STR','token':'STR','connectionId':'STR','createdAt':0,'session':'STR','role':'STR','data':'STR','kurentoOptions':{}}"; final protected String DEFAULT_JSON_TOKEN = "{'id':'STR','token':'STR','connectionId':'STR','createdAt':0,'session':'STR','role':'STR','data':'STR','kurentoOptions':{}}";
protected static String OPENVIDU_SECRET = "MY_SECRET"; protected static String OPENVIDU_SECRET = "MY_SECRET";