Delete communicating and move the missing info into js-plugin-api
Summary: Documents init in the API reference and deletes the now redundant communicating page. Reviewed By: danielbuechele Differential Revision: D15198128 fbshipit-source-id: a9b88632b74edd7d9656ed888192db1fbe7f3642
This commit is contained in:
committed by
Facebook Github Bot
parent
f72e4b5122
commit
d5573644ac
@@ -1,42 +0,0 @@
|
|||||||
---
|
|
||||||
id: communicating
|
|
||||||
title: Device Communication
|
|
||||||
sidebar_label: Device Communication
|
|
||||||
---
|
|
||||||
|
|
||||||
To start communicating with a client your plugin must implement the init function. Once this function has been called the active client can also be accessed via `this.client`. This `id` of the plugin in JavaScript must match the native plugin `id` to allow for them to communicate.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
class extends FlipperPlugin {
|
|
||||||
static title = "MyPlugin";
|
|
||||||
static id = "MyPlugin";
|
|
||||||
|
|
||||||
init() {
|
|
||||||
// Setup subscriptions etc using this.client
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
There are three main ways your desktop plugin can communicate with connected devices.
|
|
||||||
|
|
||||||
## Remote method calls
|
|
||||||
|
|
||||||
With remote method calls your plugin can call a method on the attached client. This is useful for querying information from the client that your plugin wants to display. The first parameter is the name of the client API and the second is the specific method on that API. Optionally a JSON object can be passed as an argument to the client.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
this.client.call('methodName', data).then(res => {
|
|
||||||
// res contains client response
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
This function returns a promise so that you can await a potential response from the client. This also gives you the opportunity to handle or report errors encountered by the client using `Promise.catch`.
|
|
||||||
|
|
||||||
## Subscriptions
|
|
||||||
|
|
||||||
A client is not only able to respond to method calls but also push data directly to the Flipper desktop app. With the subscribe API your plugin can subscribe to data pushed from the client. Pass the name of the method and the API it is part of as well as a callback function to start a subscription. Any time the client sends a push matching this method the callback will be called with any attached data as a javascript object.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
this.client.subscribe('methodName', data => {
|
|
||||||
// data contains any payload sent by the client
|
|
||||||
});
|
|
||||||
```
|
|
||||||
@@ -9,14 +9,17 @@ Provided a plugin is setup as defined in [JS Plugin Definiton](js-setup), the ba
|
|||||||
|
|
||||||
Below is a reference of the APIs available to the `FlipperPlugin` class.
|
Below is a reference of the APIs available to the `FlipperPlugin` class.
|
||||||
|
|
||||||
|
## init()
|
||||||
|
`FlipperPlugin` has an `init()` method which can be overridden by plugins. Use this to make any initial calls to the client, and set up subscriptions. Only after `init()` is called will the `client` object be set.
|
||||||
|
|
||||||
## Client
|
## Client
|
||||||
|
|
||||||
This object is provided for communicating with the client plugin, and is accessible using `this.client` inside `FlipperPlugin`. Methods called on it will be routed to the client plugin with the same identifier as the JS plugin.
|
This object is provided for communicating with the client plugin, and is accessible using `this.client` inside `FlipperPlugin` after `init()` has been called. Methods called on it will be routed to the client plugin with the same identifier as the JS plugin.
|
||||||
|
|
||||||
### call
|
### call
|
||||||
`client.call(method: string, params: Object): Promise<Object>`
|
`client.call(method: string, params: Object): Promise<Object>`
|
||||||
|
|
||||||
Call a method on your client plugin implementation.
|
Call a method on your client plugin implementation. Call `.catch()` on the returned promise to handle any errors returned from the client.
|
||||||
|
|
||||||
### subscribe
|
### subscribe
|
||||||
`client.subscribe(method: string, callback: (Object => void)): void`
|
`client.subscribe(method: string, callback: (Object => void)): void`
|
||||||
|
|||||||
@@ -12,10 +12,6 @@
|
|||||||
"extending/arch": {
|
"extending/arch": {
|
||||||
"title": "Architecture"
|
"title": "Architecture"
|
||||||
},
|
},
|
||||||
"extending/communicating": {
|
|
||||||
"title": "Device Communication",
|
|
||||||
"sidebar_label": "Device Communication"
|
|
||||||
},
|
|
||||||
"extending/create-plugin": {
|
"extending/create-plugin": {
|
||||||
"title": "Mobile Setup"
|
"title": "Mobile Setup"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"extending/js-setup",
|
"extending/js-setup",
|
||||||
"extending/js-plugin-api",
|
"extending/js-plugin-api",
|
||||||
"extending/create-table-plugin",
|
"extending/create-table-plugin",
|
||||||
"extending/communicating",
|
|
||||||
"extending/ui-components",
|
"extending/ui-components",
|
||||||
"extending/styling-components",
|
"extending/styling-components",
|
||||||
"extending/create-plugin",
|
"extending/create-plugin",
|
||||||
|
|||||||
Reference in New Issue
Block a user