js api improvements: responnders, communication protocol

Summary:
A few improvements to JS API:
1) non-dummy responders - now we can reply to flipper
2) respecting flipper communication protocol: getPlugins, getBackgroundplugins, init, deinit, execute

adding linters

Reviewed By: jknoxville

Differential Revision: D22307525

fbshipit-source-id: 2f629210f398d118cc0cb99097c9d473bb466e57
This commit is contained in:
Timur Valiev
2020-07-17 04:53:09 -07:00
committed by Facebook GitHub Bot
parent 3814c8fdfc
commit 7dbcfc89b0
8 changed files with 2069 additions and 87 deletions

View File

@@ -9,8 +9,6 @@
import {FlipperClient} from './api';
import type {FlipperPluginID, FlipperMethodID} from './api';
class FlipperWebviewClient extends FlipperClient {
_subscriptions: Map<string, (message: any) => void> = new Map();
_client: FlipperClient | null = null;
@@ -26,31 +24,14 @@ class FlipperWebviewClient extends FlipperClient {
bridge?.FlipperWebviewBridge.stop();
};
sendData = (plugin: FlipperPluginID, method: FlipperMethodID, data: any) => {
sendData = (data: any) => {
const bridge = (window as any).FlipperWebviewBridge;
bridge && bridge.sendFlipperObject(plugin, method, JSON.stringify(data));
};
subscribe = (
plugin: FlipperPluginID,
method: FlipperMethodID,
handler: (msg: any) => void,
) => {
this._subscriptions.set(plugin + method, handler);
bridge && bridge.sendFlipperObject(data);
};
isAvailable = () => {
return (window as any).FlipperWebviewBridge != null;
};
receive(plugin: FlipperPluginID, method: FlipperMethodID, data: string) {
const handler = this._subscriptions.get(plugin + method);
handler && handler(JSON.parse(data));
}
setClient(client: FlipperClient) {
this._client = client;
}
}
export function newWebviewClient(): FlipperClient {