8
8
User , WorkspaceInfo , WorkspaceCreationResult , UserMessage , WorkspaceInstanceUser ,
9
9
WhitelistedRepository , WorkspaceImageBuild , AuthProviderInfo , Branding , CreateWorkspaceMode ,
10
10
Token , UserEnvVarValue , ResolvePluginsParams , PreparePluginUploadParams , Terms ,
11
- ResolvedPlugins , Configuration , InstallPluginsParams , UninstallPluginParams , UserInfo , GitpodTokenType ,
11
+ ResolvedPlugins , Configuration , InstallPluginsParams , UninstallPluginParams , UserInfo , GitpodTokenType ,
12
12
GitpodToken , AuthProviderEntry , GuessGitTokenScopesParams , GuessedGitTokenScopes
13
13
} from './protocol' ;
14
14
import { JsonRpcProxy , JsonRpcServer } from './messaging/proxy-factory' ;
@@ -189,7 +189,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
189
189
tsGetSlots ( ) : Promise < TeamSubscriptionSlotResolved [ ] > ;
190
190
tsGetUnassignedSlot ( teamSubscriptionId : string ) : Promise < TeamSubscriptionSlot | undefined >
191
191
tsAddSlots ( teamSubscriptionId : string , quantity : number ) : Promise < void > ;
192
- tsAssignSlot ( teamSubscriptionId : string , teamSubscriptionSlotId : string , identityStr : string | undefined ) : Promise < void >
192
+ tsAssignSlot ( teamSubscriptionId : string , teamSubscriptionSlotId : string , identityStr : string | undefined ) : Promise < void >
193
193
tsReassignSlot ( teamSubscriptionId : string , teamSubscriptionSlotId : string , newIdentityStr : string ) : Promise < void > ;
194
194
tsDeactivateSlot ( teamSubscriptionId : string , teamSubscriptionSlotId : string ) : Promise < void > ;
195
195
tsReactivateSlot ( teamSubscriptionId : string , teamSubscriptionSlotId : string ) : Promise < void > ;
@@ -402,7 +402,7 @@ export class WorkspaceInstanceUpdateListener {
402
402
private readonly onDidChangeEmitter = new Emitter < void > ( ) ;
403
403
readonly onDidChange = this . onDidChangeEmitter . event ;
404
404
405
- private source : 'sync' | 'update' = 'sync' ;
405
+ private source : 'sync' | 'update' = 'sync' ;
406
406
407
407
get info ( ) : WorkspaceInfo {
408
408
return this . _info ;
@@ -494,11 +494,15 @@ export class WorkspaceInstanceUpdateListener {
494
494
495
495
}
496
496
497
+ export interface GitpodServiceOptions {
498
+ onReconnect ?: ( ) => ( void | Promise < void > )
499
+ }
500
+
497
501
export class GitpodServiceImpl < Client extends GitpodClient , Server extends GitpodServer > {
498
502
499
503
private readonly compositeClient = new GitpodCompositeClient < Client > ( ) ;
500
504
501
- constructor ( public readonly server : JsonRpcProxy < Server > ) {
505
+ constructor ( public readonly server : JsonRpcProxy < Server > , private options ?: GitpodServiceOptions ) {
502
506
server . setClient ( this . compositeClient ) ;
503
507
server . onDidOpenConnection ( ( ) => this . compositeClient . notifyDidOpenConnection ( ) ) ;
504
508
server . onDidCloseConnection ( ( ) => this . compositeClient . notifyDidCloseConnection ( ) ) ;
@@ -518,6 +522,12 @@ export class GitpodServiceImpl<Client extends GitpodClient, Server extends Gitpo
518
522
this . instanceListeners . set ( workspaceId , listener ) ;
519
523
return listener ;
520
524
}
525
+
526
+ async reconnect ( ) : Promise < void > {
527
+ if ( this . options ?. onReconnect ) {
528
+ await this . options . onReconnect ( ) ;
529
+ }
530
+ }
521
531
}
522
532
523
533
export function createGitpodService < C extends GitpodClient , S extends GitpodServer > ( serverUrl : string | Promise < string > ) {
@@ -535,6 +545,11 @@ export function createGitpodService<C extends GitpodClient, S extends GitpodServ
535
545
}
536
546
537
547
const connectionProvider = new WebSocketConnectionProvider ( ) ;
538
- const gitpodServer = connectionProvider . createProxy < S > ( url ) ;
539
- return new GitpodServiceImpl < C , S > ( gitpodServer ) ;
548
+ let onReconnect = ( ) => { } ;
549
+ const gitpodServer = connectionProvider . createProxy < S > ( url , undefined , {
550
+ onListening : socket => {
551
+ onReconnect = ( ) => socket . reconnect ( ) ;
552
+ }
553
+ } ) ;
554
+ return new GitpodServiceImpl < C , S > ( gitpodServer , { onReconnect } ) ;
540
555
}
0 commit comments