Implement JS flipper client
Summary: Standardize WS implementation for JS environments. Why do we need a separate server implementation for browsers? Browser targets cannot authenticate via the default certificate exchange flow. We need a dedicated client for them that works over an insecure channel (without the cert exchange). Major changes: 1. Renamed `flipper-js-client-sdk` to `js-flipper` for consistency with `react-native-flipper` 2. Updated `js-flipper` implementation to match our other existing clients Documentation will be updated in a separate subsequent PR. https://fb.quip.com/2mboA0xbgoxl Reviewed By: mweststrate Differential Revision: D31688105 fbshipit-source-id: 418aa80e0fd86361c089cf54b0d44a8b4f748efa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2be631ea4d
commit
9a47f41056
68
js/js-flipper/src/plugin.ts
Normal file
68
js/js-flipper/src/plugin.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export type FlipperPluginReceiverRes =
|
||||
| object
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| void;
|
||||
export type FlipperPluginReceiver = (
|
||||
data: any,
|
||||
) => FlipperPluginReceiverRes | Promise<FlipperPluginReceiverRes>;
|
||||
export interface FlipperPluginConnection {
|
||||
/**
|
||||
* Send an `execute` message to Flipper.
|
||||
* Here is what client sends over the wire:
|
||||
* { method: 'execute', params: { api: pluginID, method, params } }
|
||||
*
|
||||
* @param method Method name that needs to be executed by Flipper
|
||||
* @param params Any extra params required for the method execution
|
||||
*/
|
||||
send(method: string, params?: unknown): void;
|
||||
/**
|
||||
* Listen to messages for the method provided and execute a callback when one arrives.
|
||||
* Send response back to Flipper.
|
||||
* Read more about responses at https://fbflipper.com/docs/extending/new-clients#responding-to-messages
|
||||
*
|
||||
* @param method Method name that Flipper sent to the client
|
||||
* @param receiver A callback executed by the client when a message with the specified method arrives.
|
||||
* If this callback throws or returns a rejected Promise, client send an error message to Flipper.
|
||||
* If this callback returns any value (even undefined) synchronously, client sends it as a success message to Flipper.
|
||||
* If this callback returns a Promise, clients sends the value it is resolved with as a success message to Flipper.
|
||||
*/
|
||||
receive(method: string, receiver: FlipperPluginReceiver): void;
|
||||
}
|
||||
export interface FlipperPlugin {
|
||||
/**
|
||||
* @return The id of this plugin. This is the namespace which Flipper desktop plugins will call
|
||||
* methods on to route them to your plugin. This should match the id specified in your React
|
||||
* plugin.
|
||||
*/
|
||||
getId(): string;
|
||||
|
||||
/**
|
||||
* Called when a connection has been established. The connection passed to this method is valid
|
||||
* until {@link FlipperPlugin#onDisconnect()} is called.
|
||||
*/
|
||||
onConnect(connection: FlipperPluginConnection): void;
|
||||
|
||||
/**
|
||||
* Called when the connection passed to `FlipperPlugin#onConnect(FlipperConnection)` is no
|
||||
* longer valid. Do not try to use the connection in or after this method has been called.
|
||||
*/
|
||||
onDisconnect(): void;
|
||||
|
||||
/**
|
||||
* Returns true if the plugin is meant to be run in background too, otherwise it returns false.
|
||||
*/
|
||||
runInBackground?(): boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user