Files
flipper/flipper-js-client-sdk/src/example.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

59 lines
1.3 KiB
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, FlipperConnection, FlipperPlugin} from './api';
import {newWebviewClient} from './webviewImpl';
export class SeaMammalPlugin implements FlipperPlugin {
protected connection: FlipperConnection | null | undefined;
onConnect(connection: FlipperConnection): void {
this.connection = connection;
}
onDisconnect(): void {
this.connection = null;
}
getId(): string {
return 'sea-mammals';
}
runInBackground(): boolean {
return true;
}
newRow(row: {id: string; url: string; title: string}) {
this.connection?.send('newRow', row);
}
}
class FlipperManager {
flipperClient: FlipperClient;
seaMammalPlugin: SeaMammalPlugin;
constructor() {
this.flipperClient = newWebviewClient();
this.seaMammalPlugin = new SeaMammalPlugin();
this.flipperClient.addPlugin(this.seaMammalPlugin);
this.flipperClient.start('Example JS App');
}
}
let flipperManager: FlipperManager | undefined;
export function init() {
if (!flipperManager) {
flipperManager = new FlipperManager();
}
}
export function flipper(): FlipperManager | undefined {
return flipperManager;
}