openvidu-server: participant location dummy

pull/121/head
pabloFuente 2018-09-25 10:26:53 +02:00
parent 68d704ab33
commit 1271c5a0aa
7 changed files with 51 additions and 79 deletions

View File

@ -281,11 +281,6 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.7</version> <version>3.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.12.0</version>
</dependency>
<!-- Test dependencies --> <!-- Test dependencies -->

View File

@ -61,6 +61,8 @@ import io.openvidu.server.recording.ComposedRecordingService;
import io.openvidu.server.rest.NgrokRestController; import io.openvidu.server.rest.NgrokRestController;
import io.openvidu.server.rpc.RpcHandler; import io.openvidu.server.rpc.RpcHandler;
import io.openvidu.server.rpc.RpcNotificationService; import io.openvidu.server.rpc.RpcNotificationService;
import io.openvidu.server.utils.GeoLocationByIp;
import io.openvidu.server.utils.GeoLocationByIpDummy;
/** /**
* OpenVidu Server application * OpenVidu Server application
@ -154,6 +156,12 @@ public class OpenViduServer implements JsonRpcConfigurer {
return new CoturnCredentialsServiceFactory(openviduConfig()).getCoturnCredentialsService(); return new CoturnCredentialsServiceFactory(openviduConfig()).getCoturnCredentialsService();
} }
@Bean
@ConditionalOnMissingBean
public GeoLocationByIp geoLocationByIp() {
return new GeoLocationByIpDummy();
}
@Override @Override
public void registerJsonRpcHandlers(JsonRpcHandlerRegistry registry) { public void registerJsonRpcHandlers(JsonRpcHandlerRegistry registry) {
registry.addHandler(rpcHandler().withPingWatchdog(true), "/openvidu"); registry.addHandler(rpcHandler().withPingWatchdog(true), "/openvidu");

View File

@ -37,7 +37,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
@ -47,7 +46,7 @@ import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant; import io.openvidu.server.core.Participant;
import io.openvidu.server.core.SessionManager; import io.openvidu.server.core.SessionManager;
import io.openvidu.server.core.Token; import io.openvidu.server.core.Token;
import io.openvidu.server.utils.GeoLocationByIpUtils; import io.openvidu.server.utils.GeoLocationByIp;
public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> { public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
@ -57,7 +56,7 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
OpenviduConfig openviduConfig; OpenviduConfig openviduConfig;
@Autowired @Autowired
GeoLocationByIpUtils geoLocationByIp; GeoLocationByIp geoLocationByIp;
@Autowired @Autowired
SessionManager sessionManager; SessionManager sessionManager;
@ -180,11 +179,10 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
location = "error"; location = "error";
} catch (GeoIp2Exception e) { } catch (Exception e) {
log.warn("Error getting address location: {}", e.getMessage()); log.warn("Error getting address location: {}", e.getMessage());
location = "unknown"; location = "unknown";
} }
} }
boolean recorder = false; boolean recorder = false;

View File

@ -0,0 +1,26 @@
/*
* (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.openvidu.server.utils;
import java.net.InetAddress;
public interface GeoLocationByIp {
public String getLocationByIp(InetAddress ipAddress) throws Exception;
}

View File

@ -0,0 +1,14 @@
package io.openvidu.server.utils;
import java.net.InetAddress;
import org.springframework.stereotype.Service;
@Service
public class GeoLocationByIpDummy implements GeoLocationByIp {
public String getLocationByIp(InetAddress ipAddress) throws Exception {
return "";
}
}

View File

@ -1,69 +0,0 @@
package io.openvidu.server.utils;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import com.maxmind.db.Reader;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
/**
* This product includes GeoLite2 data created by MaxMind, available from
* <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
*/
@Service("geolocationservice")
public class GeoLocationByIpUtils {
private static final Logger log = LoggerFactory.getLogger(GeoLocationByIpUtils.class);
private static DatabaseReader reader = null;
private ResourceLoader resourceLoader;
@Inject
public GeoLocationByIpUtils(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
@PostConstruct
public void init() {
try {
log.info("Trying to load GeoLite2-City database...");
Resource resource = resourceLoader.getResource("classpath:GeoLite2-City.mmdb");
InputStream dbAsStream = resource.getInputStream();
// Initialize the reader
reader = new DatabaseReader.Builder(dbAsStream).fileMode(Reader.FileMode.MEMORY).build();
log.info("Database was loaded successfully");
} catch (IOException | NullPointerException e) {
log.error("Database reader cound not be initialized", e);
}
}
@PreDestroy
public void preDestroy() {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
log.error("Failed to close the GeoLocation reader");
}
}
}
public String getLocationByIp(InetAddress ipAddress) throws IOException, GeoIp2Exception {
CityResponse response = reader.city(ipAddress);
return response.getCity().getNames().get("en") + ", " + response.getCountry().getNames().get("en");
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 MiB