Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/frontend-dashboard-service.ts
2498 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { WorkspaceInstancePhase } from "./workspace-instance";
8
import { RemoteTrackMessage } from "./analytics";
9
10
/**
11
* IDEFrontendDashboardService enables IDE related communications
12
* between the workspace to gitpod origins. Use it to communicate
13
* between IDE and dashboard iframes, never use
14
* `window.postMessage` directly.
15
*
16
* **Security Note**: never expose information about other workspaces
17
* or sensitive information for the current workspace, i.e. owner token.
18
*/
19
export namespace IDEFrontendDashboardService {
20
/**
21
* IClient is the client side which is using in supervisor frontend
22
*/
23
export interface IClient {
24
trackEvent(msg: RemoteTrackMessage): void;
25
activeHeartbeat(): void;
26
setState(state: SetStateData): void;
27
openDesktopIDE(url: string): void;
28
}
29
30
/**
31
* IServer is the server side which is using in dashboard loading screen
32
*/
33
export interface IServer {
34
relocate(url: string): void;
35
sendInfoUpdate(info: Info): void;
36
openBrowserIDE(): void;
37
}
38
39
/**
40
* Info defined the information that `supervisor/frontend` requires.
41
*/
42
export interface Info {
43
workspaceID: string;
44
loggedUserId: string;
45
ownerId: string;
46
47
instanceId?: string;
48
ideUrl?: string;
49
statusPhase?: WorkspaceInstancePhase;
50
51
workspaceDescription: string;
52
workspaceType: string;
53
credentialsToken: string;
54
}
55
56
export interface SetStateData {
57
ideFrontendFailureCause?: string;
58
desktopIDE?: {
59
clientID: string;
60
link: string;
61
label?: string;
62
};
63
}
64
65
export interface InfoUpdateEventData {
66
// protocol version
67
version?: number;
68
type: "ide-info-update";
69
info: Info;
70
}
71
72
export interface FeatureFlagsUpdateEventData {
73
type: "ide-feature-flag-update";
74
flags: { supervisor_check_ready_retry: boolean };
75
}
76
77
export interface FeatureFlagsRequestEventData {
78
type: "ide-feature-flag-request";
79
}
80
81
export interface HeartbeatEventData {
82
type: "ide-heartbeat";
83
}
84
85
export interface TrackEventData {
86
type: "ide-track-event";
87
msg: RemoteTrackMessage;
88
}
89
90
export interface RelocateEventData {
91
type: "ide-relocate";
92
url: string;
93
}
94
95
export interface SetStateEventData {
96
type: "ide-set-state";
97
state: SetStateData;
98
}
99
100
export interface OpenBrowserIDE {
101
type: "ide-open-browser";
102
}
103
104
export interface OpenDesktopIDE {
105
type: "ide-open-desktop";
106
url: string;
107
}
108
109
export function isInfoUpdateEventData(obj: any): obj is InfoUpdateEventData {
110
return obj != null && typeof obj === "object" && obj.type === "ide-info-update";
111
}
112
113
export function isFeatureFlagsUpdateEventData(obj: any): obj is FeatureFlagsUpdateEventData {
114
return obj != null && typeof obj === "object" && obj.type === "ide-feature-flag-update";
115
}
116
117
export function isFeatureFlagsRequestEventData(obj: any): obj is FeatureFlagsRequestEventData {
118
return obj != null && typeof obj === "object" && obj.type === "ide-feature-flag-request";
119
}
120
121
export function isHeartbeatEventData(obj: any): obj is HeartbeatEventData {
122
return obj != null && typeof obj === "object" && obj.type === "ide-heartbeat";
123
}
124
125
export function isTrackEventData(obj: any): obj is TrackEventData {
126
return obj != null && typeof obj === "object" && obj.type === "ide-track-event";
127
}
128
129
export function isRelocateEventData(obj: any): obj is RelocateEventData {
130
return obj != null && typeof obj === "object" && obj.type === "ide-relocate";
131
}
132
133
export function isSetStateEventData(obj: any): obj is SetStateEventData {
134
return obj != null && typeof obj === "object" && obj.type === "ide-set-state";
135
}
136
137
export function isOpenBrowserIDE(obj: any): obj is OpenBrowserIDE {
138
return obj != null && typeof obj === "object" && obj.type === "ide-open-browser";
139
}
140
141
export function isOpenDesktopIDE(obj: any): obj is OpenDesktopIDE {
142
return obj != null && typeof obj === "object" && obj.type === "ide-open-desktop";
143
}
144
}
145
146