mirror of https://github.com/OpenVidu/openvidu.git
OpenVidu maven multimodule project refactoring
parent
16684e8f06
commit
298428e5fa
|
@ -0,0 +1,49 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openvidu</groupId>
|
||||||
|
<artifactId>openvidu</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>openvidu-backend-client</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>client</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,101 @@
|
||||||
|
package org.openvidu.client;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.auth.AuthScope;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.ClientProtocolException;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.openvidu.client.OpenViduException.Code;
|
||||||
|
|
||||||
|
public class OpenVidu {
|
||||||
|
|
||||||
|
private String urlOpenViduServer;
|
||||||
|
private String secret;
|
||||||
|
private HttpClient myHttpClient;
|
||||||
|
|
||||||
|
public OpenVidu(String urlOpenViduServer, String secret) {
|
||||||
|
|
||||||
|
this.urlOpenViduServer = urlOpenViduServer;
|
||||||
|
|
||||||
|
if (!this.urlOpenViduServer.endsWith("/")){
|
||||||
|
this.urlOpenViduServer += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.secret = secret;
|
||||||
|
|
||||||
|
CredentialsProvider provider = new BasicCredentialsProvider();
|
||||||
|
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("OPENVIDUAPP", this.secret);
|
||||||
|
provider.setCredentials(AuthScope.ANY, credentials);
|
||||||
|
|
||||||
|
SSLContextBuilder builder = new SSLContextBuilder();
|
||||||
|
try {
|
||||||
|
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
|
||||||
|
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),
|
||||||
|
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
/*SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
||||||
|
builder.build());*/
|
||||||
|
this.myHttpClient = HttpClients.custom().setSSLSocketFactory(
|
||||||
|
sslsf).setDefaultCredentialsProvider(provider).build();
|
||||||
|
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createSession() throws OpenViduException, ClientProtocolException, IOException {
|
||||||
|
|
||||||
|
HttpResponse response = myHttpClient.execute(new HttpGet(this.urlOpenViduServer + "getSessionId"));
|
||||||
|
|
||||||
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
if ((statusCode == org.apache.http.HttpStatus.SC_OK) && (response.getEntity().getContentLength() > 0)){
|
||||||
|
System.out.println("Returning a SESSIONID");
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||||
|
String sessionId = br.readLine();
|
||||||
|
|
||||||
|
return sessionId;
|
||||||
|
} else {
|
||||||
|
throw new OpenViduException(Code.TRANSPORT_REQUEST_ERROR_CODE, "Unable to generate a sessionID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateToken(String sessionId, String role) throws OpenViduException, ClientProtocolException, IOException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put(0, sessionId);
|
||||||
|
json.put(1, role);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(this.urlOpenViduServer + "newToken");
|
||||||
|
StringEntity params = new StringEntity(json.toString());
|
||||||
|
request.addHeader("content-type", "application/json");
|
||||||
|
request.setEntity(params);
|
||||||
|
|
||||||
|
HttpResponse response = myHttpClient.execute(request);
|
||||||
|
|
||||||
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
if ((statusCode == org.apache.http.HttpStatus.SC_OK) && (response.getEntity().getContentLength() > 0)){
|
||||||
|
System.out.println("Returning a TOKEN");
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||||
|
String token = br.readLine();
|
||||||
|
|
||||||
|
return token;
|
||||||
|
} else {
|
||||||
|
throw new OpenViduException(Code.TRANSPORT_REQUEST_ERROR_CODE, "Unable to generate a token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2015 Kurento (http://kurento.org/)
|
||||||
|
*
|
||||||
|
* 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 org.openvidu.client;
|
||||||
|
|
||||||
|
public class OpenViduException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static enum Code {
|
||||||
|
GENERIC_ERROR_CODE(999),
|
||||||
|
|
||||||
|
TRANSPORT_ERROR_CODE(803), TRANSPORT_RESPONSE_ERROR_CODE(802), TRANSPORT_REQUEST_ERROR_CODE(
|
||||||
|
801),
|
||||||
|
|
||||||
|
MEDIA_MUTE_ERROR_CODE(307), MEDIA_NOT_A_WEB_ENDPOINT_ERROR_CODE(
|
||||||
|
306), MEDIA_RTP_ENDPOINT_ERROR_CODE(305), MEDIA_WEBRTC_ENDPOINT_ERROR_CODE(
|
||||||
|
304), MEDIA_ENDPOINT_ERROR_CODE(
|
||||||
|
303), MEDIA_SDP_ERROR_CODE(302), MEDIA_GENERIC_ERROR_CODE(301),
|
||||||
|
|
||||||
|
ROOM_CANNOT_BE_CREATED_ERROR_CODE(204), ROOM_CLOSED_ERROR_CODE(203), ROOM_NOT_FOUND_ERROR_CODE(
|
||||||
|
202), ROOM_GENERIC_ERROR_CODE(201),
|
||||||
|
|
||||||
|
USER_NOT_STREAMING_ERROR_CODE(105), EXISTING_USER_IN_ROOM_ERROR_CODE(
|
||||||
|
104), USER_CLOSED_ERROR_CODE(
|
||||||
|
103), USER_NOT_FOUND_ERROR_CODE(102), USER_GENERIC_ERROR_CODE(101),
|
||||||
|
|
||||||
|
USER_UNAUTHORIZED(401);
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
private Code(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Code code = Code.GENERIC_ERROR_CODE;
|
||||||
|
|
||||||
|
public OpenViduException(Code code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Code getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCodeValue() {
|
||||||
|
return code.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Code: " + getCodeValue() + " " + super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.openvidu.client;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class OpenViduTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName name of the test case
|
||||||
|
*/
|
||||||
|
public OpenViduTest( String testName )
|
||||||
|
{
|
||||||
|
super( testName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
return new TestSuite( OpenViduTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rigourous Test :-)
|
||||||
|
*/
|
||||||
|
public void testApp()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
"wolfy87-eventemitter": "4.2.9",
|
"wolfy87-eventemitter": "4.2.9",
|
||||||
"@types/wolfy87-eventemitter": "4.2.31",
|
"@types/wolfy87-eventemitter": "4.2.31",
|
||||||
"webrtc-adapter": "3.2.0",
|
"webrtc-adapter": "3.2.0",
|
||||||
"kurento-utils": "6.6.0",
|
"kurento-utils": "6.6.1",
|
||||||
"uuid": "~2.0.1",
|
"uuid": "~2.0.1",
|
||||||
"sdp-translator": "^0.1.15"
|
"sdp-translator": "^0.1.15"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
## files generated by popular Visual Studio add-ons.
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
backend/openvidu-sample-app/target/*
|
target/*
|
||||||
backend/openvidu-sample-app/src/main/resources/static/*
|
src/main/resources/static/*
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.suo
|
*.suo
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
cd frontend
|
|
||||||
ng build --output-path ./../backend/openvidu-sample-app/src/main/resources/static
|
|
||||||
cd ../backend/openvidu-sample-app
|
|
||||||
mvn clean package
|
|
||||||
java -jar target/openvidu-sample-app-0.0.1-SNAPSHOT.war
|
|
|
@ -1 +0,0 @@
|
||||||
/target/
|
|
|
@ -26,12 +26,21 @@
|
||||||
|
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>frontend/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<!-- ONLY ON DEVELOPMENT -->
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
@ -39,7 +48,6 @@
|
||||||
<version>1.2.6.RELEASE</version>
|
<version>1.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<!-- ONLY ON DEVELOPMENT -->
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -60,6 +68,7 @@
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
</webResources>
|
</webResources>
|
||||||
|
<packagingExcludes>src/main/resources/frontend/**</packagingExcludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
@ -118,9 +127,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>4.5</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openvidu</groupId>
|
||||||
|
<artifactId>openvidu-backend-client</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -1,29 +1,14 @@
|
||||||
package openvidu.openvidu_sample_app.session_manager;
|
package openvidu.openvidu_sample_app.session_manager;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.KeyStoreException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.auth.AuthScope;
|
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
||||||
import org.apache.http.client.CredentialsProvider;
|
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
||||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
|
||||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.openvidu.client.OpenVidu;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -41,6 +26,8 @@ import openvidu.openvidu_sample_app.user.UserComponent;
|
||||||
@RequestMapping("/api-sessions")
|
@RequestMapping("/api-sessions")
|
||||||
public class SessionController {
|
public class SessionController {
|
||||||
|
|
||||||
|
OpenVidu openVidu;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LessonRepository lessonRepository;
|
private LessonRepository lessonRepository;
|
||||||
|
|
||||||
|
@ -50,31 +37,17 @@ public class SessionController {
|
||||||
private Map<Long, String> lessonIdSessionId = new ConcurrentHashMap<>();
|
private Map<Long, String> lessonIdSessionId = new ConcurrentHashMap<>();
|
||||||
private Map<String, Map<Long, String>> sessionIdUserIdToken = new ConcurrentHashMap<>();
|
private Map<String, Map<Long, String>> sessionIdUserIdToken = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final String OPENVIDU_URL = "https://localhost:8443/";
|
|
||||||
private final String SECRET ="MY_SECRET";
|
|
||||||
private HttpClient myHttpClient;
|
private HttpClient myHttpClient;
|
||||||
|
|
||||||
public SessionController() {
|
private final String OPENVIDU_URL = "https://localhost:8443/";
|
||||||
try {
|
private final String SECRET ="MY_SECRET";
|
||||||
CredentialsProvider provider = new BasicCredentialsProvider();
|
|
||||||
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("OPENVIDUAPP", SECRET);
|
|
||||||
provider.setCredentials(AuthScope.ANY, credentials);
|
|
||||||
|
|
||||||
SSLContextBuilder builder = new SSLContextBuilder();
|
public SessionController(){
|
||||||
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
|
this.openVidu = new OpenVidu(OPENVIDU_URL, SECRET);
|
||||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),
|
|
||||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
|
||||||
/*SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
|
||||||
builder.build());*/
|
|
||||||
this.myHttpClient = HttpClients.custom().setSSLSocketFactory(
|
|
||||||
sslsf).setDefaultCredentialsProvider(provider).build();
|
|
||||||
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/create-session", method = RequestMethod.POST)
|
@RequestMapping(value = "/create-session", method = RequestMethod.POST)
|
||||||
public ResponseEntity<String> createSession(@RequestBody String lessonId) throws Exception {
|
public ResponseEntity<String> createSession(@RequestBody String lessonId) {
|
||||||
|
|
||||||
if (!this.userIsLogged()) {
|
if (!this.userIsLogged()) {
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
|
@ -98,31 +71,20 @@ public class SessionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.lessonIdSessionId.get(id_lesson) != null) {
|
if(this.lessonIdSessionId.get(id_lesson) != null) {
|
||||||
|
|
||||||
// If there's already a valid sessionId for this lesson, not necessary to ask for a new one
|
// If there's already a valid sessionId for this lesson, not necessary to ask for a new one
|
||||||
return new ResponseEntity<>(this.lessonIdSessionId.get(id_lesson), HttpStatus.OK);
|
return new ResponseEntity<>(this.lessonIdSessionId.get(id_lesson), HttpStatus.OK);
|
||||||
|
}
|
||||||
} else {
|
else {
|
||||||
|
try {
|
||||||
/*
|
|
||||||
String sessionId = this.openVidu.createSession();
|
String sessionId = this.openVidu.createSession();
|
||||||
*/
|
|
||||||
|
|
||||||
HttpResponse response = myHttpClient.execute(new HttpGet(OPENVIDU_URL + "getSessionId"));
|
|
||||||
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
|
||||||
if ((statusCode == org.apache.http.HttpStatus.SC_OK) && (response.getEntity().getContentLength() > 0)){
|
|
||||||
System.out.println("Returning a sessionId...");
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
||||||
String sessionId = br.readLine();
|
|
||||||
|
|
||||||
this.lessonIdSessionId.put(id_lesson, sessionId);
|
this.lessonIdSessionId.put(id_lesson, sessionId);
|
||||||
this.sessionIdUserIdToken.put(sessionId, new HashMap<>());
|
this.sessionIdUserIdToken.put(sessionId, new HashMap<>());
|
||||||
|
|
||||||
|
showMap();
|
||||||
|
|
||||||
return new ResponseEntity<>(sessionId, HttpStatus.OK);
|
return new ResponseEntity<>(sessionId, HttpStatus.OK);
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
System.out.println("Problems with openvidu-server");
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,46 +106,34 @@ public class SessionController {
|
||||||
Lesson c = lessonRepository.findOne(id_lesson);
|
Lesson c = lessonRepository.findOne(id_lesson);
|
||||||
|
|
||||||
if (!checkAuthorizationUsers(c, c.getAttenders())){
|
if (!checkAuthorizationUsers(c, c.getAttenders())){
|
||||||
|
System.out.println("Not authorizedd");
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lessonIdSessionId.get(id_lesson) == null){
|
if (this.lessonIdSessionId.get(id_lesson) == null){
|
||||||
|
System.out.println("There's no sessionId fot this lesson");
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String sessionId = this.lessonIdSessionId.get(id_lesson);
|
||||||
String role = user.hasRoleTeacher() ? "PUBLISHER" : "SUBSCRIBER";
|
String role = user.hasRoleTeacher() ? "PUBLISHER" : "SUBSCRIBER";
|
||||||
|
|
||||||
/*
|
try {
|
||||||
|
|
||||||
String token = this.openVidu.generateToken(sessionId, role);
|
String token = this.openVidu.generateToken(sessionId, role);
|
||||||
*/
|
this.sessionIdUserIdToken.get(sessionId).put(this.user.getLoggedUser().getId(), token);
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put(0, this.lessonIdSessionId.get(id_lesson));
|
|
||||||
json.put(1, role);
|
|
||||||
|
|
||||||
HttpPost request = new HttpPost(OPENVIDU_URL + "newToken");
|
|
||||||
StringEntity params = new StringEntity(json.toString());
|
|
||||||
request.addHeader("content-type", "application/json");
|
|
||||||
request.setEntity(params);
|
|
||||||
|
|
||||||
HttpResponse response = myHttpClient.execute(request);
|
|
||||||
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
|
||||||
if ((statusCode == org.apache.http.HttpStatus.SC_OK) && (response.getEntity().getContentLength() > 0)){
|
|
||||||
System.out.println("Returning a sessionId and a token...");
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
||||||
String token = br.readLine();
|
|
||||||
|
|
||||||
this.sessionIdUserIdToken.get(this.lessonIdSessionId.get(id_lesson)).put(this.user.getLoggedUser().getId(), token);
|
|
||||||
|
|
||||||
JSONObject responseJson = new JSONObject();
|
JSONObject responseJson = new JSONObject();
|
||||||
responseJson.put(0, this.lessonIdSessionId.get(id_lesson));
|
responseJson.put(0, sessionId);
|
||||||
responseJson.put(1, token);
|
responseJson.put(1, token);
|
||||||
|
|
||||||
|
showMap();
|
||||||
|
|
||||||
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
System.out.println("Problems with openvidu-server");
|
JSONParser parser = new JSONParser();
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
JSONObject json = (JSONObject) parser.parse(e.getMessage());
|
||||||
|
return new ResponseEntity<>(json, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +170,9 @@ public class SessionController {
|
||||||
this.lessonIdSessionId.remove(id_lesson);
|
this.lessonIdSessionId.remove(id_lesson);
|
||||||
this.sessionIdUserIdToken.remove(sessionId);
|
this.sessionIdUserIdToken.remove(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showMap();
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Problems in the app server: the user didn't have a valid token");
|
System.out.println("Problems in the app server: the user didn't have a valid token");
|
||||||
|
@ -228,6 +181,14 @@ public class SessionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showMap(){
|
||||||
|
System.out.println("------------------------------");
|
||||||
|
System.out.println(this.lessonIdSessionId.toString());
|
||||||
|
System.out.println(this.sessionIdUserIdToken.toString());
|
||||||
|
System.out.println("------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean userIsLogged(){
|
private boolean userIsLogged(){
|
||||||
if (!user.isLoggedUser()) {
|
if (!user.isLoggedUser()) {
|
||||||
System.out.println("Not user logged");
|
System.out.println("Not user logged");
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
cd frontend
|
||||||
|
ng build --output-path ../static
|
||||||
|
cd ../../../../
|
||||||
|
mvn clean package
|
||||||
|
java -jar target/openvidu-sample-app-0.0.1-SNAPSHOT.war
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
@ -164,6 +164,8 @@ public class RoomManager {
|
||||||
|
|
||||||
this.sessionIdTokenRole.get(roomName).remove(participant.getName());
|
this.sessionIdTokenRole.get(roomName).remove(participant.getName());
|
||||||
|
|
||||||
|
showMap();
|
||||||
|
|
||||||
Set<UserParticipant> remainingParticipants = null;
|
Set<UserParticipant> remainingParticipants = null;
|
||||||
try {
|
try {
|
||||||
remainingParticipants = getParticipants(roomName);
|
remainingParticipants = getParticipants(roomName);
|
||||||
|
@ -178,6 +180,8 @@ public class RoomManager {
|
||||||
|
|
||||||
sessionIdTokenRole.remove(roomName);
|
sessionIdTokenRole.remove(roomName);
|
||||||
|
|
||||||
|
showMap();
|
||||||
|
|
||||||
log.warn("Room '{}' removed and closed", roomName);
|
log.warn("Room '{}' removed and closed", roomName);
|
||||||
}
|
}
|
||||||
return remainingParticipants;
|
return remainingParticipants;
|
||||||
|
@ -927,7 +931,11 @@ public class RoomManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void showMap(){
|
||||||
|
System.out.println("------------------------------");
|
||||||
|
System.out.println(this.sessionIdTokenRole.toString());
|
||||||
|
System.out.println("------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
public String getRoomNameFromParticipantId(String pid){
|
public String getRoomNameFromParticipantId(String pid){
|
||||||
return getParticipant(pid).getRoom().getName();
|
return getParticipant(pid).getRoom().getName();
|
||||||
|
@ -946,7 +954,7 @@ public class RoomManager {
|
||||||
|
|
||||||
this.sessionIdTokenRole.put(sessionId, new ConcurrentHashMap<>());
|
this.sessionIdTokenRole.put(sessionId, new ConcurrentHashMap<>());
|
||||||
|
|
||||||
System.out.println(this.sessionIdTokenRole.toString());
|
showMap();
|
||||||
|
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
@ -957,7 +965,7 @@ public class RoomManager {
|
||||||
|
|
||||||
this.sessionIdTokenRole.get(sessionId).put(token, role);
|
this.sessionIdTokenRole.get(sessionId).put(token, role);
|
||||||
|
|
||||||
System.out.println(this.sessionIdTokenRole.toString());
|
showMap();
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,7 +67,6 @@ public class RoomController {
|
||||||
|
|
||||||
@RequestMapping(value = "/newToken", method = RequestMethod.POST)
|
@RequestMapping(value = "/newToken", method = RequestMethod.POST)
|
||||||
public ResponseEntity<String> getToken(@RequestBody Map sessionIdAndRole) {
|
public ResponseEntity<String> getToken(@RequestBody Map sessionIdAndRole) {
|
||||||
System.out.println("SESSIONID: " + sessionIdAndRole.get("0") + " - ROLE: " + sessionIdAndRole.get("1"));
|
|
||||||
String token = roomManager.newToken((String) sessionIdAndRole.get("0"), ParticipantRole.valueOf((String) sessionIdAndRole.get("1")));
|
String token = roomManager.newToken((String) sessionIdAndRole.get("0"), ParticipantRole.valueOf((String) sessionIdAndRole.get("1")));
|
||||||
return new ResponseEntity<String>(token, HttpStatus.OK);
|
return new ResponseEntity<String>(token, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class JsonRpcUserControl {
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: user is not a publisher");
|
System.out.println("Error: user is not a publisher");
|
||||||
throw new OpenViduException(Code.USER_UNAUTHORIZED,
|
throw new OpenViduException(Code.USER_UNAUTHORIZED,
|
||||||
"Unable to join room. The user does not have a valid token");
|
"Unable to publish video. The user does not have a valid token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -74,6 +74,8 @@
|
||||||
<module>openvidu-test</module>
|
<module>openvidu-test</module>
|
||||||
<module>openvidu-demo</module>
|
<module>openvidu-demo</module>
|
||||||
<module>openvidu-testapp</module>
|
<module>openvidu-testapp</module>
|
||||||
|
<module>openvidu-sample-app</module>
|
||||||
|
<module>openvidu-backend-client</module>
|
||||||
</modules>
|
</modules>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
|
|
Loading…
Reference in New Issue