openvidu-server: ngrok environment updated

pull/73/head
pabloFuente 2018-05-14 12:04:11 +02:00
parent 7c871218ef
commit bb2e120991
1 changed files with 28 additions and 11 deletions

View File

@ -34,8 +34,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@ -72,6 +74,8 @@ public class OpenViduServer implements JsonRpcConfigurer {
public static final String KMSS_URIS_PROPERTY = "kms.uris"; public static final String KMSS_URIS_PROPERTY = "kms.uris";
public static String publicUrl; public static String publicUrl;
private String ngrokAppUrl = "";
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ -166,20 +170,19 @@ public class OpenViduServer implements JsonRpcConfigurer {
case "ngrok": case "ngrok":
try { try {
NgrokRestController ngrok = new NgrokRestController(); NgrokRestController ngrok = new NgrokRestController();
String ngrokAppUrl = ngrok.getNgrokAppUrl(); ngrokAppUrl = ngrok.getNgrokAppUrl();
if (ngrokAppUrl.isEmpty()) { if (ngrokAppUrl.isEmpty()) {
ngrokAppUrl = "(No tunnel 'app' found in ngrok.yml)"; ngrokAppUrl = "(No tunnel 'app' found in ngrok.yml)";
} }
final String NEW_LINE = System.getProperty("line.separator");
String str = NEW_LINE + // For frontend-only applications overriding openvidu-server dashboard...
NEW_LINE + " APP PUBLIC IP " + String ngrokServerUrl = ngrok.getNgrokServerUrl();
NEW_LINE + "-------------------------" + if (ngrokServerUrl.isEmpty()) {
NEW_LINE + ngrokAppUrl + ngrokServerUrl = ngrok.getNgrokAppUrl();
NEW_LINE + "-------------------------" + }
NEW_LINE;
log.info(str); OpenViduServer.publicUrl = ngrokServerUrl.replaceFirst("https://", "wss://");
OpenViduServer.publicUrl = ngrok.getNgrokServerUrl().replaceFirst("https://", "wss://"); openviduConf.setFinalUrl(ngrokServerUrl);
openviduConf.setFinalUrl(ngrok.getNgrokServerUrl());
} catch (Exception e) { } catch (Exception e) {
log.error("Ngrok URL was configured, but there was an error connecting to ngrok: " log.error("Ngrok URL was configured, but there was an error connecting to ngrok: "
@ -291,5 +294,19 @@ public class OpenViduServer implements JsonRpcConfigurer {
} }
log.info("OpenVidu Server using " + type + " URL: [" + OpenViduServer.publicUrl + "]"); log.info("OpenVidu Server using " + type + " URL: [" + OpenViduServer.publicUrl + "]");
} }
@EventListener(ApplicationReadyEvent.class)
public void printNgrokUrl() {
if (!this.ngrokAppUrl.isEmpty()) {
final String NEW_LINE = System.getProperty("line.separator");
String str = NEW_LINE +
NEW_LINE + " APP PUBLIC IP " +
NEW_LINE + "-------------------------" +
NEW_LINE + ngrokAppUrl +
NEW_LINE + "-------------------------" +
NEW_LINE;
log.info(str);
}
}
} }