From e5166450d0868d1cfe72dd7a7900a22e4ca2a44a Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Tue, 10 Nov 2020 17:08:18 +0100 Subject: [PATCH] Updated tutorials with new OpenVidu API WIP: Test the tutorials which use Java or Node client --- .../activities/SessionActivity.java | 6 ++-- .../utils/CustomHttpClient.java | 3 +- openvidu-electron/src/app.js | 18 +++++------ openvidu-filters/web/app.js | 19 ++++++------ openvidu-getaroom/web/app.js | 22 +++++++------- openvidu-hello-world/web/app.js | 16 +++++----- .../src/app/app.component.ts | 12 ++++---- openvidu-insecure-js/web/app.js | 15 +++++----- openvidu-insecure-react/src/App.js | 12 ++++---- openvidu-insecure-vue/src/App.vue | 16 +++++----- openvidu-internet-explorer/web/app.js | 20 ++++++------- openvidu-ionic/src/app/app.component.ts | 12 ++++---- .../openvidu/ipcameras/MyRestController.java | 9 +++++- .../openvidu/js/java/SessionController.java | 14 ++++----- openvidu-js-node/server.js | 26 ++++++++-------- .../src/app/app.component.ts | 12 ++++---- openvidu-library-react/src/App.js | 12 ++++---- .../openvidu/mvc/java/SessionController.java | 18 ++++++----- openvidu-mvc-node/server.js | 26 ++++++++-------- openvidu-react-native/App.js | 12 ++++---- .../recording/java/MyRestController.java | 19 +++++++----- openvidu-recording-node/server.js | 30 +++++++++---------- openvidu-webcomponent/web/app.js | 14 ++++----- 23 files changed, 187 insertions(+), 176 deletions(-) diff --git a/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/activities/SessionActivity.java b/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/activities/SessionActivity.java index d7875546..004bc1cf 100644 --- a/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/activities/SessionActivity.java +++ b/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/activities/SessionActivity.java @@ -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) { diff --git a/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/utils/CustomHttpClient.java b/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/utils/CustomHttpClient.java index a3cf387d..59b249df 100644 --- a/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/utils/CustomHttpClient.java +++ b/openvidu-android/app/src/main/java/io/openvidu/openvidu_android/utils/CustomHttpClient.java @@ -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); diff --git a/openvidu-electron/src/app.js b/openvidu-electron/src/app.js index 147880b2..203a494a 100644 --- a/openvidu-electron/src/app.js +++ b/openvidu-electron/src/app.js @@ -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//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', diff --git a/openvidu-filters/web/app.js b/openvidu-filters/web/app.js index 9b4a0550..91d0a81a 100644 --- a/openvidu-filters/web/app.js +++ b/openvidu-filters/web/app.js @@ -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//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), diff --git a/openvidu-getaroom/web/app.js b/openvidu-getaroom/web/app.js index 5d153028..025cda07 100644 --- a/openvidu-getaroom/web/app.js +++ b/openvidu-getaroom/web/app.js @@ -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//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" diff --git a/openvidu-hello-world/web/app.js b/openvidu-hello-world/web/app.js index e9bf188b..0f7ce59b 100644 --- a/openvidu-hello-world/web/app.js +++ b/openvidu-hello-world/web/app.js @@ -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//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" diff --git a/openvidu-insecure-angular/src/app/app.component.ts b/openvidu-insecure-angular/src/app/app.component.ts index 3d814071..47cb309a 100644 --- a/openvidu-insecure-angular/src/app/app.component.ts +++ b/openvidu-insecure-angular/src/app/app.component.ts @@ -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//connection) + * 3) The Connection.token must be consumed in Session.connect() method */ getToken(): Promise { @@ -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 { 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); diff --git a/openvidu-insecure-js/web/app.js b/openvidu-insecure-js/web/app.js index 256db584..4cb72549 100644 --- a/openvidu-insecure-js/web/app.js +++ b/openvidu-insecure-js/web/app.js @@ -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//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" diff --git a/openvidu-insecure-react/src/App.js b/openvidu-insecure-react/src/App.js index f186913b..59445a1d 100644 --- a/openvidu-insecure-react/src/App.js +++ b/openvidu-insecure-react/src/App.js @@ -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//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', diff --git a/openvidu-insecure-vue/src/App.vue b/openvidu-insecure-vue/src/App.vue index 4b138a9b..5d9528ad 100644 --- a/openvidu-insecure-vue/src/App.vue +++ b/openvidu-insecure-vue/src/App.vue @@ -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//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, diff --git a/openvidu-internet-explorer/web/app.js b/openvidu-internet-explorer/web/app.js index 6f21d748..2ea53a5a 100644 --- a/openvidu-internet-explorer/web/app.js +++ b/openvidu-internet-explorer/web/app.js @@ -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//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" diff --git a/openvidu-ionic/src/app/app.component.ts b/openvidu-ionic/src/app/app.component.ts index 48177ed4..c49dc939 100644 --- a/openvidu-ionic/src/app/app.component.ts +++ b/openvidu-ionic/src/app/app.component.ts @@ -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//connection) + * 3) The Connection.token must be consumed in Session.connect() method */ getToken(): Promise { @@ -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 { 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); diff --git a/openvidu-ipcameras/src/main/java/io/openvidu/ipcameras/MyRestController.java b/openvidu-ipcameras/src/main/java/io/openvidu/ipcameras/MyRestController.java index da67c6e2..7db3444e 100644 --- a/openvidu-ipcameras/src/main/java/io/openvidu/ipcameras/MyRestController.java +++ b/openvidu-ipcameras/src/main/java/io/openvidu/ipcameras/MyRestController.java @@ -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 diff --git a/openvidu-js-java/src/main/java/io/openvidu/js/java/SessionController.java b/openvidu-js-java/src/main/java/io/openvidu/js/java/SessionController.java index 6ccdf8dd..a1ed9f36 100644 --- a/openvidu-js-java/src/main/java/io/openvidu/js/java/SessionController.java +++ b/openvidu-js-java/src/main/java/io/openvidu/js/java/SessionController.java @@ -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); diff --git a/openvidu-js-node/server.js b/openvidu-js-node/server.js index 35626f72..8583e28c 100644 --- a/openvidu-js-node/server.js +++ b/openvidu-js-node/server.js @@ -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 => { diff --git a/openvidu-library-angular/src/app/app.component.ts b/openvidu-library-angular/src/app/app.component.ts index bdbd2988..05efbe4c 100644 --- a/openvidu-library-angular/src/app/app.component.ts +++ b/openvidu-library-angular/src/app/app.component.ts @@ -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//connection) + * 3) The Connection.token must be consumed in Session.connect() method */ getToken(): Promise { @@ -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 { 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); diff --git a/openvidu-library-react/src/App.js b/openvidu-library-react/src/App.js index cd0ebf0c..0bd9f9eb 100644 --- a/openvidu-library-react/src/App.js +++ b/openvidu-library-react/src/App.js @@ -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//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', diff --git a/openvidu-mvc-java/src/main/java/io/openvidu/mvc/java/SessionController.java b/openvidu-mvc-java/src/main/java/io/openvidu/mvc/java/SessionController.java index 55939d30..2d00801a 100644 --- a/openvidu-mvc-java/src/main/java/io/openvidu/mvc/java/SessionController.java +++ b/openvidu-mvc-java/src/main/java/io/openvidu/mvc/java/SessionController.java @@ -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); diff --git a/openvidu-mvc-node/server.js b/openvidu-mvc-node/server.js index 42b17772..9a437ae2 100644 --- a/openvidu-mvc-node/server.js +++ b/openvidu-mvc-node/server.js @@ -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, }); diff --git a/openvidu-react-native/App.js b/openvidu-react-native/App.js index e50f9b1f..1a6b189a 100644 --- a/openvidu-react-native/App.js +++ b/openvidu-react-native/App.js @@ -379,9 +379,9 @@ export default 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//connection) + * 3) The Connection.token must be consumed in Session.connect() method */ getToken() { @@ -394,7 +394,7 @@ export default class App extends Component { 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 { 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', diff --git a/openvidu-recording-java/src/main/java/io/openvidu/recording/java/MyRestController.java b/openvidu-recording-java/src/main/java/io/openvidu/recording/java/MyRestController.java index 53fa5f25..30ff0a21 100644 --- a/openvidu-recording-java/src/main/java/io/openvidu/recording/java/MyRestController.java +++ b/openvidu-recording-java/src/main/java/io/openvidu/recording/java/MyRestController.java @@ -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); diff --git a/openvidu-recording-node/server.js b/openvidu-recording-node/server.js index f2162e69..e09c15d4 100644 --- a/openvidu-recording-node/server.js +++ b/openvidu-recording-node/server.js @@ -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 => { diff --git a/openvidu-webcomponent/web/app.js b/openvidu-webcomponent/web/app.js index f2cc93c0..33b0cfc7 100644 --- a/openvidu-webcomponent/web/app.js +++ b/openvidu-webcomponent/web/app.js @@ -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//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),