openvidu-ipcameras: create new Session if not exists in OpenVidu Server
This commit is contained in:
parent
1af250954f
commit
e0496943fa
@ -44,7 +44,8 @@ public class MyRestController {
|
||||
private final SimpleHttpClient httpClient = new SimpleHttpClient();
|
||||
|
||||
@RequestMapping(value = "/")
|
||||
public String subscribe(@RequestParam(name = "credentials", required = false) String credentials, Model model) {
|
||||
public String subscribe(@RequestParam(name = "credentials", required = false) String credentials, Model model)
|
||||
throws OpenViduJavaClientException, OpenViduHttpException {
|
||||
|
||||
if (credentials == null) {
|
||||
return "index";
|
||||
@ -70,7 +71,17 @@ public class MyRestController {
|
||||
String token = null;
|
||||
try {
|
||||
token = this.session.generateToken();
|
||||
} catch (OpenViduJavaClientException | OpenViduHttpException e) {
|
||||
} catch (OpenViduHttpException e) {
|
||||
if (e.getStatus() == 404) {
|
||||
// Session was closed in openvidu-server. Create it again
|
||||
createOpenViduSession();
|
||||
publishCameras();
|
||||
token = this.session.generateToken();
|
||||
} else {
|
||||
return generateError(model,
|
||||
"Error creating OpenVidu token for session " + SESSION_ID + ": " + e.getMessage());
|
||||
}
|
||||
} catch (OpenViduJavaClientException e) {
|
||||
return generateError(model,
|
||||
"Error creating OpenVidu token for session " + SESSION_ID + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
@ -22,10 +22,11 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.TrustStrategy;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* Simple HTTP client able to send REST API requests to insecure servers
|
||||
* (self-signed certificates are accepted). It only implements a single method
|
||||
@ -71,11 +72,11 @@ public class SimpleHttpClient {
|
||||
|
||||
HttpPost request = new HttpPost(App.OPENVIDU_URL + "api/sessions/" + sessionId + "/connection");
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("rtspUri", rtspUri);
|
||||
json.put("data", cameraName);
|
||||
json.put("adaptativeBitrate", adaptativeBitrate);
|
||||
json.put("onlyPlayWithSubscribers", onlyPlayWhenSubscribers);
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("rtspUri", rtspUri);
|
||||
json.addProperty("data", cameraName);
|
||||
json.addProperty("adaptativeBitrate", adaptativeBitrate);
|
||||
json.addProperty("onlyPlayWithSubscribers", onlyPlayWhenSubscribers);
|
||||
StringEntity params = new StringEntity(json.toString());
|
||||
|
||||
request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user