Path: blob/main/components/gitpod-protocol/src/frontend-dashboard-service.ts
2498 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { WorkspaceInstancePhase } from "./workspace-instance";7import { RemoteTrackMessage } from "./analytics";89/**10* IDEFrontendDashboardService enables IDE related communications11* between the workspace to gitpod origins. Use it to communicate12* between IDE and dashboard iframes, never use13* `window.postMessage` directly.14*15* **Security Note**: never expose information about other workspaces16* or sensitive information for the current workspace, i.e. owner token.17*/18export namespace IDEFrontendDashboardService {19/**20* IClient is the client side which is using in supervisor frontend21*/22export interface IClient {23trackEvent(msg: RemoteTrackMessage): void;24activeHeartbeat(): void;25setState(state: SetStateData): void;26openDesktopIDE(url: string): void;27}2829/**30* IServer is the server side which is using in dashboard loading screen31*/32export interface IServer {33relocate(url: string): void;34sendInfoUpdate(info: Info): void;35openBrowserIDE(): void;36}3738/**39* Info defined the information that `supervisor/frontend` requires.40*/41export interface Info {42workspaceID: string;43loggedUserId: string;44ownerId: string;4546instanceId?: string;47ideUrl?: string;48statusPhase?: WorkspaceInstancePhase;4950workspaceDescription: string;51workspaceType: string;52credentialsToken: string;53}5455export interface SetStateData {56ideFrontendFailureCause?: string;57desktopIDE?: {58clientID: string;59link: string;60label?: string;61};62}6364export interface InfoUpdateEventData {65// protocol version66version?: number;67type: "ide-info-update";68info: Info;69}7071export interface FeatureFlagsUpdateEventData {72type: "ide-feature-flag-update";73flags: { supervisor_check_ready_retry: boolean };74}7576export interface FeatureFlagsRequestEventData {77type: "ide-feature-flag-request";78}7980export interface HeartbeatEventData {81type: "ide-heartbeat";82}8384export interface TrackEventData {85type: "ide-track-event";86msg: RemoteTrackMessage;87}8889export interface RelocateEventData {90type: "ide-relocate";91url: string;92}9394export interface SetStateEventData {95type: "ide-set-state";96state: SetStateData;97}9899export interface OpenBrowserIDE {100type: "ide-open-browser";101}102103export interface OpenDesktopIDE {104type: "ide-open-desktop";105url: string;106}107108export function isInfoUpdateEventData(obj: any): obj is InfoUpdateEventData {109return obj != null && typeof obj === "object" && obj.type === "ide-info-update";110}111112export function isFeatureFlagsUpdateEventData(obj: any): obj is FeatureFlagsUpdateEventData {113return obj != null && typeof obj === "object" && obj.type === "ide-feature-flag-update";114}115116export function isFeatureFlagsRequestEventData(obj: any): obj is FeatureFlagsRequestEventData {117return obj != null && typeof obj === "object" && obj.type === "ide-feature-flag-request";118}119120export function isHeartbeatEventData(obj: any): obj is HeartbeatEventData {121return obj != null && typeof obj === "object" && obj.type === "ide-heartbeat";122}123124export function isTrackEventData(obj: any): obj is TrackEventData {125return obj != null && typeof obj === "object" && obj.type === "ide-track-event";126}127128export function isRelocateEventData(obj: any): obj is RelocateEventData {129return obj != null && typeof obj === "object" && obj.type === "ide-relocate";130}131132export function isSetStateEventData(obj: any): obj is SetStateEventData {133return obj != null && typeof obj === "object" && obj.type === "ide-set-state";134}135136export function isOpenBrowserIDE(obj: any): obj is OpenBrowserIDE {137return obj != null && typeof obj === "object" && obj.type === "ide-open-browser";138}139140export function isOpenDesktopIDE(obj: any): obj is OpenDesktopIDE {141return obj != null && typeof obj === "object" && obj.type === "ide-open-desktop";142}143}144145146