@@ -11,19 +11,20 @@ import {
1111 GitpodServerPath ,
1212 GitpodService ,
1313 GitpodServiceImpl ,
14- WorkspaceInfo ,
1514 Disposable ,
1615} from "@gitpod/gitpod-protocol" ;
1716import { WebSocketConnectionProvider } from "@gitpod/gitpod-protocol/lib/messaging/browser/connection" ;
1817import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url" ;
1918import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
2019import { IDEFrontendDashboardService } from "@gitpod/gitpod-protocol/lib/frontend-dashboard-service" ;
2120import { 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" ;
2322import { getExperimentsClient } from "../experiments/client" ;
2423import { instrumentWebSocket } from "./metrics" ;
2524import { LotsOfRepliesResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/dummy_pb" ;
2625import { 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" ;
2728
2829export const gitpodHostUrl = new GitpodHostUrl ( window . location . toString ( ) ) ;
2930
@@ -164,8 +165,9 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
164165 private ownerId : string | undefined ;
165166 private user : User | undefined ;
166167 private ideCredentials ! : string ;
168+ private workspace ! : Workspace ;
167169
168- private latestInfo ?: IDEFrontendDashboardService . Status ;
170+ private latestInfo ?: IDEFrontendDashboardService . Info ;
169171
170172 private readonly onDidChangeEmitter = new Emitter < IDEFrontendDashboardService . SetStateData > ( ) ;
171173 readonly onSetState = this . onDidChangeEmitter . event ;
@@ -208,17 +210,18 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
208210 }
209211
210212 private async processServerInfo ( ) {
211- const [ user , listener , ideCredentials ] = await Promise . all ( [
213+ const [ user , workspaceResponse , ideCredentials ] = await Promise . all ( [
212214 userClient . getAuthenticatedUser ( { } ) . then ( ( r ) => r . user ) ,
213- this . service . listenToInstance ( this . workspaceID ) ,
215+ workspaceClient . getWorkspace ( { workspaceId : this . workspaceID } ) ,
214216 workspaceClient
215217 . getWorkspaceEditorCredentials ( { workspaceId : this . workspaceID } )
216218 . then ( ( resp ) => resp . editorCredentials ) ,
217219 ] ) ;
220+ this . workspace = workspaceResponse . workspace ! ;
218221 this . user = user ;
219222 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 ! ) ;
222225 this . latestInfo = info ;
223226 const oldInstanceID = this . instanceID ;
224227 this . instanceID = info . instanceId ;
@@ -227,27 +230,27 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
227230 if ( info . instanceId && oldInstanceID !== info . instanceId ) {
228231 this . auth ( ) ;
229232 }
230-
231- // TODO(hw): to be removed after IDE deployed
232- this . sendStatusUpdate ( this . latestInfo ) ;
233- // TODO(hw): end of todo
234233 this . sendInfoUpdate ( this . latestInfo ) ;
235234 } ;
236235 reconcile ( ) ;
237- listener . onDidChange ( reconcile ) ;
236+ watchWorkspaceStatus ( this . workspaceID , ( response ) => {
237+ if ( response . status ) {
238+ reconcile ( response . status ) ;
239+ }
240+ } ) ;
238241 }
239242
240- private parseInfo ( workspace : WorkspaceInfo ) : IDEFrontendDashboardService . Info {
243+ private parseInfo ( status : WorkspaceStatus ) : IDEFrontendDashboardService . Info {
241244 return {
242245 loggedUserId : this . user ! . id ,
243246 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" ,
249252 credentialsToken : this . ideCredentials ,
250- ownerId : workspace . workspace . ownerId ,
253+ ownerId : this . workspace . metadata ?. ownerId ?? "" ,
251254 } ;
252255 }
253256
@@ -271,6 +274,7 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
271274 workspaceId : this . workspaceID ,
272275 type : this . latestInfo ?. workspaceType ,
273276 } ;
277+ // TODO:
274278 this . service . server . trackEvent ( msg ) ;
275279 }
276280
@@ -300,19 +304,6 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
300304 }
301305 }
302306
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-
316307 sendInfoUpdate ( info : IDEFrontendDashboardService . Info ) : void {
317308 this . clientWindow . postMessage (
318309 {
0 commit comments