Intergrate ServerAddOn with PluginManager

Reviewed By: lblasa

Differential Revision: D34042338

fbshipit-source-id: 2ae3992738e647075f19c4dba0ebfb01e6c12b8f
This commit is contained in:
Andrey Goncharov
2022-02-28 03:50:34 -08:00
committed by Facebook GitHub Bot
parent 016299b374
commit a60865f0be
3 changed files with 41 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ import {
getInstalledPlugin,
installPluginFromNpm,
} from 'flipper-plugin-lib';
import {ServerAddOn} from './ServerAddOn';
const maxInstalledPluginVersionsToKeep = 2;
@@ -43,6 +44,8 @@ const getTempDirName = promisify(tmp.dir) as (
) => Promise<string>;
export class PluginManager {
private readonly serverAddOns = new Map<string, ServerAddOn>();
async start() {
// This needn't happen immediately and is (light) I/O work.
setTimeout(() => {
@@ -154,9 +157,32 @@ export class PluginManager {
async startServerAddOn(pluginName: string) {
console.debug('PluginManager.startServerAddOn', pluginName);
// TODO: Get owner from websocket connection ID
const fakeOwner = 'test';
const existingServerAddOn = this.serverAddOns.get(pluginName);
if (existingServerAddOn) {
console.debug(
'PluginManager.startServerAddOn -> already started, adding an owner',
pluginName,
fakeOwner,
);
existingServerAddOn.addOwner(fakeOwner);
return;
}
const newServerAddOn = await ServerAddOn.start(pluginName, fakeOwner);
this.serverAddOns.set(pluginName, newServerAddOn);
}
async stopServerAddOn(pluginName: string) {
stopServerAddOn(pluginName: string) {
console.debug('PluginManager.stopServerAddOn', pluginName);
const serverAddOn = this.serverAddOns.get(pluginName);
if (!serverAddOn) {
console.debug('PluginManager.stopServerAddOn -> not started', pluginName);
return;
}
// TODO: Get owner from websocket connection ID
const fakeOwner = 'test';
serverAddOn.removeOwner(fakeOwner);
}
}