openvidu-server: GeoLocation

pull/255/head
pabloFuente 2019-03-13 15:37:40 +01:00
parent 8fd17155a1
commit 10e78ab00b
9 changed files with 67 additions and 18 deletions

View File

@ -41,7 +41,8 @@ public class CDREventParticipant extends CDREventEnd {
public JsonObject toJson() {
JsonObject json = super.toJson();
json.addProperty("participantId", this.participant.getParticipantPublicId());
json.addProperty("location", this.participant.getLocation());
json.addProperty("location",
this.participant.getLocation() != null ? this.participant.getLocation().toString() : "unknown");
json.addProperty("platform", this.participant.getPlatform());
return json;
}

View File

@ -25,12 +25,13 @@ import com.google.gson.JsonObject;
import io.openvidu.server.cdr.CDREventParticipant;
import io.openvidu.server.summary.ParticipantSummary;
import io.openvidu.server.utils.GeoLocation;
public class FinalUser {
private String id;
private String sessionId;
private String location;
private GeoLocation location;
private String platform;
private Map<String, ParticipantSummary> connections = new ConcurrentHashMap<>();
@ -51,7 +52,7 @@ public class FinalUser {
return sessionId;
}
public String getLocation() {
public GeoLocation getLocation() {
return location;
}
@ -76,7 +77,7 @@ public class FinalUser {
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("id", id);
json.addProperty("location", location);
json.addProperty("location", this.location != null ? this.location.toString() : "unknown");
json.addProperty("platform", platform);
JsonObject connectionsJson = new JsonObject();

View File

@ -19,6 +19,8 @@ package io.openvidu.server.core;
import com.google.gson.JsonObject;
import io.openvidu.server.utils.GeoLocation;
public class Participant {
protected String finalUserId; // ID to match this connection with a final user (HttpSession id)
@ -29,7 +31,7 @@ public class Participant {
protected String clientMetadata = ""; // Metadata provided on client side
protected String serverMetadata = ""; // Metadata provided on server side
protected Token token; // Token associated to this participant
protected String location; // Remote IP of the participant
protected GeoLocation location; // Location of the participant
protected String platform; // Platform used by the participant to connect to the session
protected boolean streaming = false;
@ -38,7 +40,7 @@ public class Participant {
private final String METADATA_SEPARATOR = "%/%";
public Participant(String finalUserId, String participantPrivatetId, String participantPublicId, String sessionId,
Token token, String clientMetadata, String location, String platform, Long createdAt) {
Token token, String clientMetadata, GeoLocation location, String platform, Long createdAt) {
this.finalUserId = finalUserId;
this.participantPrivatetId = participantPrivatetId;
this.participantPublicId = participantPublicId;
@ -108,11 +110,11 @@ public class Participant {
this.token = token;
}
public String getLocation() {
public GeoLocation getLocation() {
return this.location;
}
public void setLocation(String location) {
public void setLocation(GeoLocation location) {
this.location = location;
}
@ -209,8 +211,7 @@ public class Participant {
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("connectionId", this.participantPublicId);
json.addProperty("createdAt", this.createdAt);
json.addProperty("location", this.location);
json.addProperty("location", this.location != null ? this.location.toString() : "unknown");
json.addProperty("platform", this.platform);
json.addProperty("token", this.token.getToken());
json.addProperty("role", this.token.getRole().name());

View File

@ -47,6 +47,7 @@ import io.openvidu.server.coturn.CoturnCredentialsService;
import io.openvidu.server.kurento.core.KurentoTokenOptions;
import io.openvidu.server.recording.service.RecordingManager;
import io.openvidu.server.utils.FormatChecker;
import io.openvidu.server.utils.GeoLocation;
import io.openvidu.server.utils.RandomStringGenerator;
public abstract class SessionManager {
@ -335,7 +336,7 @@ public abstract class SessionManager {
}
public Participant newParticipant(String sessionId, String participantPrivatetId, Token token,
String clientMetadata, String location, String platform, String finalUserId) {
String clientMetadata, GeoLocation location, String platform, String finalUserId) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
String participantPublicId = RandomStringGenerator.generateRandomChain();
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,

View File

@ -49,6 +49,7 @@ import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant;
import io.openvidu.server.core.SessionManager;
import io.openvidu.server.core.Token;
import io.openvidu.server.utils.GeoLocation;
import io.openvidu.server.utils.GeoLocationByIp;
import io.openvidu.server.utils.RandomStringGenerator;
@ -174,7 +175,7 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
String participantPrivatetId = rpcConnection.getParticipantPrivateId();
InetAddress remoteAddress = null;
String location = "";
GeoLocation location = null;
Object obj = rpcConnection.getSession().getAttributes().get("remoteAddress");
if (obj != null && obj instanceof InetAddress) {
remoteAddress = (InetAddress) obj;
@ -182,10 +183,10 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
location = this.geoLocationByIp.getLocationByIp(remoteAddress);
} catch (IOException e) {
e.printStackTrace();
location = "error";
location = null;
} catch (Exception e) {
log.warn("Error getting address location: {}", e.getMessage());
location = "unknown";
location = null;
}
}

View File

@ -78,9 +78,13 @@ public class SessionSummary {
return json;
}
public CDREventSession getEventSessionEnd() {
return this.eventSessionEnd;
}
public Map<String, FinalUser> getUsers() {
return this.users;
}
}

View File

@ -0,0 +1,39 @@
package io.openvidu.server.utils;
public class GeoLocation {
private String country;
private String city;
private Double latitude;
private Double longitude;
public GeoLocation(String country, String city, Double latitude, Double longitude) {
super();
this.country = country;
this.city = city;
this.latitude = latitude;
this.longitude = longitude;
}
public String getCountry() {
return country;
}
public String getCity() {
return city;
}
public Double getLatitude() {
return latitude;
}
public Double getLongitude() {
return longitude;
}
@Override
public String toString() {
return this.city + ", " + this.country;
}
}

View File

@ -21,6 +21,6 @@ import java.net.InetAddress;
public interface GeoLocationByIp {
public String getLocationByIp(InetAddress ipAddress) throws Exception;
public GeoLocation getLocationByIp(InetAddress ipAddress) throws Exception;
}

View File

@ -7,8 +7,9 @@ import org.springframework.stereotype.Service;
@Service
public class GeoLocationByIpDummy implements GeoLocationByIp {
public String getLocationByIp(InetAddress ipAddress) throws Exception {
return "";
@Override
public GeoLocation getLocationByIp(InetAddress ipAddress) throws Exception {
return null;
}
}