/
renderingSession.ts
223 lines (210 loc) · 7.38 KB
/
renderingSession.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
RenderingServerSize,
SessionProperties,
KnownRenderingSessionStatus
} from "../generated/index";
import {
RemoteRenderingServiceError,
createRemoteRenderingServiceError
} from "../remoteRenderingServiceError";
/** Properties available for a rendering session in any state */
export interface RenderingSessionBase {
/** The ID of the session supplied when the session was created. */
sessionId: string;
/** The size of the server used for the rendering session. The size impacts the number of polygons the server can render. Refer to https://docs.microsoft.com/azure/remote-rendering/reference/vm-sizes for details. */
size: RenderingServerSize;
/** The time in minutes the session will run after reaching the 'Ready' state. */
maxLeaseTimeInMinutes: number;
}
/** The properties of a complete rendering session */
export interface RenderingSessionProperties {
/**
* The TCP port at which the Azure Remote Rendering Inspector tool is hosted.
*/
readonly arrInspectorPort: number;
/**
* The TCP port used for the handshake when establishing a connection.
*/
readonly handshakePort: number;
/**
* Amount of time in minutes the session is or was in the 'Ready' state. Time is rounded down to a full minute.
*/
readonly elapsedTimeInMinutes: number;
/**
* The hostname under which the rendering session is reachable.
*/
readonly host: string;
/**
* The computational power of the rendering session GPU measured in teraflops.
*/
readonly teraflops: number;
/**
* The time when the rendering session was created. Date and time in ISO 8601 format.
*/
readonly createdOn: Date;
}
/**
* In certain RenderingSession states, some properties are available and some are not.
*/
export interface PartialRenderingSessionProperties {
/**
* The TCP port at which the Azure Remote Rendering Inspector tool is hosted.
*/
readonly arrInspectorPort?: number;
/**
* The TCP port used for the handshake when establishing a connection.
*/
readonly handshakePort?: number;
/**
* Amount of time in minutes the session is or was in the 'Ready' state. Time is rounded down to a full minute.
*/
readonly elapsedTimeInMinutes?: number;
/**
* The hostname under which the rendering session is reachable.
*/
readonly host?: string;
/**
* The computational power of the rendering session GPU measured in teraflops.
*/
readonly teraflops?: number;
/**
* The time when the rendering session was created. Date and time in ISO 8601 format.
*/
readonly createdOn?: Date;
}
/** The rendering session is ready for incoming connections. */
export interface ReadyRenderingSession extends RenderingSessionBase {
/** The rendering session is ready for incoming connections. */
status: "Ready";
/**
* The properties of the session.
*/
properties: RenderingSessionProperties;
}
/** The rendering session has encountered an error, and is unusable. */
export interface ErrorRenderingSession extends RenderingSessionBase {
/** The rendering session has encountered an error, and is unusable. This is a terminal state. */
status: "Error";
/**
* The error object containing details about the rendering session startup failure.
*/
readonly error: RemoteRenderingServiceError;
/**
* The properties of the session which had been set.
*/
partialProperties: PartialRenderingSessionProperties;
}
/** The rendering session is starting, but not accepting incoming connections yet. */
export interface StartingRenderingSession extends RenderingSessionBase {
/** The rendering session is starting, but not accepting incoming connections yet. */
status: "Starting";
/**
* The properties which are currently known about the session.
*/
partialProperties: PartialRenderingSessionProperties;
}
/** The rendering session enters the 'Expired' state when it has been in the 'Ready' state longer than its lease time. This is a terminal state. */
export interface ExpiredRenderingSession extends RenderingSessionBase {
/** The rendering session enters the 'Expired' state when it has been in the 'Ready' state longer than its lease time. This is a terminal state. */
status: "Expired";
/**
* The properties of the session.
*/
properties: RenderingSessionProperties;
}
/** The rendering session has been stopped with the 'Stop Session' operation. This is a terminal state. */
export interface StoppedRenderingSession extends RenderingSessionBase {
/** The rendering session has been stopped with the 'Stop Session' operation. This is a terminal state. */
status: "Stopped";
/**
* The properties that were known about the session.
*/
partialProperties: PartialRenderingSessionProperties;
}
/** Information about a rendering session. This is a tagged union with "status" as its discriminant property. */
export type RenderingSession =
| StartingRenderingSession
| ReadyRenderingSession
| ErrorRenderingSession
| ExpiredRenderingSession
| StoppedRenderingSession;
/**
* @internal
*/
function renderingSessionPropertiesFromSessionProperties(
session: SessionProperties
): RenderingSessionProperties {
return {
arrInspectorPort: session.arrInspectorPort!,
handshakePort: session.handshakePort!,
elapsedTimeInMinutes: session.elapsedTimeInMinutes!,
host: session.host!,
teraflops: session.teraflops!,
createdOn: session.createdOn!
};
}
/**
* @internal
*/
function partialRenderingSessionPropertiesFromSessionProperties(
session: SessionProperties
): PartialRenderingSessionProperties {
return {
arrInspectorPort: session.arrInspectorPort,
handshakePort: session.handshakePort,
elapsedTimeInMinutes: session.elapsedTimeInMinutes,
host: session.host,
teraflops: session.teraflops,
createdOn: session.createdOn
};
}
/**
* Build a RenderingSession object from the SessionProperties object returned by the service.
* @internal
*/
export function renderingSessionFromSessionProperties(
session: SessionProperties
): RenderingSession {
const baseProperties: RenderingSessionBase = {
sessionId: session.sessionId,
size: session.size,
maxLeaseTimeInMinutes: session.maxLeaseTimeInMinutes!
};
switch (session.status) {
case KnownRenderingSessionStatus.Ready:
return {
status: "Ready",
...baseProperties,
properties: renderingSessionPropertiesFromSessionProperties(session)
};
case KnownRenderingSessionStatus.Starting:
return {
status: "Starting",
...baseProperties,
partialProperties: partialRenderingSessionPropertiesFromSessionProperties(session)
};
case KnownRenderingSessionStatus.Error:
return {
status: "Error",
...baseProperties,
error: createRemoteRenderingServiceError(session.error!),
partialProperties: partialRenderingSessionPropertiesFromSessionProperties(session)
};
case KnownRenderingSessionStatus.Expired:
return {
status: "Expired",
...baseProperties,
properties: renderingSessionPropertiesFromSessionProperties(session)
};
case KnownRenderingSessionStatus.Stopped:
return {
status: "Stopped",
...baseProperties,
partialProperties: partialRenderingSessionPropertiesFromSessionProperties(session)
};
default:
throw new Error("Unrecognized RenderingSessionStatus returned by the service");
}
}