mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: add webhook properties to GET /config endpoint
parent
690900a45b
commit
921b7c1ea8
|
@ -147,22 +147,21 @@ public class OpenviduConfig {
|
|||
if (this.isWebhookEnabled()) {
|
||||
log.info("OpenVidu Webhook service enabled");
|
||||
try {
|
||||
new URL(this.openviduWebhookEndpoint);
|
||||
log.info("OpenVidu Webhook endpoint is {}", this.getOpenViduWebhookEndpoint());
|
||||
} catch (MalformedURLException e) {
|
||||
log.error("Error in 'openvidu.webhook.endpoint' system property. Malformed URL: " + e.getMessage());
|
||||
this.initiateOpenViduWebhookEndpoint(this.openviduWebhookEndpoint);
|
||||
} catch (Exception e) {
|
||||
log.error("Error in 'openvidu.webhook.endpoint' system property. " + e.getMessage());
|
||||
log.error("Shutting down OpenVidu Server");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
this.initiateOpenViduWebhookHeaders();
|
||||
this.initiateOpenViduWebhookHeaders(this.openviduWebhookHeaders);
|
||||
} catch (Exception e) {
|
||||
log.error("Error in 'openvidu.webhook.headers' system property: " + e.getMessage());
|
||||
log.error("Shutting down OpenVidu Server");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
this.initiateOpenViduWebhookEvents();
|
||||
this.initiateOpenViduWebhookEvents(this.openviduWebhookEvents);
|
||||
} catch (Exception e) {
|
||||
log.error("Error in 'openvidu.webhook.events' system property: " + e.getMessage());
|
||||
log.error("Shutting down OpenVidu Server");
|
||||
|
@ -343,10 +342,19 @@ public class OpenviduConfig {
|
|||
}
|
||||
}
|
||||
|
||||
private void initiateOpenViduWebhookHeaders() throws Exception {
|
||||
public void initiateOpenViduWebhookEndpoint(String endpoint) throws Exception {
|
||||
try {
|
||||
new URL(endpoint);
|
||||
log.info("OpenVidu Webhook endpoint is {}", endpoint);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new Exception("Webhook endpoint '" + endpoint + "' is not correct. Malformed URL: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void initiateOpenViduWebhookHeaders(String headers) throws Exception {
|
||||
if (webhookHeadersList == null) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement elem = parser.parse(this.openviduWebhookHeaders);
|
||||
JsonElement elem = parser.parse(headers);
|
||||
JsonArray headersJsonArray = elem.getAsJsonArray();
|
||||
this.webhookHeadersList = new ArrayList<>();
|
||||
|
||||
|
@ -365,10 +373,10 @@ public class OpenviduConfig {
|
|||
}
|
||||
}
|
||||
|
||||
private void initiateOpenViduWebhookEvents() throws Exception {
|
||||
public void initiateOpenViduWebhookEvents(String events) throws Exception {
|
||||
if (webhookEventsList == null) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement elem = parser.parse(this.openviduWebhookEvents);
|
||||
JsonElement elem = parser.parse(events);
|
||||
JsonArray eventsJsonArray = elem.getAsJsonArray();
|
||||
this.webhookEventsList = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package io.openvidu.server.rest;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -29,8 +30,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.openvidu.server.cdr.CDREventName;
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
|
||||
/**
|
||||
|
@ -109,6 +112,20 @@ public class ConfigRestController {
|
|||
json.addProperty("openviduRecordingCustomLayout", openviduConfig.getOpenviduRecordingCustomLayout());
|
||||
json.addProperty("openviduRecordingAutostopTimeout", openviduConfig.getOpenviduRecordingAutostopTimeout());
|
||||
}
|
||||
json.addProperty("openviduWebhook", openviduConfig.isWebhookEnabled());
|
||||
if (openviduConfig.isWebhookEnabled()) {
|
||||
json.addProperty("openviduWebhookEndpoint", openviduConfig.getOpenViduWebhookEndpoint());
|
||||
JsonArray webhookHeaders = new JsonArray();
|
||||
for (Header header : openviduConfig.getOpenViduWebhookHeaders()) {
|
||||
webhookHeaders.add(header.getName() + ": " + header.getValue());
|
||||
}
|
||||
json.add("openviduWebhookHeaders", webhookHeaders);
|
||||
JsonArray webhookEvents = new JsonArray();
|
||||
for (CDREventName eventName : openviduConfig.getOpenViduWebhookEvents()) {
|
||||
webhookEvents.add(eventName.name());
|
||||
}
|
||||
json.add("openviduWebhookEvents", webhookEvents);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(json.toString(), getResponseHeaders(), HttpStatus.OK);
|
||||
}
|
||||
|
|
|
@ -2833,7 +2833,6 @@ public class OpenViduTestAppE2eTest {
|
|||
} finally {
|
||||
CustomWebhook.shutDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void listEmptyRecordings() {
|
||||
|
|
Loading…
Reference in New Issue