Skip to content

Commit 62bc2b1

Browse files
authored
[remoterendering] Migrate remoterendering projects to use snippets extraction (#33248)
### Packages impacted by this PR - @azure/mixed-reality-remote-rendering ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `remoterendering` to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 3352cfc commit 62bc2b1

File tree

7 files changed

+469
-83
lines changed

7 files changed

+469
-83
lines changed

sdk/remoterendering/mixed-reality-remote-rendering/README.md

+189-62
Large diffs are not rendered by default.

sdk/remoterendering/mixed-reality-remote-rendering/package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
4646
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
4747
"unit-test:node": "dev-tool run test:vitest",
48-
"update-snippets": "echo skipped"
48+
"update-snippets": "dev-tool run update-snippets"
4949
},
5050
"files": [
5151
"dist/",
@@ -75,7 +75,7 @@
7575
"@azure/core-client": "^1.9.2",
7676
"@azure/core-lro": "^2.7.2",
7777
"@azure/core-paging": "^1.6.2",
78-
"@azure/core-rest-pipeline": "^1.18.0",
78+
"@azure/core-rest-pipeline": "^1.19.0",
7979
"@azure/core-tracing": "^1.2.0",
8080
"@azure/core-util": "^1.11.0",
8181
"@azure/logger": "^1.1.4",
@@ -87,15 +87,15 @@
8787
"@azure-tools/test-utils-vitest": "^1.0.0",
8888
"@azure/dev-tool": "^1.0.0",
8989
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
90-
"@azure/identity": "^4.0.1",
90+
"@azure/identity": "^4.7.0",
9191
"@types/node": "^18.0.0",
92-
"@vitest/browser": "^3.0.3",
93-
"@vitest/coverage-istanbul": "^3.0.3",
92+
"@vitest/browser": "^3.0.6",
93+
"@vitest/coverage-istanbul": "^3.0.6",
9494
"dotenv": "^16.0.0",
9595
"eslint": "^9.9.0",
96-
"playwright": "^1.49.0",
96+
"playwright": "^1.50.1",
9797
"typescript": "~5.7.2",
98-
"vitest": "^3.0.3"
98+
"vitest": "^3.0.6"
9999
},
100100
"//sampleConfiguration": {
101101
"productName": "Azure Remote Rendering",
@@ -110,6 +110,7 @@
110110
},
111111
"type": "module",
112112
"tshy": {
113+
"project": "./tsconfig.src.json",
113114
"exports": {
114115
"./package.json": "./package.json",
115116
".": "./src/index.ts"
@@ -122,8 +123,7 @@
122123
"browser",
123124
"react-native"
124125
],
125-
"selfLink": false,
126-
"project": "./tsconfig.src.json"
126+
"selfLink": false
127127
},
128128
"exports": {
129129
"./package.json": "./package.json",
@@ -145,5 +145,6 @@
145145
"default": "./dist/commonjs/index.js"
146146
}
147147
}
148-
}
148+
},
149+
"react-native": "./dist/react-native/index.js"
149150
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { AzureKeyCredential } from "@azure/core-auth";
5+
import { RemoteRenderingClient } from "../src/index.js";
6+
import {
7+
ClientSecretCredential,
8+
DefaultAzureCredential,
9+
DeviceCodeCredential,
10+
} from "@azure/identity";
11+
import { setLogLevel } from "@azure/logger";
12+
import { describe, it } from "vitest";
13+
import { randomUUID } from "node:crypto";
14+
15+
describe("snippets", () => {
16+
it("ReadmeSampleCreateClient_KeyCredential", async () => {
17+
const accountDomain = "<account domain>";
18+
const accountId = "<account ID>";
19+
const accountKey = "<account key>";
20+
const serviceEndpoint = "<serviceEndpoint>";
21+
// @ts-preserve-whitespace
22+
const credential = new AzureKeyCredential(accountKey);
23+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
24+
});
25+
26+
it("ReadmeSampleCreateClient_DeviceCodeCredential", async () => {
27+
const accountDomain = "<account domain>";
28+
const accountId = "<account ID>";
29+
const serviceEndpoint = "<serviceEndpoint>";
30+
const tenantId = "<tenant ID>";
31+
const clientId = "<client ID>";
32+
// @ts-preserve-whitespace
33+
const userPromptCallback = (deviceCodeInfo) => {
34+
console.debug(deviceCodeInfo.message);
35+
console.log(deviceCodeInfo.message);
36+
};
37+
// @ts-preserve-whitespace
38+
const credential = new DeviceCodeCredential({
39+
tenantId,
40+
clientId,
41+
userPromptCallback,
42+
authorityHost: `https://login.microsoftonline.com/${tenantId}`,
43+
});
44+
// @ts-preserve-whitespace
45+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
46+
});
47+
48+
it("ReadmeSampleCreateClient_ClientSecretCredential", async () => {
49+
const accountDomain = "<account domain>";
50+
const accountId = "<account ID>";
51+
const serviceEndpoint = "<serviceEndpoint>";
52+
const tenantId = "<tenant ID>";
53+
const clientId = "<client ID>";
54+
const clientSecret = "<client secret>";
55+
// @ts-preserve-whitespace
56+
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret, {
57+
authorityHost: `https://login.microsoftonline.com/${tenantId}`,
58+
});
59+
// @ts-preserve-whitespace
60+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
61+
});
62+
63+
it("ReadmeSampleCreateClient_DefaultAzureCredential", async () => {
64+
const accountDomain = "<account domain>";
65+
const accountId = "<account ID>";
66+
const serviceEndpoint = "<serviceEndpoint>";
67+
// @ts-preserve-whitespace
68+
const credential = new DefaultAzureCredential();
69+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
70+
});
71+
72+
it("ReadmeSampleCreateClient_AccessToken", async () => {
73+
const accountId = "<account ID>";
74+
const serviceEndpoint = "<serviceEndpoint>";
75+
// @ts-preserve-whitespace
76+
// getMixedRealityAccessTokenFromWebService is a hypothetical method that retrieves
77+
// a Mixed Reality access token from a web service. The web service would use the
78+
// MixedRealityStsClient and credentials to obtain an access token to be returned
79+
// to the client.
80+
async function getMixedRealityAccessTokenFromWebService() {
81+
return {
82+
token: "<access token>",
83+
expiresOnTimestamp: Date.now() + 24 * 60 * 60 * 1000,
84+
};
85+
}
86+
const accessToken = await getMixedRealityAccessTokenFromWebService();
87+
// @ts-preserve-whitespace
88+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accessToken);
89+
});
90+
91+
it("ReadmeSampleConvertASimpleAsset", async () => {
92+
const accountDomain = "<account domain>";
93+
const accountId = "<account ID>";
94+
const serviceEndpoint = "<serviceEndpoint>";
95+
const storageAccountName = "<storageAccountName>";
96+
const blobContainerName = "<blobStorageName>";
97+
const storageContainerUrl = `https://${storageAccountName}.blob.core.windows.net/${blobContainerName}`;
98+
// @ts-preserve-whitespace
99+
const credential = new DefaultAzureCredential();
100+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
101+
// @ts-preserve-whitespace
102+
const inputSettings = {
103+
storageContainerUrl,
104+
relativeInputAssetPath: "box.fbx",
105+
};
106+
const outputSettings = {
107+
storageContainerUrl,
108+
};
109+
const conversionSettings = { inputSettings, outputSettings };
110+
// @ts-preserve-whitespace
111+
// A randomly generated UUID is a good choice for a conversionId.
112+
const conversionId = randomUUID();
113+
// @ts-preserve-whitespace
114+
const conversionPoller = await client.beginConversion(conversionId, conversionSettings);
115+
// @ts-preserve-whitespace
116+
const conversion = await conversionPoller.pollUntilDone();
117+
// @ts-preserve-whitespace
118+
if (conversion.status === "Succeeded") {
119+
console.log(`Conversion succeeded: Output written to ${conversion.output?.outputAssetUrl}`);
120+
} else if (conversion.status === "Failed") {
121+
console.log(`Conversion failed: ${conversion.error.code} ${conversion.error.message}`);
122+
}
123+
});
124+
125+
it("ReadmeSampleConvertAMoreComplexAsset", async () => {
126+
const accountDomain = "<account domain>";
127+
const accountId = "<account ID>";
128+
const serviceEndpoint = "<serviceEndpoint>";
129+
const storageAccountName = "<storageAccountName>";
130+
const blobContainerName = "<blobStorageName>";
131+
const storageAccountName2 = "<storageAccountName2>";
132+
const blobContainerName2 = "<blobStorageName2>";
133+
const inputStorageUrl = `https://${storageAccountName}.blob.core.windows.net/${blobContainerName}`;
134+
const outputStorageUrl = `https://${storageAccountName2}.blob.core.windows.net/${blobContainerName2}`;
135+
// @ts-preserve-whitespace
136+
const credential = new DefaultAzureCredential();
137+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
138+
// @ts-preserve-whitespace
139+
const inputSettings = {
140+
storageContainerUrl: inputStorageUrl,
141+
blobPrefix: "Bicycle",
142+
relativeInputAssetPath: "bicycle.gltf",
143+
};
144+
const outputSettings = {
145+
storageContainerUrl: outputStorageUrl,
146+
blobPrefix: "ConvertedBicycle",
147+
};
148+
const conversionSettings = { inputSettings, outputSettings };
149+
// @ts-preserve-whitespace
150+
const conversionId = randomUUID();
151+
// @ts-preserve-whitespace
152+
const conversionPoller = await client.beginConversion(conversionId, conversionSettings);
153+
// @ts-preserve-whitespace
154+
const conversion = await conversionPoller.pollUntilDone();
155+
// @ts-preserve-whitespace
156+
if (conversion.status === "Succeeded") {
157+
console.log(`Conversion succeeded: Output written to ${conversion.output?.outputAssetUrl}`);
158+
} else if (conversion.status === "Failed") {
159+
console.log(`Conversion failed: ${conversion.error.code} ${conversion.error.message}`);
160+
}
161+
});
162+
163+
it("ReadmeSampleListConversions", async () => {
164+
const accountDomain = "<account domain>";
165+
const accountId = "<account ID>";
166+
const serviceEndpoint = "<serviceEndpoint>";
167+
// @ts-preserve-whitespace
168+
const credential = new DefaultAzureCredential();
169+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
170+
// @ts-preserve-whitespace
171+
for await (const conversion of client.listConversions()) {
172+
if (conversion.status === "Succeeded") {
173+
console.log(
174+
`Conversion ${conversion.conversionId} succeeded: Output written to ${conversion.output?.outputAssetUrl}`,
175+
);
176+
} else if (conversion.status === "Failed") {
177+
console.log(
178+
`Conversion ${conversion.conversionId} failed: ${conversion.error.code} ${conversion.error.message}`,
179+
);
180+
}
181+
}
182+
});
183+
184+
it("ReadmeSampleCreateASession", async () => {
185+
const accountDomain = "<account domain>";
186+
const accountId = "<account ID>";
187+
const serviceEndpoint = "<serviceEndpoint>";
188+
// @ts-preserve-whitespace
189+
const credential = new DefaultAzureCredential();
190+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
191+
// @ts-preserve-whitespace
192+
const sessionSettings = {
193+
maxLeaseTimeInMinutes: 4,
194+
size: "Standard",
195+
};
196+
// @ts-preserve-whitespace
197+
// A randomly generated UUID is a good choice for a conversionId.
198+
const sessionId = randomUUID();
199+
// @ts-preserve-whitespace
200+
const sessionPoller = await client.beginSession(sessionId, sessionSettings);
201+
});
202+
203+
it("ReadmeSampleExtendLease", async () => {
204+
const accountDomain = "<account domain>";
205+
const accountId = "<account ID>";
206+
const serviceEndpoint = "<serviceEndpoint>";
207+
// @ts-preserve-whitespace
208+
const credential = new DefaultAzureCredential();
209+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
210+
// @ts-preserve-whitespace
211+
const sessionId = "<session ID from previous step>";
212+
const currentSession = await client.getSession(sessionId);
213+
if (currentSession.status === "Ready") {
214+
if (
215+
currentSession.maxLeaseTimeInMinutes -
216+
(Date.now() - +currentSession.properties.createdOn) / 60000 <
217+
2
218+
) {
219+
const newLeaseTime = currentSession.maxLeaseTimeInMinutes + 15;
220+
// @ts-preserve-whitespace
221+
await client.updateSession(sessionId, { maxLeaseTimeInMinutes: newLeaseTime });
222+
}
223+
}
224+
});
225+
226+
it("ReadmeSampleListSessions", async () => {
227+
const accountDomain = "<account domain>";
228+
const accountId = "<account ID>";
229+
const serviceEndpoint = "<serviceEndpoint>";
230+
// @ts-preserve-whitespace
231+
const credential = new DefaultAzureCredential();
232+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
233+
// @ts-preserve-whitespace
234+
for await (const session of client.listSessions()) {
235+
console.log(`Session ${session.sessionId} is ${session.status}`);
236+
}
237+
});
238+
239+
it("ReadmeSampleStopASession", async () => {
240+
const accountDomain = "<account domain>";
241+
const accountId = "<account ID>";
242+
const serviceEndpoint = "<serviceEndpoint>";
243+
// @ts-preserve-whitespace
244+
const credential = new DefaultAzureCredential();
245+
const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
246+
// @ts-preserve-whitespace
247+
const sessionId = "<session ID from previous step>";
248+
await client.endSession(sessionId);
249+
});
250+
251+
it("SetLogLevel", async () => {
252+
setLogLevel("info");
253+
});
254+
});
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"references": [
3-
{ "path": "./tsconfig.src.json" },
4-
{ "path": "./tsconfig.samples.json" },
5-
{ "path": "./tsconfig.test.json" }
3+
{
4+
"path": "./tsconfig.src.json"
5+
},
6+
{
7+
"path": "./tsconfig.samples.json"
8+
},
9+
{
10+
"path": "./tsconfig.test.json"
11+
}
612
]
713
}

sdk/remoterendering/mixed-reality-remote-rendering/vitest.browser.config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export default mergeConfig(
99
defineConfig({
1010
test: {
1111
include: ["dist-test/browser/test/**/*.spec.js"],
12-
hookTimeout: 5000000,
13-
testTimeout: 5000000,
12+
exclude: ["dist-test/browser/test/snippets.spec.js"],
13+
testTimeout: 1200000,
14+
hookTimeout: 1200000,
1415
},
1516
}),
1617
);

sdk/remoterendering/mixed-reality-remote-rendering/vitest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default mergeConfig(
88
viteConfig,
99
defineConfig({
1010
test: {
11-
hookTimeout: 5000000,
12-
testTimeout: 5000000,
11+
testTimeout: 1200000,
12+
hookTimeout: 1200000,
1313
},
1414
}),
1515
);

sdk/remoterendering/mixed-reality-remote-rendering/vitest.esm.config.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
55
import vitestConfig from "./vitest.config.ts";
66
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";
77

8-
export default mergeConfig(
9-
vitestConfig,
10-
vitestEsmConfig
11-
);
8+
export default mergeConfig(vitestConfig, vitestEsmConfig);

0 commit comments

Comments
 (0)