Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the example to use the latest apis for fetching recipes and accessing instances. #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions example/geny-window.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ <h3>Connect to an existing instance</h3>
<datalist id="instances-history"></datalist>
<div class="note" id="input-note">
<ul>
<li><strong>Instance uuid:</strong> the uuid of a launched device.</li>
<li><strong>Instance uuid:</strong> the uuid of a launched device. <strong>(Genymotion SaaS only)</strong></li>
<li>
<strong>WebSocket address:</strong> the WebSocket address (starting with "wss://") of a
launched device.
<strong>WebSocket address:</strong> the WebSocket address ("<i>wss://public ip address</i>") of the device. <strong>(Genymotion Device Image only)</strong>
</li>
</ul>
</div>
Expand Down
41 changes: 17 additions & 24 deletions example/geny-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -95,7 +98,7 @@ const startInstance = async (recipeUuid) => {

instanceUuid = recipe.uuid;

await getJWTToken();
await getJWTToken(instanceUuid);

return recipe;
};
Expand Down Expand Up @@ -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;
}

Expand All @@ -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) => {
Expand All @@ -202,7 +195,7 @@ const connectInstance = async (wsAddress) => {
});
const instance = await response.json();
instanceUuid = instance.uuid;
await getJWTToken();
await getJWTToken(instanceUuid);
initPlayer(instance.publicWebrtcUrl);
};

Expand Down
Loading