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

[remoterendering] Migrate remoterendering projects to use snippets extraction #33248

Merged
merged 14 commits into from
Mar 3, 2025
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
251 changes: 189 additions & 62 deletions sdk/remoterendering/mixed-reality-remote-rendering/README.md

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions sdk/remoterendering/mixed-reality-remote-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"files": [
"dist/",
Expand Down Expand Up @@ -75,7 +75,7 @@
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.7.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-tracing": "^1.2.0",
"@azure/core-util": "^1.11.0",
"@azure/logger": "^1.1.4",
Expand All @@ -87,15 +87,15 @@
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.7.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"//sampleConfiguration": {
"productName": "Azure Remote Rendering",
Expand All @@ -110,6 +110,7 @@
},
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -122,8 +123,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
Expand All @@ -145,5 +145,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { AzureKeyCredential } from "@azure/core-auth";
import { RemoteRenderingClient } from "../src/index.js";
import {
ClientSecretCredential,
DefaultAzureCredential,
DeviceCodeCredential,
} from "@azure/identity";
import { setLogLevel } from "@azure/logger";
import { describe, it } from "vitest";
import { randomUUID } from "node:crypto";

describe("snippets", () => {
it("ReadmeSampleCreateClient_KeyCredential", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const accountKey = "<account key>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new AzureKeyCredential(accountKey);
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
});

it("ReadmeSampleCreateClient_DeviceCodeCredential", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
const tenantId = "<tenant ID>";
const clientId = "<client ID>";
// @ts-preserve-whitespace
const userPromptCallback = (deviceCodeInfo) => {
console.debug(deviceCodeInfo.message);
console.log(deviceCodeInfo.message);
};
// @ts-preserve-whitespace
const credential = new DeviceCodeCredential({
tenantId,
clientId,
userPromptCallback,
authorityHost: `https://login.microsoftonline.com/${tenantId}`,
});
// @ts-preserve-whitespace
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
});

it("ReadmeSampleCreateClient_ClientSecretCredential", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
const tenantId = "<tenant ID>";
const clientId = "<client ID>";
const clientSecret = "<client secret>";
// @ts-preserve-whitespace
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret, {
authorityHost: `https://login.microsoftonline.com/${tenantId}`,
});
// @ts-preserve-whitespace
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
});

it("ReadmeSampleCreateClient_DefaultAzureCredential", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
});

it("ReadmeSampleCreateClient_AccessToken", async () => {
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
// getMixedRealityAccessTokenFromWebService is a hypothetical method that retrieves
// a Mixed Reality access token from a web service. The web service would use the
// MixedRealityStsClient and credentials to obtain an access token to be returned
// to the client.
async function getMixedRealityAccessTokenFromWebService() {
return {
token: "<access token>",
expiresOnTimestamp: Date.now() + 24 * 60 * 60 * 1000,
};
}
const accessToken = await getMixedRealityAccessTokenFromWebService();
// @ts-preserve-whitespace
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accessToken);
});

it("ReadmeSampleConvertASimpleAsset", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
const storageAccountName = "<storageAccountName>";
const blobContainerName = "<blobStorageName>";
const storageContainerUrl = `https://${storageAccountName}.blob.core.windows.net/${blobContainerName}`;
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
const inputSettings = {
storageContainerUrl,
relativeInputAssetPath: "box.fbx",
};
const outputSettings = {
storageContainerUrl,
};
const conversionSettings = { inputSettings, outputSettings };
// @ts-preserve-whitespace
// A randomly generated UUID is a good choice for a conversionId.
const conversionId = randomUUID();
// @ts-preserve-whitespace
const conversionPoller = await client.beginConversion(conversionId, conversionSettings);
// @ts-preserve-whitespace
const conversion = await conversionPoller.pollUntilDone();
// @ts-preserve-whitespace
if (conversion.status === "Succeeded") {
console.log(`Conversion succeeded: Output written to ${conversion.output?.outputAssetUrl}`);
} else if (conversion.status === "Failed") {
console.log(`Conversion failed: ${conversion.error.code} ${conversion.error.message}`);
}
});

it("ReadmeSampleConvertAMoreComplexAsset", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
const storageAccountName = "<storageAccountName>";
const blobContainerName = "<blobStorageName>";
const storageAccountName2 = "<storageAccountName2>";
const blobContainerName2 = "<blobStorageName2>";
const inputStorageUrl = `https://${storageAccountName}.blob.core.windows.net/${blobContainerName}`;
const outputStorageUrl = `https://${storageAccountName2}.blob.core.windows.net/${blobContainerName2}`;
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
const inputSettings = {
storageContainerUrl: inputStorageUrl,
blobPrefix: "Bicycle",
relativeInputAssetPath: "bicycle.gltf",
};
const outputSettings = {
storageContainerUrl: outputStorageUrl,
blobPrefix: "ConvertedBicycle",
};
const conversionSettings = { inputSettings, outputSettings };
// @ts-preserve-whitespace
const conversionId = randomUUID();
// @ts-preserve-whitespace
const conversionPoller = await client.beginConversion(conversionId, conversionSettings);
// @ts-preserve-whitespace
const conversion = await conversionPoller.pollUntilDone();
// @ts-preserve-whitespace
if (conversion.status === "Succeeded") {
console.log(`Conversion succeeded: Output written to ${conversion.output?.outputAssetUrl}`);
} else if (conversion.status === "Failed") {
console.log(`Conversion failed: ${conversion.error.code} ${conversion.error.message}`);
}
});

it("ReadmeSampleListConversions", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
for await (const conversion of client.listConversions()) {
if (conversion.status === "Succeeded") {
console.log(
`Conversion ${conversion.conversionId} succeeded: Output written to ${conversion.output?.outputAssetUrl}`,
);
} else if (conversion.status === "Failed") {
console.log(
`Conversion ${conversion.conversionId} failed: ${conversion.error.code} ${conversion.error.message}`,
);
}
}
});

it("ReadmeSampleCreateASession", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
const sessionSettings = {
maxLeaseTimeInMinutes: 4,
size: "Standard",
};
// @ts-preserve-whitespace
// A randomly generated UUID is a good choice for a conversionId.
const sessionId = randomUUID();
// @ts-preserve-whitespace
const sessionPoller = await client.beginSession(sessionId, sessionSettings);
});

it("ReadmeSampleExtendLease", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
const sessionId = "<session ID from previous step>";
const currentSession = await client.getSession(sessionId);
if (currentSession.status === "Ready") {
if (
currentSession.maxLeaseTimeInMinutes -
(Date.now() - +currentSession.properties.createdOn) / 60000 <
2
) {
const newLeaseTime = currentSession.maxLeaseTimeInMinutes + 15;
// @ts-preserve-whitespace
await client.updateSession(sessionId, { maxLeaseTimeInMinutes: newLeaseTime });
}
}
});

it("ReadmeSampleListSessions", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
for await (const session of client.listSessions()) {
console.log(`Session ${session.sessionId} is ${session.status}`);
}
});

it("ReadmeSampleStopASession", async () => {
const accountDomain = "<account domain>";
const accountId = "<account ID>";
const serviceEndpoint = "<serviceEndpoint>";
// @ts-preserve-whitespace
const credential = new DefaultAzureCredential();
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
// @ts-preserve-whitespace
const sessionId = "<session ID from previous step>";
await client.endSession(sessionId);
});

it("SetLogLevel", async () => {
setLogLevel("info");
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
{
"path": "./tsconfig.src.json"
},
{
"path": "./tsconfig.samples.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export default mergeConfig(
defineConfig({
test: {
include: ["dist-test/browser/test/**/*.spec.js"],
hookTimeout: 5000000,
testTimeout: 5000000,
exclude: ["dist-test/browser/test/snippets.spec.js"],
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
hookTimeout: 5000000,
testTimeout: 5000000,
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
export default mergeConfig(vitestConfig, vitestEsmConfig);
Loading