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

diff --git a/example/geny-window.js b/example/geny-window.js index 408b479..d46b4de 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; }; @@ -143,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; } @@ -163,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) => { @@ -202,7 +195,7 @@ const connectInstance = async (wsAddress) => { }); const instance = await response.json(); instanceUuid = instance.uuid; - await getJWTToken(); + await getJWTToken(instanceUuid); initPlayer(instance.publicWebrtcUrl); };