mirror of https://github.com/OpenVidu/openvidu.git
ngrok configuration removed
parent
e001b2dbc9
commit
c670b76e3d
|
@ -58,7 +58,6 @@ import io.openvidu.server.kurento.core.KurentoSessionEventsHandler;
|
|||
import io.openvidu.server.kurento.core.KurentoSessionManager;
|
||||
import io.openvidu.server.kurento.kms.FixedOneKmsManager;
|
||||
import io.openvidu.server.recording.ComposedRecordingService;
|
||||
import io.openvidu.server.rest.NgrokRestController;
|
||||
import io.openvidu.server.rpc.RpcHandler;
|
||||
import io.openvidu.server.rpc.RpcNotificationService;
|
||||
import io.openvidu.server.utils.CommandExecutor;
|
||||
|
@ -81,9 +80,9 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
|
||||
public static final String KMSS_URIS_PROPERTY = "kms.uris";
|
||||
|
||||
public static String publicUrl;
|
||||
|
||||
private String ngrokAppUrl = "";
|
||||
public static String wsUrl;
|
||||
|
||||
public static String httpUrl;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
|
@ -187,44 +186,24 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
String type = publicUrl;
|
||||
|
||||
switch (publicUrl) {
|
||||
case "ngrok":
|
||||
try {
|
||||
NgrokRestController ngrok = new NgrokRestController();
|
||||
ngrokAppUrl = ngrok.getNgrokAppUrl();
|
||||
if (ngrokAppUrl.isEmpty()) {
|
||||
ngrokAppUrl = "(No tunnel 'app' found in ngrok.yml)";
|
||||
}
|
||||
|
||||
// For frontend-only applications overriding openvidu-server dashboard...
|
||||
String ngrokServerUrl = ngrok.getNgrokServerUrl();
|
||||
if (ngrokServerUrl.isEmpty()) {
|
||||
ngrokServerUrl = ngrok.getNgrokAppUrl();
|
||||
}
|
||||
|
||||
OpenViduServer.publicUrl = ngrokServerUrl.replaceFirst("https://", "wss://");
|
||||
openviduConf.setFinalUrl(ngrokServerUrl);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Ngrok URL was configured, but there was an error connecting to ngrok: "
|
||||
+ e.getClass().getName() + " " + e.getMessage());
|
||||
log.error("Fallback to local URL");
|
||||
}
|
||||
break;
|
||||
|
||||
case "docker":
|
||||
try {
|
||||
String containerIp = getContainerIp();
|
||||
OpenViduServer.publicUrl = "wss://" + containerIp + ":" + openviduConf.getServerPort();
|
||||
OpenViduServer.wsUrl = "wss://" + containerIp + ":" + openviduConf.getServerPort();
|
||||
openviduConf.setFinalUrl("https://" + containerIp + ":" + openviduConf.getServerPort());
|
||||
} catch (Exception e) {
|
||||
log.error("Docker container IP was configured, but there was an error obtaining IP: "
|
||||
+ e.getClass().getName() + " " + e.getMessage());
|
||||
log.error("Fallback to local URL");
|
||||
OpenViduServer.wsUrl = null;
|
||||
}
|
||||
break;
|
||||
|
||||
case "local":
|
||||
break;
|
||||
|
||||
case "":
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
|
@ -233,26 +212,26 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
type = "custom";
|
||||
|
||||
if (publicUrl.startsWith("https://")) {
|
||||
OpenViduServer.publicUrl = publicUrl.replace("https://", "wss://");
|
||||
OpenViduServer.wsUrl = publicUrl.replace("https://", "wss://");
|
||||
} else if (publicUrl.startsWith("http://")) {
|
||||
OpenViduServer.publicUrl = publicUrl.replace("http://", "wss://");
|
||||
OpenViduServer.wsUrl = publicUrl.replace("http://", "wss://");
|
||||
}
|
||||
|
||||
openviduConf.setFinalUrl(url.toString());
|
||||
|
||||
if (!OpenViduServer.publicUrl.startsWith("wss://")) {
|
||||
OpenViduServer.publicUrl = "wss://" + OpenViduServer.publicUrl;
|
||||
if (!OpenViduServer.wsUrl.startsWith("wss://")) {
|
||||
OpenViduServer.wsUrl = "wss://" + OpenViduServer.wsUrl;
|
||||
}
|
||||
}
|
||||
|
||||
if (OpenViduServer.publicUrl == null) {
|
||||
if (OpenViduServer.wsUrl == null) {
|
||||
type = "local";
|
||||
OpenViduServer.publicUrl = "wss://localhost:" + openviduConf.getServerPort();
|
||||
OpenViduServer.wsUrl = "wss://localhost:" + openviduConf.getServerPort();
|
||||
openviduConf.setFinalUrl("https://localhost:" + openviduConf.getServerPort());
|
||||
}
|
||||
|
||||
if (OpenViduServer.publicUrl.endsWith("/")) {
|
||||
OpenViduServer.publicUrl = OpenViduServer.publicUrl.substring(0, OpenViduServer.publicUrl.length() - 1);
|
||||
if (OpenViduServer.wsUrl.endsWith("/")) {
|
||||
OpenViduServer.wsUrl = OpenViduServer.wsUrl.substring(0, OpenViduServer.wsUrl.length() - 1);
|
||||
}
|
||||
|
||||
boolean recordingModuleEnabled = openviduConf.isRecordingModuleEnabled();
|
||||
|
@ -307,21 +286,21 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
|
||||
recordingService.initRecordingPath();
|
||||
}
|
||||
log.info("OpenVidu Server using " + type + " URL: [" + OpenViduServer.publicUrl + "]");
|
||||
|
||||
httpUrl = openviduConf.getFinalUrl();
|
||||
log.info("OpenVidu Server using " + type + " URL: [" + OpenViduServer.wsUrl + "]");
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void printNgrokUrl() {
|
||||
if (!this.ngrokAppUrl.isEmpty()) {
|
||||
final String NEW_LINE = System.lineSeparator();
|
||||
String str = NEW_LINE +
|
||||
NEW_LINE + " APP PUBLIC IP " +
|
||||
NEW_LINE + "-------------------------" +
|
||||
NEW_LINE + ngrokAppUrl +
|
||||
NEW_LINE + "-------------------------" +
|
||||
NEW_LINE;
|
||||
log.info(str);
|
||||
}
|
||||
public void printUrl() {
|
||||
final String NEW_LINE = System.lineSeparator();
|
||||
String str = NEW_LINE +
|
||||
NEW_LINE + " ACCESS IP " +
|
||||
NEW_LINE + "-------------------------" +
|
||||
NEW_LINE + httpUrl +
|
||||
NEW_LINE + "-------------------------" +
|
||||
NEW_LINE;
|
||||
log.info(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import io.openvidu.server.core.ParticipantRole;
|
|||
public class OpenviduConfig {
|
||||
|
||||
@Value("${openvidu.publicurl}")
|
||||
private String openviduPublicUrl; // local, ngrok, docker, [FINAL_URL]
|
||||
private String openviduPublicUrl; // local, docker, [FINAL_URL]
|
||||
|
||||
@Value("${server.port}")
|
||||
private String serverPort;
|
||||
|
|
|
@ -150,11 +150,9 @@ public abstract class SessionManager {
|
|||
/**
|
||||
* Returns all the participants inside a session.
|
||||
*
|
||||
* @param sessionId
|
||||
* identifier of the session
|
||||
* @param sessionId identifier of the session
|
||||
* @return set of {@link Participant}
|
||||
* @throws OpenViduException
|
||||
* in case the session doesn't exist
|
||||
* @throws OpenViduException in case the session doesn't exist
|
||||
*/
|
||||
public Set<Participant> getParticipants(String sessionId) throws OpenViduException {
|
||||
Session session = sessions.get(sessionId);
|
||||
|
@ -169,14 +167,11 @@ public abstract class SessionManager {
|
|||
/**
|
||||
* Returns a participant in a session
|
||||
*
|
||||
* @param sessionId
|
||||
* identifier of the session
|
||||
* @param participantPrivateId
|
||||
* private identifier of the participant
|
||||
* @param sessionId identifier of the session
|
||||
* @param participantPrivateId private identifier of the participant
|
||||
* @return {@link Participant}
|
||||
* @throws OpenViduException
|
||||
* in case the session doesn't exist or the participant doesn't
|
||||
* belong to it
|
||||
* @throws OpenViduException in case the session doesn't exist or the
|
||||
* participant doesn't belong to it
|
||||
*/
|
||||
public Participant getParticipant(String sessionId, String participantPrivateId) throws OpenViduException {
|
||||
Session session = sessions.get(sessionId);
|
||||
|
@ -194,11 +189,9 @@ public abstract class SessionManager {
|
|||
/**
|
||||
* Returns a participant
|
||||
*
|
||||
* @param participantPrivateId
|
||||
* private identifier of the participant
|
||||
* @param participantPrivateId private identifier of the participant
|
||||
* @return {@link Participant}
|
||||
* @throws OpenViduException
|
||||
* in case the participant doesn't exist
|
||||
* @throws OpenViduException in case the participant doesn't exist
|
||||
*/
|
||||
public Participant getParticipant(String participantPrivateId) throws OpenViduException {
|
||||
for (Session session : sessions.values()) {
|
||||
|
@ -232,11 +225,10 @@ public abstract class SessionManager {
|
|||
|
||||
if (!isMetadataFormatCorrect(serverMetadata)) {
|
||||
log.error("Data invalid format");
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||
"Data invalid format");
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE, "Data invalid format");
|
||||
}
|
||||
|
||||
String token = OpenViduServer.publicUrl;
|
||||
String token = OpenViduServer.wsUrl;
|
||||
token += "?sessionId=" + sessionId;
|
||||
token += "&token=" + this.generateRandomChain();
|
||||
token += "&role=" + role.name();
|
||||
|
@ -422,13 +414,12 @@ public abstract class SessionManager {
|
|||
* notifications to the existing participants in the session to inform that it
|
||||
* was forcibly closed.
|
||||
*
|
||||
* @param sessionId
|
||||
* identifier of the session
|
||||
* @param sessionId identifier of the session
|
||||
* @return
|
||||
* @return set of {@link Participant} POJOS representing the session's
|
||||
* participants
|
||||
* @throws OpenViduException
|
||||
* in case the session doesn't exist or has been already closed
|
||||
* @throws OpenViduException in case the session doesn't exist or has been
|
||||
* already closed
|
||||
*/
|
||||
public Set<Participant> closeSession(String sessionId, String reason) {
|
||||
Session session = sessions.get(sessionId);
|
||||
|
|
|
@ -526,7 +526,7 @@ public class ComposedRecordingService {
|
|||
|
||||
private String getLayoutUrl(Recording recording, String shortSessionId) {
|
||||
String secret = openviduConfig.getOpenViduSecret();
|
||||
String location = OpenViduServer.publicUrl.replaceFirst("wss://", "");
|
||||
String location = OpenViduServer.wsUrl.replaceFirst("wss://", "");
|
||||
String layout, finalUrl;
|
||||
|
||||
if (RecordingLayout.CUSTOM.equals(recording.getRecordingLayout())) {
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* (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.rest;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class NgrokRestController {
|
||||
|
||||
private final String NGROK_URL = "http://localhost:4040/api/tunnels";
|
||||
private final String NGROK_APP_NAME = "app";
|
||||
private final String NGROK_SERVER_NAME = "server";
|
||||
|
||||
private String appUrl = "";
|
||||
private String serverUrl = "";
|
||||
private JsonObject json;
|
||||
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
|
||||
public String getNgrokAppUrl() throws ClientProtocolException, IOException {
|
||||
|
||||
if (this.appUrl != null && !this.appUrl.isEmpty()) {
|
||||
return this.appUrl;
|
||||
}
|
||||
|
||||
if (this.json == null) {
|
||||
this.json = this.httpRequest();
|
||||
}
|
||||
|
||||
String appPublicUrl = "";
|
||||
|
||||
JsonArray array = this.json.getAsJsonArray("tunnels");
|
||||
for (JsonElement el : array) {
|
||||
JsonObject elObj = el.getAsJsonObject();
|
||||
String name = elObj.get("name").getAsString();
|
||||
if (name.equals(NGROK_APP_NAME)) {
|
||||
appPublicUrl = elObj.get("public_url").getAsString();
|
||||
appPublicUrl = appPublicUrl.replaceFirst("http://", "https://");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.appUrl = appPublicUrl;
|
||||
|
||||
return appPublicUrl;
|
||||
}
|
||||
|
||||
public String getNgrokServerUrl() throws ClientProtocolException, IOException {
|
||||
|
||||
if (this.serverUrl != null && !this.serverUrl.isEmpty()) {
|
||||
return this.serverUrl;
|
||||
}
|
||||
|
||||
if (this.json == null) {
|
||||
this.json = this.httpRequest();
|
||||
}
|
||||
|
||||
String serverPublicUrl = "";
|
||||
|
||||
JsonArray array = this.json.getAsJsonArray("tunnels");
|
||||
for (JsonElement el : array) {
|
||||
JsonObject elObj = el.getAsJsonObject();
|
||||
String name = elObj.get("name").getAsString();
|
||||
if (name.equals(NGROK_SERVER_NAME)) {
|
||||
serverPublicUrl = elObj.get("public_url").getAsString();
|
||||
serverPublicUrl = serverPublicUrl.replaceFirst("http://", "https://");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.serverUrl = serverPublicUrl;
|
||||
|
||||
return serverPublicUrl;
|
||||
}
|
||||
|
||||
private JsonObject httpRequest() throws ClientProtocolException, IOException {
|
||||
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
|
||||
HttpGet request = new HttpGet(NGROK_URL);
|
||||
HttpResponse response = client.execute(request);
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
String line = "";
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
JsonObject responseJson = (JsonObject) new JsonParser().parse(result.toString());
|
||||
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
spring.profiles.active=ngrok
|
||||
|
||||
server.port: 5000
|
||||
server.address: 0.0.0.0
|
||||
server.ssl.enabled: false
|
||||
openvidu.recording.version: 2.7.0
|
||||
|
||||
kms.uris=[\"ws://localhost:8888/kurento\"]
|
||||
openvidu.secret: MY_SECRET
|
||||
openvidu.publicurl: ngrok
|
||||
openvidu.cdr: false
|
||||
openvidu.recording: false
|
||||
openvidu.recording.path: /opt/openvidu/recordings
|
||||
openvidu.recording.public-access: false
|
Loading…
Reference in New Issue