2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { ErrorNoTelemetry } from '../../../base/common/errors.js';
7
>
import { Event } from '../../../base/common/event.js';
8
>
import { URI } from '../../../base/common/uri.js';
9
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
10
>
11
>
export const IRemoteAuthorityResolverService = createDecorator<IRemoteAuthorityResolverService>('remoteAuthorityResolverService');
12
>
13
>
export const enum RemoteConnectionType {
14
>
WebSocket,
15
>
Managed
16
>
}
17
>
18
>
export class ManagedRemoteConnection {
19
>
public readonly type = RemoteConnectionType.Managed;
20
>
21
>
constructor(
22
public readonly id: number
23
) { }
25
>
public toString(): string {
26
return `Managed(${this.id})`;
27
}
29
>
30
>
export class WebSocketRemoteConnection {
31
>
public readonly type = RemoteConnectionType.WebSocket;
32
>
33
>
constructor(
34
public readonly host: string,
35
public readonly port: number,
36
) { }
38
>
public toString(): string {
39
return `WebSocket(${this.host}:${this.port})`;
40
}
42
>
43
>
export type RemoteConnection = WebSocketRemoteConnection | ManagedRemoteConnection;
44
>
45
>
export type RemoteConnectionOfType<T extends RemoteConnectionType> = RemoteConnection & { type: T };
46
>
47
>
export interface ResolvedAuthority {
48
>
readonly authority: string;
49
>
readonly connectTo: RemoteConnection;
50
>
readonly connectionToken: string | undefined;
51
>
}
52
>
53
>
export interface ResolvedOptions {
54
>
readonly extensionHostEnv?: { [key: string]: string | null };
55
>
readonly isTrusted?: boolean;
56
>
readonly authenticationSession?: { id: string; providerId: string };
57
>
}
58
>
59
>
export interface TunnelDescription {
60
>
remoteAddress: { port: number; host: string };
61
>
localAddress: { port: number; host: string } | string;
62
>
privacy?: string;
63
>
protocol?: string;
64
>
}
65
>
export interface TunnelPrivacy {
66
>
themeIcon: string;
67
>
id: string;
68
>
label: string;
69
>
}
70
>
export interface TunnelInformation {
71
>
environmentTunnels?: TunnelDescription[];
72
>
features?: {
73
>
elevation: boolean;
74
>
public?: boolean;
75
>
privacyOptions: TunnelPrivacy[];
76
>
protocol: boolean;
77
>
};
78
>
}
79
>
80
>
export interface ResolverResult {
81
>
authority: ResolvedAuthority;
82
>
options?: ResolvedOptions;
83
>
tunnelInformation?: TunnelInformation;
84
>
}
85
>
86
>
export interface IRemoteConnectionData {
87
>
connectTo: RemoteConnection;
88
>
connectionToken: string | undefined;
89
>
}
90
>
91
>
export enum RemoteAuthorityResolverErrorCode {
92
>
Unknown = 'Unknown',
93
>
NotAvailable = 'NotAvailable',
94
>
TemporarilyNotAvailable = 'TemporarilyNotAvailable',
95
>
NoResolverFound = 'NoResolverFound',
96
>
InvalidAuthority = 'InvalidAuthority'
97
>
}
98
>
99
>
export class RemoteAuthorityResolverError extends ErrorNoTelemetry {
100
>
101
>
public static isNotAvailable(err: any): boolean {
102
return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.NotAvailable;
103
}
105
>
public static isTemporarilyNotAvailable(err: any): boolean {
106
return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.TemporarilyNotAvailable;
107
}
109
>
public static isNoResolverFound(err: any): err is RemoteAuthorityResolverError {
110
return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.NoResolverFound;
111
}
113
>
public static isInvalidAuthority(err: any): boolean {
114
return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.InvalidAuthority;
115
}
117
>
public static isHandled(err: any): boolean {
118
return (err instanceof RemoteAuthorityResolverError) && err.isHandled;
119
}
121
>
public readonly _message: string | undefined;
122
>
public readonly _code: RemoteAuthorityResolverErrorCode;
123
>
public readonly _detail: unknown;
124
>
125
>
public isHandled: boolean;
126
>
127
>
constructor(message?: string, code: RemoteAuthorityResolverErrorCode = RemoteAuthorityResolverErrorCode.Unknown, detail?: unknown) {
128
super(message);
129