@@ -11,19 +11,20 @@ import {
11
11
GitpodServerPath ,
12
12
GitpodService ,
13
13
GitpodServiceImpl ,
14
- WorkspaceInfo ,
15
14
Disposable ,
16
15
} from "@gitpod/gitpod-protocol" ;
17
16
import { WebSocketConnectionProvider } from "@gitpod/gitpod-protocol/lib/messaging/browser/connection" ;
18
17
import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url" ;
19
18
import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
20
19
import { IDEFrontendDashboardService } from "@gitpod/gitpod-protocol/lib/frontend-dashboard-service" ;
21
20
import { RemoteTrackMessage } from "@gitpod/gitpod-protocol/lib/analytics" ;
22
- import { helloService , stream , userClient , workspaceClient } from "./public-api" ;
21
+ import { converter , helloService , stream , userClient , workspaceClient } from "./public-api" ;
23
22
import { getExperimentsClient } from "../experiments/client" ;
24
23
import { instrumentWebSocket } from "./metrics" ;
25
24
import { LotsOfRepliesResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/dummy_pb" ;
26
25
import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb" ;
26
+ import { watchWorkspaceStatus } from "../data/workspaces/listen-to-workspace-ws-messages" ;
27
+ import { Workspace , WorkspaceSpec_WorkspaceType , WorkspaceStatus } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb" ;
27
28
28
29
export const gitpodHostUrl = new GitpodHostUrl ( window . location . toString ( ) ) ;
29
30
@@ -164,8 +165,9 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
164
165
private ownerId : string | undefined ;
165
166
private user : User | undefined ;
166
167
private ideCredentials ! : string ;
168
+ private workspace ! : Workspace ;
167
169
168
- private latestInfo ?: IDEFrontendDashboardService . Status ;
170
+ private latestInfo ?: IDEFrontendDashboardService . Info ;
169
171
170
172
private readonly onDidChangeEmitter = new Emitter < IDEFrontendDashboardService . SetStateData > ( ) ;
171
173
readonly onSetState = this . onDidChangeEmitter . event ;
@@ -208,17 +210,18 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
208
210
}
209
211
210
212
private async processServerInfo ( ) {
211
- const [ user , listener , ideCredentials ] = await Promise . all ( [
213
+ const [ user , workspaceResponse , ideCredentials ] = await Promise . all ( [
212
214
userClient . getAuthenticatedUser ( { } ) . then ( ( r ) => r . user ) ,
213
- this . service . listenToInstance ( this . workspaceID ) ,
215
+ workspaceClient . getWorkspace ( { workspaceId : this . workspaceID } ) ,
214
216
workspaceClient
215
217
. getWorkspaceEditorCredentials ( { workspaceId : this . workspaceID } )
216
218
. then ( ( resp ) => resp . editorCredentials ) ,
217
219
] ) ;
220
+ this . workspace = workspaceResponse . workspace ! ;
218
221
this . user = user ;
219
222
this . ideCredentials = ideCredentials ;
220
- const reconcile = ( ) => {
221
- const info = this . parseInfo ( listener . info ) ;
223
+ const reconcile = ( status ?: WorkspaceStatus ) => {
224
+ const info = this . parseInfo ( status ?? this . workspace . status ! ) ;
222
225
this . latestInfo = info ;
223
226
const oldInstanceID = this . instanceID ;
224
227
this . instanceID = info . instanceId ;
@@ -227,27 +230,27 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
227
230
if ( info . instanceId && oldInstanceID !== info . instanceId ) {
228
231
this . auth ( ) ;
229
232
}
230
-
231
- // TODO(hw): to be removed after IDE deployed
232
- this . sendStatusUpdate ( this . latestInfo ) ;
233
- // TODO(hw): end of todo
234
233
this . sendInfoUpdate ( this . latestInfo ) ;
235
234
} ;
236
235
reconcile ( ) ;
237
- listener . onDidChange ( reconcile ) ;
236
+ watchWorkspaceStatus ( this . workspaceID , ( response ) => {
237
+ if ( response . status ) {
238
+ reconcile ( response . status ) ;
239
+ }
240
+ } ) ;
238
241
}
239
242
240
- private parseInfo ( workspace : WorkspaceInfo ) : IDEFrontendDashboardService . Info {
243
+ private parseInfo ( status : WorkspaceStatus ) : IDEFrontendDashboardService . Info {
241
244
return {
242
245
loggedUserId : this . user ! . id ,
243
246
workspaceID : this . workspaceID ,
244
- instanceId : workspace . latestInstance ?. id ,
245
- ideUrl : workspace . latestInstance ?. ideUrl ,
246
- statusPhase : workspace . latestInstance ?. status . phase ,
247
- workspaceDescription : workspace . workspace . description ,
248
- workspaceType : workspace . workspace . type ,
247
+ instanceId : status . instanceId ,
248
+ ideUrl : status . workspaceUrl ,
249
+ statusPhase : status . phase ?. name ? converter . fromPhase ( status . phase ?. name ) : "unknown" ,
250
+ workspaceDescription : this . workspace . metadata ?. name ?? "" ,
251
+ workspaceType : this . workspace . spec ?. type === WorkspaceSpec_WorkspaceType . PREBUILD ? "prebuild" : "regular" ,
249
252
credentialsToken : this . ideCredentials ,
250
- ownerId : workspace . workspace . ownerId ,
253
+ ownerId : this . workspace . metadata ?. ownerId ?? "" ,
251
254
} ;
252
255
}
253
256
@@ -271,6 +274,7 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
271
274
workspaceId : this . workspaceID ,
272
275
type : this . latestInfo ?. workspaceType ,
273
276
} ;
277
+ // TODO:
274
278
this . service . server . trackEvent ( msg ) ;
275
279
}
276
280
@@ -300,19 +304,6 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
300
304
}
301
305
}
302
306
303
- // TODO(hw): to be removed after IDE deployed
304
- sendStatusUpdate ( status : IDEFrontendDashboardService . Status ) : void {
305
- this . clientWindow . postMessage (
306
- {
307
- version : 1 ,
308
- type : "ide-status-update" ,
309
- status,
310
- } as IDEFrontendDashboardService . StatusUpdateEventData ,
311
- "*" ,
312
- ) ;
313
- }
314
- // TODO(hw): end of todo
315
-
316
307
sendInfoUpdate ( info : IDEFrontendDashboardService . Info ) : void {
317
308
this . clientWindow . postMessage (
318
309
{
0 commit comments