From 0366eabf3aa675a3587f501a26bbe099102e870d Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Thu, 26 Sep 2024 12:27:52 +0200 Subject: [PATCH 1/3] Example: Update the example to provide the instance uuid when fetching a JWT token. See the documentation for `POST /v1/instances/access-token`: https://developer.genymotion.com/saas/#tag/Instances-v1/operation/accessToken It has an `instance_uuid` request payload field. --- example/geny-window.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/example/geny-window.js b/example/geny-window.js index 408b479..451ac6b 100644 --- a/example/geny-window.js +++ b/example/geny-window.js @@ -29,11 +29,14 @@ const getApiToken = async () => { }; // get jwt token -const getJWTToken = async () => { +const getJWTToken = async (instanceUuid) => { try { const response = await fetch(baseUrlToFetch + `/v1/instances/access-token`, { ...requestInit, method: 'POST', + body: JSON.stringify({ + instance_uuid: instanceUuid, + }), }); if (response.status !== 200) { @@ -95,7 +98,7 @@ const startInstance = async (recipeUuid) => { instanceUuid = recipe.uuid; - await getJWTToken(); + await getJWTToken(instanceUuid); return recipe; }; @@ -202,7 +205,7 @@ const connectInstance = async (wsAddress) => { }); const instance = await response.json(); instanceUuid = instance.uuid; - await getJWTToken(); + await getJWTToken(instanceUuid); initPlayer(instance.publicWebrtcUrl); }; From 980e11ad945379db1693848f97939e68dd082d8f Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Thu, 26 Sep 2024 17:36:12 +0200 Subject: [PATCH 2/3] Example: Update the text for connecting to a websocket address directly. Indicate that the instance uuid is for Genymotion SaaS, and the webrtc address is for Genymotion Device Image. --- example/geny-window.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/example/geny-window.html b/example/geny-window.html index 20c5c8f..4973492 100644 --- a/example/geny-window.html +++ b/example/geny-window.html @@ -61,10 +61,9 @@

Connect to an existing instance

    -
  • Instance uuid: the uuid of a launched device.
  • +
  • Instance uuid: the uuid of a launched device. (Genymotion SaaS only)
  • - WebSocket address: the WebSocket address (starting with "wss://") of a - launched device. + WebSocket address: the WebSocket address ("wss://public ip address") of the device. (Genymotion Device Image only)
From 03e4be168f5fb228779e7b5e4bacfe0c8eb3235f Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Thu, 26 Sep 2024 12:59:57 +0200 Subject: [PATCH 3/3] Example: Use the `GET /v3/recipes/` route to retrieve recipes. See the documentation: https://developer.genymotion.com/saas/#tag/Recipes-v3/operation/listRecipesV3 --- example/geny-window.js | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/example/geny-window.js b/example/geny-window.js index 451ac6b..d46b4de 100644 --- a/example/geny-window.js +++ b/example/geny-window.js @@ -146,14 +146,14 @@ const stopInstance = async () => { // Fetch recipe and add them to the select const fetchRecipes = async () => { try { - const response = await fetch(baseUrlToFetch + `/v1/recipes?limit=1000`, { + const response = await fetch(baseUrlToFetch + `/v3/recipes/?arch=x86_64&arch=x86&arch=arm64&limit=1000`, { ...requestInit, method: 'GET', }); - const recipes = await response.json(); + const recipesResult = await response.json(); if (response.status !== 200) { - alert(recipes.message); + alert(recipesResult.message); return; } @@ -166,30 +166,20 @@ const fetchRecipes = async () => { placeholderOption.disabled = true; placeholderOption.selected = true; selectElement.add(placeholderOption, selectElement.firstChild); - - for (const recipeType in recipes) { - addOptionsToGroup(recipeType, recipes[recipeType]); + const recipes = recipesResult.results; + + for (let i = 0; i < recipes.length; i++) { + const recipe = recipes[i]; + const optionElement = document.createElement('option'); + optionElement.value = recipe.uuid; + optionElement.textContent = recipe.name; + selectElement.appendChild(optionElement); } } catch (error) { alert(error); } }; -const addOptionsToGroup = (recipeType, recipes) => { - const selectElement = document.querySelector('#listRecipes'); - - const optgroup = document.createElement('optgroup'); - optgroup.label = recipeType; - - recipes.forEach((recipe) => { - const optionElement = document.createElement('option'); - optionElement.value = recipe.uuid; - optionElement.textContent = recipe.name; - optgroup.appendChild(optionElement); - }); - - selectElement.appendChild(optgroup); -}; // connect to an existing instance through an instance Uuid or an instance ws address const connectInstance = async (wsAddress) => {