Updated tutorials with new OpenVidu API
WIP: Test the tutorials which use Java or Node client
This commit is contained in:
parent
9e3b0265e6
commit
e5166450d0
@ -137,15 +137,15 @@ public class SessionActivity extends AppCompatActivity {
|
||||
try {
|
||||
// Session Request
|
||||
RequestBody sessionBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"customSessionId\": \"" + sessionId + "\"}");
|
||||
this.httpClient.httpCall("/api/sessions", "POST", "application/json", sessionBody, new Callback() {
|
||||
this.httpClient.httpCall("/openvidu/api/sessions", "POST", "application/json", sessionBody, new Callback() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
||||
Log.d(TAG, "responseString: " + response.body().string());
|
||||
|
||||
// Token Request
|
||||
RequestBody tokenBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"session\": \"" + sessionId + "\"}");
|
||||
httpClient.httpCall("/api/tokens", "POST", "application/json", tokenBody, new Callback() {
|
||||
RequestBody tokenBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{}");
|
||||
httpClient.httpCall("/openvidu/api/sessions/" + sessionId + "/connection", "POST", "application/json", tokenBody, new Callback() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||
|
||||
@ -82,7 +82,8 @@ public class CustomHttpClient {
|
||||
url = url.startsWith("/") ? url.substring(1) : url;
|
||||
Request request = new Request.Builder()
|
||||
.url(this.baseUrl + url)
|
||||
.header("Authorization", this.basicAuth).header("Content-Type", contentType).method(method, body)
|
||||
.header("Authorization", this.basicAuth).header("Content-Type", contentType)
|
||||
.method(method, body)
|
||||
.build();
|
||||
Call call = client.newCall(request);
|
||||
call.enqueue(callback);
|
||||
|
||||
@ -91,9 +91,9 @@ function openScreenShareModal() {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://localhost:4443";
|
||||
@ -103,10 +103,10 @@ function getToken(mySessionId) {
|
||||
return createSession(mySessionId).then(sessionId => createToken(sessionId));
|
||||
}
|
||||
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(
|
||||
OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
JSON.stringify({
|
||||
customSessionId: sessionId
|
||||
}), {
|
||||
@ -138,13 +138,11 @@ function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/re
|
||||
});
|
||||
}
|
||||
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(
|
||||
OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
JSON.stringify({
|
||||
session: sessionId
|
||||
}), {
|
||||
OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
{
|
||||
headers: {
|
||||
'Authorization': "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@ -91,7 +91,7 @@ function joinSession() {
|
||||
publishVideo: true, // Whether you want to start publishing with your video enabled or not
|
||||
resolution: '1280x720', // The resolution of your video
|
||||
frameRate: 30, // The frame rate of your video
|
||||
insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
|
||||
insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
|
||||
mirror: false // Whether to mirror your local video or not
|
||||
};
|
||||
|
||||
@ -161,7 +161,7 @@ function leaveSession() {
|
||||
|
||||
session.disconnect();
|
||||
|
||||
// Removing all HTML elements with user's nicknames.
|
||||
// Removing all HTML elements with user's nicknames.
|
||||
// HTML videos are automatically removed when leaving a Session
|
||||
removeAllUserData();
|
||||
|
||||
@ -369,9 +369,9 @@ function initMainVideo(streamManager, userData) {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the REST API, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
|
||||
@ -382,11 +382,11 @@ function getToken(mySessionId, role) {
|
||||
}
|
||||
|
||||
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sessionId }),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
@ -409,10 +409,9 @@ function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/re
|
||||
}
|
||||
|
||||
|
||||
function createToken(sessionId, role) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId, role) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
var openviduRole;
|
||||
var jsonBody = {
|
||||
session: sessionId,
|
||||
role: role,
|
||||
kurentoOptions: {}
|
||||
};
|
||||
@ -427,7 +426,7 @@ function createToken(sessionId, role) { // See https://docs.openvidu.io/en/stabl
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
data: JSON.stringify(jsonBody),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
|
||||
@ -173,7 +173,7 @@ function showSessionHideJoin() {
|
||||
$('#main-container').removeClass('container');
|
||||
}
|
||||
|
||||
// 'Join' page
|
||||
// 'Join' page
|
||||
function showJoinHideSession() {
|
||||
$('#nav-join').show();
|
||||
$('#nav-session').hide();
|
||||
@ -261,9 +261,9 @@ function updateLayout() {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
|
||||
@ -273,12 +273,12 @@ function getToken(mySessionId) {
|
||||
return createSession(mySessionId).then(sId => createToken(sId));
|
||||
}
|
||||
|
||||
function createSession(sId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sId }),
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sessionId }),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
"Content-Type": "application/json"
|
||||
@ -286,7 +286,7 @@ function createSession(sId) { // See https://docs.openvidu.io/en/stable/referenc
|
||||
success: response => resolve(response.id),
|
||||
error: (error) => {
|
||||
if (error.status === 409) {
|
||||
resolve(sId);
|
||||
resolve(sessionId);
|
||||
} else {
|
||||
console.warn('No connection to OpenVidu Server. This may be a certificate error at ' + OPENVIDU_SERVER_URL);
|
||||
if (window.confirm('No connection to OpenVidu Server. This may be a certificate error at \"' + OPENVIDU_SERVER_URL + '\"\n\nClick OK to navigate and accept it. ' +
|
||||
@ -299,12 +299,12 @@ function createSession(sId) { // See https://docs.openvidu.io/en/stable/referenc
|
||||
});
|
||||
}
|
||||
|
||||
function createToken(sId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
data: JSON.stringify({ session: sId }),
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
data: JSON.stringify({}),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -48,9 +48,9 @@ window.onbeforeunload = function () {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
|
||||
@ -60,11 +60,11 @@ function getToken(mySessionId) {
|
||||
return createSession(mySessionId).then(sessionId => createToken(sessionId));
|
||||
}
|
||||
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sessionId }),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
@ -86,12 +86,12 @@ function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/re
|
||||
});
|
||||
}
|
||||
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
data: JSON.stringify({ session: sessionId }),
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
data: JSON.stringify({}),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -153,9 +153,9 @@ export class AppComponent implements OnDestroy {
|
||||
* This method retrieve the mandatory user token from OpenVidu Server,
|
||||
* in this case making use Angular http API.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION. In this case:
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method of OpenVidu Browser
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken(): Promise<string> {
|
||||
@ -175,7 +175,7 @@ export class AppComponent implements OnDestroy {
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.httpClient.post(this.OPENVIDU_SERVER_URL + '/api/sessions', body, options)
|
||||
return this.httpClient.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions', body, options)
|
||||
.pipe(
|
||||
catchError(error => {
|
||||
if (error.status === 409) {
|
||||
@ -201,14 +201,14 @@ export class AppComponent implements OnDestroy {
|
||||
createToken(sessionId): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const body = JSON.stringify({ session: sessionId });
|
||||
const body = {};
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
'Authorization': 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.httpClient.post(this.OPENVIDU_SERVER_URL + '/api/tokens', body, options)
|
||||
return this.httpClient.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
.pipe(
|
||||
catchError(error => {
|
||||
reject(error);
|
||||
|
||||
@ -181,9 +181,9 @@ function initMainVideo(videoElement, userData) {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
|
||||
@ -193,11 +193,11 @@ function getToken(mySessionId) {
|
||||
return createSession(mySessionId).then(sessionId => createToken(sessionId));
|
||||
}
|
||||
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sessionId }),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
@ -219,12 +219,11 @@ function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/re
|
||||
});
|
||||
}
|
||||
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
data: JSON.stringify({ session: sessionId }),
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -266,9 +266,9 @@ class App extends Component {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken() {
|
||||
@ -279,7 +279,7 @@ class App extends Component {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = JSON.stringify({ customSessionId: sessionId });
|
||||
axios
|
||||
.post(OPENVIDU_SERVER_URL + '/api/sessions', data, {
|
||||
.post(OPENVIDU_SERVER_URL + '/openvidu/api/sessions', data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
@ -318,9 +318,9 @@ class App extends Component {
|
||||
|
||||
createToken(sessionId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = JSON.stringify({ session: sessionId });
|
||||
var data = {};
|
||||
axios
|
||||
.post(OPENVIDU_SERVER_URL + '/api/tokens', data, {
|
||||
.post(OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection", data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@ -151,20 +151,20 @@ export default {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken (mySessionId) {
|
||||
return this.createSession(mySessionId).then(sessionId => this.createToken(sessionId));
|
||||
},
|
||||
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
createSession (sessionId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`${OPENVIDU_SERVER_URL}/api/sessions`, JSON.stringify({
|
||||
.post(`${OPENVIDU_SERVER_URL}/openvidu/api/sessions`, JSON.stringify({
|
||||
customSessionId: sessionId,
|
||||
}), {
|
||||
auth: {
|
||||
@ -188,13 +188,11 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
createToken (sessionId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`${OPENVIDU_SERVER_URL}/api/tokens`, JSON.stringify({
|
||||
session: sessionId,
|
||||
}), {
|
||||
.post(`${OPENVIDU_SERVER_URL}/openvidu/api/sessions/${sessionId}/connection`, {}, {
|
||||
auth: {
|
||||
username: 'OPENVIDUAPP',
|
||||
password: OPENVIDU_SERVER_SECRET,
|
||||
|
||||
@ -69,7 +69,7 @@ function joinSession() {
|
||||
publishVideo: true, // Whether you want to start publishing with your video enabled or not
|
||||
resolution: '640x480', // The resolution of your video
|
||||
frameRate: 30, // The frame rate of your video
|
||||
insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
|
||||
insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
|
||||
mirror: false // Whether to mirror your local video or not
|
||||
});
|
||||
|
||||
@ -105,7 +105,7 @@ function leaveSession() {
|
||||
|
||||
session.disconnect();
|
||||
|
||||
// Removing all HTML elements with user's nicknames.
|
||||
// Removing all HTML elements with user's nicknames.
|
||||
// HTML videos are automatically removed when leaving a Session
|
||||
removeAllUserData();
|
||||
|
||||
@ -206,9 +206,9 @@ function initMainVideo(publisher, userData) {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
|
||||
@ -218,11 +218,11 @@ function getToken(mySessionId) {
|
||||
return createSession(mySessionId).then(function(sessionId) { return createToken(sessionId); });
|
||||
}
|
||||
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise(function(resolve, reject) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/sessions",
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions",
|
||||
data: JSON.stringify({ customSessionId: sessionId }),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
@ -244,12 +244,12 @@ function createSession(sessionId) { // See https://docs.openvidu.io/en/stable/re
|
||||
});
|
||||
}
|
||||
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
function createToken(sessionId) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
return new Promise(function(resolve, reject) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: OPENVIDU_SERVER_URL + "/api/tokens",
|
||||
data: JSON.stringify({ session: sessionId }),
|
||||
url: OPENVIDU_SERVER_URL + "/openvidu/api/sessions/" + sessionId + "/connection",
|
||||
data: JSON.stringify({}),
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -283,9 +283,9 @@ export class AppComponent implements OnDestroy {
|
||||
* This method retrieve the mandatory user token from OpenVidu Server,
|
||||
* in this case making use Angular http API.
|
||||
* This behaviour MUST BE IN YOUR SERVER-SIDE IN PRODUCTION. In this case:
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method of OpenVidu Browser
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken(): Promise<string> {
|
||||
@ -308,7 +308,7 @@ export class AppComponent implements OnDestroy {
|
||||
}),
|
||||
};
|
||||
return this.httpClient
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/sessions', body, options)
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
if (error.status === 409) {
|
||||
@ -344,7 +344,7 @@ export class AppComponent implements OnDestroy {
|
||||
|
||||
createToken(sessionId): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({ session: sessionId });
|
||||
const body = JSON.stringify({});
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
||||
@ -352,7 +352,7 @@ export class AppComponent implements OnDestroy {
|
||||
}),
|
||||
};
|
||||
return this.httpClient
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/tokens', body, options)
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
reject(error);
|
||||
|
||||
@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import io.openvidu.java.client.OpenVidu;
|
||||
import io.openvidu.java.client.OpenViduHttpException;
|
||||
import io.openvidu.java.client.OpenViduJavaClientException;
|
||||
import io.openvidu.java.client.OpenViduRole;
|
||||
import io.openvidu.java.client.ConnectionType;
|
||||
import io.openvidu.java.client.Session;
|
||||
import io.openvidu.java.client.SessionProperties;
|
||||
|
||||
@ -69,8 +71,13 @@ public class MyRestController {
|
||||
|
||||
// Generate a token for the user
|
||||
String token = null;
|
||||
ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
|
||||
.type(ConnectionType.WEBRTC)
|
||||
.role(OpenViduRole.PUBLISHER)
|
||||
.data("user_data")
|
||||
.build();
|
||||
try {
|
||||
token = this.session.generateToken();
|
||||
token = this.session.createConnection(connectionProperties).getToken();
|
||||
} catch (OpenViduHttpException e) {
|
||||
if (e.getStatus() == 404) {
|
||||
// Session was closed in openvidu-server. Create it again
|
||||
|
||||
@ -21,7 +21,7 @@ import io.openvidu.java.client.OpenViduHttpException;
|
||||
import io.openvidu.java.client.OpenViduJavaClientException;
|
||||
import io.openvidu.java.client.OpenViduRole;
|
||||
import io.openvidu.java.client.Session;
|
||||
import io.openvidu.java.client.TokenOptions;
|
||||
import io.openvidu.java.client.ConnectionProperties;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api-sessions")
|
||||
@ -71,8 +71,8 @@ public class SessionController {
|
||||
// object on login
|
||||
String serverData = "{\"serverData\": \"" + httpSession.getAttribute("loggedUser") + "\"}";
|
||||
|
||||
// Build tokenOptions object with the serverData and the role
|
||||
TokenOptions tokenOptions = new TokenOptions.Builder().data(serverData).role(role).build();
|
||||
// Build connectionProperties object with the serverData and the role
|
||||
ConnectionProperties connectionProperties = new ConnectionProperties.Builder().type(ConnectionType.WEBRTC).data(serverData).role(role).build();
|
||||
|
||||
JSONObject responseJson = new JSONObject();
|
||||
|
||||
@ -81,8 +81,8 @@ public class SessionController {
|
||||
System.out.println("Existing session " + sessionName);
|
||||
try {
|
||||
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = this.mapSessions.get(sessionName).generateToken(tokenOptions);
|
||||
// Generate a new Connection with the recently created connectionProperties
|
||||
String token = this.mapSessions.get(sessionName).createConnection(connectionProperties).getToken();
|
||||
|
||||
// Update our collection storing the new token
|
||||
this.mapSessionNamesTokens.get(sessionName).put(token, role);
|
||||
@ -111,8 +111,8 @@ public class SessionController {
|
||||
|
||||
// Create a new OpenVidu Session
|
||||
Session session = this.openVidu.createSession();
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = session.generateToken(tokenOptions);
|
||||
// Generate a new Connection with the recently created connectionProperties
|
||||
String token = this.mapSessions.get(sessionName).createConnection(connectionProperties).getToken();
|
||||
|
||||
// Store the session and the token in our collections
|
||||
this.mapSessions.put(sessionName, session);
|
||||
|
||||
@ -86,7 +86,7 @@ app.post('/api-login/login', function (req, res) {
|
||||
console.log("Logging in | {user, pass}={" + user + ", " + pass + "}");
|
||||
|
||||
if (login(user, pass)) { // Correct user-pass
|
||||
// Validate session and return OK
|
||||
// Validate session and return OK
|
||||
// Value stored in req.session allows us to identify the user in future requests
|
||||
console.log("'" + user + "' has logged in");
|
||||
req.session.loggedUser = user;
|
||||
@ -124,8 +124,8 @@ app.post('/api-sessions/get-token', function (req, res) {
|
||||
|
||||
console.log("Getting a token | {sessionName}={" + sessionName + "}");
|
||||
|
||||
// Build tokenOptions object with the serverData and the role
|
||||
var tokenOptions = {
|
||||
// Build connectionProperties object with the serverData and the role
|
||||
var connectionProperties = {
|
||||
data: serverData,
|
||||
role: role
|
||||
};
|
||||
@ -137,16 +137,16 @@ app.post('/api-sessions/get-token', function (req, res) {
|
||||
// Get the existing Session from the collection
|
||||
var mySession = mapSessions[sessionName];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
mySession.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new token asynchronously with the recently created connectionProperties
|
||||
mySession.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return the token to the client
|
||||
res.status(200).send({
|
||||
0: token
|
||||
0: connection.token
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
@ -164,16 +164,16 @@ app.post('/api-sessions/get-token', function (req, res) {
|
||||
// Store a new empty array in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName] = [];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
session.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new connection asynchronously with the recently created connectionProperties
|
||||
session.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return the Token to the client
|
||||
res.status(200).send({
|
||||
0: token
|
||||
0: connection.token
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
@ -88,9 +88,9 @@ export class AppComponent {
|
||||
* This method retrieve the mandatory user token from OpenVidu Server,
|
||||
* in this case making use Angular http API.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION. In this case:
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method of OpenVidu Browser
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken(): Promise<string> {
|
||||
@ -109,7 +109,7 @@ export class AppComponent {
|
||||
}),
|
||||
};
|
||||
return this.httpClient
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/sessions', body, options)
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
if (error.status === 409) {
|
||||
@ -141,7 +141,7 @@ export class AppComponent {
|
||||
|
||||
createToken(sessionId): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({ session: sessionId });
|
||||
const body = JSON.stringify({});
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
||||
@ -149,7 +149,7 @@ export class AppComponent {
|
||||
}),
|
||||
};
|
||||
return this.httpClient
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/tokens', body, options)
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
reject(error);
|
||||
|
||||
@ -122,9 +122,9 @@ class App extends Component {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behaviour MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken() {
|
||||
@ -137,7 +137,7 @@ class App extends Component {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = JSON.stringify({ customSessionId: sessionId });
|
||||
axios
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/sessions', data, {
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions', data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
@ -175,9 +175,9 @@ class App extends Component {
|
||||
|
||||
createToken(sessionId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = JSON.stringify({ session: sessionId });
|
||||
var data = JSON.stringify({});
|
||||
axios
|
||||
.post(this.OPENVIDU_SERVER_URL + '/api/tokens', data, {
|
||||
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import io.openvidu.java.client.OpenVidu;
|
||||
import io.openvidu.java.client.OpenViduRole;
|
||||
import io.openvidu.java.client.Session;
|
||||
import io.openvidu.java.client.TokenOptions;
|
||||
import io.openvidu.java.client.ConnectionProperties;
|
||||
|
||||
@Controller
|
||||
public class SessionController {
|
||||
@ -57,16 +57,20 @@ public class SessionController {
|
||||
// In this case, a JSON with the value we stored in the HttpSession object on login
|
||||
String serverData = "{\"serverData\": \"" + httpSession.getAttribute("loggedUser") + "\"}";
|
||||
|
||||
// Build tokenOptions object with the serverData and the role
|
||||
TokenOptions tokenOptions = new TokenOptions.Builder().data(serverData).role(role).build();
|
||||
// Build connectionProperties object with the serverData and the role
|
||||
ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
|
||||
.type(ConnectionType.WEBRTC)
|
||||
.role(role)
|
||||
.data(serverData)
|
||||
.build();
|
||||
|
||||
if (this.mapSessions.get(sessionName) != null) {
|
||||
// Session already exists
|
||||
System.out.println("Existing session " + sessionName);
|
||||
try {
|
||||
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = this.mapSessions.get(sessionName).generateToken(tokenOptions);
|
||||
// Generate a new token with the recently created connectionProperties
|
||||
String token = this.mapSessions.get(sessionName).createConnection(connectionProperties).getToken();
|
||||
|
||||
// Update our collection storing the new token
|
||||
this.mapSessionNamesTokens.get(sessionName).put(token, role);
|
||||
@ -92,8 +96,8 @@ public class SessionController {
|
||||
|
||||
// Create a new OpenVidu Session
|
||||
Session session = this.openVidu.createSession();
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = session.generateToken(tokenOptions);
|
||||
// Generate a new token with the recently created connectionProperties
|
||||
String token = session.createConnection(connectionProperties).getToken();
|
||||
|
||||
// Store the session and the token in our collections
|
||||
this.mapSessions.put(sessionName, session);
|
||||
|
||||
@ -117,7 +117,7 @@ function dashboardController(req, res) {
|
||||
console.log("Logging in | {user, pass}={" + user + ", " + pass + "}");
|
||||
|
||||
if (login(user, pass)) { // Correct user-pass
|
||||
// Validate session and return OK
|
||||
// Validate session and return OK
|
||||
// Value stored in req.session allows us to identify the user in future requests
|
||||
console.log("'" + user + "' has logged in");
|
||||
req.session.loggedUser = user;
|
||||
@ -152,8 +152,8 @@ app.post('/session', (req, res) => {
|
||||
|
||||
console.log("Getting a token | {sessionName}={" + sessionName + "}");
|
||||
|
||||
// Build tokenOptions object with the serverData and the role
|
||||
var tokenOptions = {
|
||||
// Build connectionProperties object with the serverData and the role
|
||||
var connectionProperties = {
|
||||
data: serverData,
|
||||
role: role
|
||||
};
|
||||
@ -165,17 +165,17 @@ app.post('/session', (req, res) => {
|
||||
// Get the existing Session from the collection
|
||||
var mySession = mapSessions[sessionName];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
mySession.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new token asynchronously with the recently created connectionProperties
|
||||
mySession.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return session template with all the needed attributes
|
||||
res.render('session.ejs', {
|
||||
sessionId: mySession.getSessionId(),
|
||||
token: token,
|
||||
token: connection.token,
|
||||
nickName: clientData,
|
||||
userName: req.session.loggedUser,
|
||||
sessionName: sessionName
|
||||
@ -196,17 +196,17 @@ app.post('/session', (req, res) => {
|
||||
// Store a new empty array in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName] = [];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
session.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new token asynchronously with the recently created connectionProperties
|
||||
session.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return session template with all the needed attributes
|
||||
res.render('session.ejs', {
|
||||
sessionName: sessionName,
|
||||
token: token,
|
||||
token: connection.token,
|
||||
nickName: clientData,
|
||||
userName: req.session.loggedUser,
|
||||
});
|
||||
|
||||
@ -379,9 +379,9 @@ export default class App extends Component<Props> {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) The token must be consumed in Session.connect() method
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
getToken() {
|
||||
@ -394,7 +394,7 @@ export default class App extends Component<Props> {
|
||||
return new Promise((resolve) => {
|
||||
var data = JSON.stringify({ customSessionId: sessionId });
|
||||
axios
|
||||
.post(OPENVIDU_SERVER_URL + '/api/sessions', data, {
|
||||
.post(OPENVIDU_SERVER_URL + '/openvidu/api/sessions', data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
@ -453,9 +453,9 @@ export default class App extends Component<Props> {
|
||||
|
||||
createToken(sessionId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = JSON.stringify({ session: sessionId });
|
||||
var data = JSON.stringify({});
|
||||
axios
|
||||
.post(OPENVIDU_SERVER_URL + '/api/tokens', data, {
|
||||
.post(OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', data, {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@ -21,10 +21,11 @@ import io.openvidu.java.client.OpenVidu;
|
||||
import io.openvidu.java.client.OpenViduHttpException;
|
||||
import io.openvidu.java.client.OpenViduJavaClientException;
|
||||
import io.openvidu.java.client.OpenViduRole;
|
||||
import io.openvidu.java.client.ConnectionType;
|
||||
import io.openvidu.java.client.Recording;
|
||||
import io.openvidu.java.client.RecordingProperties;
|
||||
import io.openvidu.java.client.Session;
|
||||
import io.openvidu.java.client.TokenOptions;
|
||||
import io.openvidu.java.client.ConnectionProperties;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@ -69,8 +70,12 @@ public class MyRestController {
|
||||
// Role associated to this user
|
||||
OpenViduRole role = OpenViduRole.PUBLISHER;
|
||||
|
||||
// Build tokenOptions object with the serverData and the role
|
||||
TokenOptions tokenOptions = new TokenOptions.Builder().role(role).build();
|
||||
// Build connectionProperties object with the serverData and the role
|
||||
ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
|
||||
.type(ConnectionType.WEBRTC)
|
||||
.role(role)
|
||||
.data("user_data")
|
||||
.build();
|
||||
|
||||
JSONObject responseJson = new JSONObject();
|
||||
|
||||
@ -79,8 +84,8 @@ public class MyRestController {
|
||||
System.out.println("Existing session " + sessionName);
|
||||
try {
|
||||
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = this.mapSessions.get(sessionName).generateToken(tokenOptions);
|
||||
// Generate a new token with the recently created connectionProperties
|
||||
String token = this.mapSessions.get(sessionName).createConnection(connectionProperties).getToken();
|
||||
|
||||
// Update our collection storing the new token
|
||||
this.mapSessionNamesTokens.get(sessionName).put(token, role);
|
||||
@ -111,8 +116,8 @@ public class MyRestController {
|
||||
// Create a new OpenVidu Session
|
||||
Session session = this.openVidu.createSession();// new
|
||||
// SessionProperties.Builder().customSessionId("CUSTOMSESSIONID").defaultRecordingLayout(RecordingLayout.CUSTOM).defaultCustomLayout("CUSTOM/LAYOUT").recordingMode(RecordingMode.ALWAYS).build());
|
||||
// Generate a new token with the recently created tokenOptions
|
||||
String token = session.generateToken(tokenOptions);
|
||||
// Generate a new token with the recently created connectionProperties
|
||||
String token = session.createConnection(connectionProperties).getToken();
|
||||
|
||||
// Store the session and the token in our collections
|
||||
this.mapSessions.put(sessionName, session);
|
||||
|
||||
@ -65,8 +65,8 @@ app.post('/api/get-token', function (req, res) {
|
||||
|
||||
console.log("Getting a token | {sessionName}={" + sessionName + "}");
|
||||
|
||||
// Build tokenOptions object with PUBLISHER role
|
||||
var tokenOptions = {
|
||||
// Build connectionProperties object with PUBLISHER role
|
||||
var connectionProperties = {
|
||||
role: role
|
||||
}
|
||||
|
||||
@ -77,16 +77,16 @@ app.post('/api/get-token', function (req, res) {
|
||||
// Get the existing Session from the collection
|
||||
var mySession = mapSessions[sessionName];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
mySession.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new Connection asynchronously with the recently created connectionProperties
|
||||
mySession.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return the token to the client
|
||||
res.status(200).send({
|
||||
0: token
|
||||
0: connection.token
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
@ -94,15 +94,15 @@ app.post('/api/get-token', function (req, res) {
|
||||
if (error.message === "404") {
|
||||
delete mapSessions[sessionName];
|
||||
delete mapSessionNamesTokens[sessionName];
|
||||
newSession(sessionName, tokenOptions, res);
|
||||
newSession(sessionName, connectionProperties, res);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
newSession(sessionName, tokenOptions, res);
|
||||
newSession(sessionName, connectionProperties, res);
|
||||
}
|
||||
});
|
||||
|
||||
function newSession(sessionName, tokenOptions, res) {
|
||||
function newSession(sessionName, connectionProperties, res) {
|
||||
// New session
|
||||
console.log('New session ' + sessionName);
|
||||
|
||||
@ -114,16 +114,16 @@ function newSession(sessionName, tokenOptions, res) {
|
||||
// Store a new empty array in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName] = [];
|
||||
|
||||
// Generate a new token asynchronously with the recently created tokenOptions
|
||||
session.generateToken(tokenOptions)
|
||||
.then(token => {
|
||||
// Generate a new connection asynchronously with the recently created connectionProperties
|
||||
session.createConnection(connectionProperties)
|
||||
.then(connection => {
|
||||
|
||||
// Store the new token in the collection of tokens
|
||||
mapSessionNamesTokens[sessionName].push(token);
|
||||
mapSessionNamesTokens[sessionName].push(connection.token);
|
||||
|
||||
// Return the Token to the client
|
||||
res.status(200).send({
|
||||
0: token
|
||||
0: connection.token
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
@ -81,9 +81,9 @@ async function joinSession() {
|
||||
* These methods retrieve the mandatory user token from OpenVidu Server.
|
||||
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
|
||||
* the API REST, openvidu-java-client or openvidu-node-client):
|
||||
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
|
||||
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
|
||||
* 3) Configure OpenVidu Web Component in your client side with the token
|
||||
* 1) Initialize a session in OpenVidu Server (POST /openvidu/api/sessions)
|
||||
* 2) Generate a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
||||
* 3) The Connection.token must be consumed in Session.connect() method
|
||||
*/
|
||||
|
||||
var OPENVIDU_SERVER_URL = "https://demos.openvidu.io";
|
||||
@ -93,11 +93,11 @@ function getToken(sessionName) {
|
||||
return createSession(sessionName).then((sessionId) => createToken(sessionId));
|
||||
}
|
||||
|
||||
function createSession(sessionName) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
|
||||
function createSession(sessionName) { // See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessions
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: OPENVIDU_SERVER_URL + '/api/sessions',
|
||||
url: OPENVIDU_SERVER_URL + '/openvidu/api/sessions',
|
||||
data: JSON.stringify({ customSessionId: sessionName }),
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
@ -128,11 +128,11 @@ function createSession(sessionName) { // See https://docs.openvidu.io/en/stable/
|
||||
}
|
||||
|
||||
function createToken(sessionId) {
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
|
||||
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-openviduapisessionsltsession_idgtconnection
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: OPENVIDU_SERVER_URL + '/api/tokens',
|
||||
url: OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection',
|
||||
data: JSON.stringify({ session: sessionId }),
|
||||
headers: {
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SERVER_SECRET),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user