Files
flipper/flipper-js-client-sdk/src/webviewImpl.ts
Timur Valiev 7dbcfc89b0 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
2020-07-17 04:54:44 -07:00

40 lines
1008 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {FlipperClient} from './api';
class FlipperWebviewClient extends FlipperClient {
_subscriptions: Map<string, (message: any) => void> = new Map();
_client: FlipperClient | null = null;
start = (appName: string) => {
const bridge = (window as any).FlipperWebviewBridge;
bridge?.registerPlugins(this.plugins);
bridge?.start(appName);
};
stop = () => {
const bridge = (window as any).FlipperWebviewBridge;
bridge?.FlipperWebviewBridge.stop();
};
sendData = (data: any) => {
const bridge = (window as any).FlipperWebviewBridge;
bridge && bridge.sendFlipperObject(data);
};
isAvailable = () => {
return (window as any).FlipperWebviewBridge != null;
};
}
export function newWebviewClient(): FlipperClient {
return new FlipperWebviewClient();
}