0.273.0 • Published 7 months ago

js-flipper v0.273.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

js-flipper

This package exposes JavaScript bindings to talk from web / Node.js directly to flipper.

Installation

yarn add js-flipper

Usage

How to build Flipper plugins is explained in the flipper documentation: Creating a Flipper plugin. Building a Flipper plugin involves building a plugin for the Desktop app, and a plugin that runs on a Device (web or Node.js). This package is only needed for the plugin that runs on the device (web / Node.js), and wants to use the WebSocket connection to communicate to Flipper.

This package exposes a flipperClient. It has:

  • addPlugin method. It accepts a plugin parameter, that registers a client plugin and will fire the relevant callbacks if the corresponding desktop plugin is selected in the Flipper Desktop. The full plugin API is documented here.
  • start method. It starts the client. It has two arguments:
    • appName - (required) the name displayed in Flipper
    • options which conforms to the interface
      interface FlipperClientOptions {
        // Make the client connect to a different URL
        urlBase?: string;
        // Override WebSocket implementation (Node.js folks, it is for you!)
        websocketFactory?: (url: string) => FlipperWebSocket;
        // Override how errors are handled (it is simple `console.error` by default)
        onError?: (e: unknown) => void;
        // Timeout after which client tries to reconnect to Flipper
        reconnectTimeout?: number;
        // Set device ID. Default: random ID persisted to local storage.
        getDeviceId?: () => Promise<string> | string
      }

Example (web)

An example plugin can be found in FlipperTicTacToe.js.

The corresponding Desktop plugin ships by default in Flipper, so importing the above file and dropping the <FlipperTicTacToe /> component somewhere in your application should work out of the box.

The sources of the corresponding Desktop plugin can be found here.

Node.js

Node.js does not have a built-in WebSocket implementation. You need to install any implementation of WebSockets for Node.js that is compatible with the interface of the web version.

import flipperClient from 'js-flipper';
// Say, you decided to go with 'ws'
// https://github.com/websockets/ws
import WebSocket from 'ws';

// Start the client and pass some options
// You might ask yourself why there is the second argument `{ origin: 'localhost:' }`
// Flipper Desktop verifies the `Origin` header for every WS connection. You need to set it to one of the whitelisted values (see `VALID_WEB_SOCKET_REQUEST_ORIGIN_PREFIXES`).
flipperClient.start('My cool nodejs app', { websocketFactory: url => new WebSocket(url, {origin: 'localhost:'}) });

An example plugin should be somewhat similar to what we have for React. It is currently WIP (do not confuse with RIP!).

0.272.0

7 months ago

0.273.0

7 months ago

0.271.0

8 months ago

0.266.0

9 months ago

0.270.0

8 months ago

0.267.1

9 months ago

0.267.0

9 months ago

0.268.0

9 months ago

0.264.0

10 months ago

0.269.0

8 months ago

0.265.0

10 months ago

0.262.0

10 months ago

0.259.0

11 months ago

0.263.0

10 months ago

0.260.0

11 months ago

0.261.0

11 months ago

0.209.0

2 years ago

0.207.0

2 years ago

0.205.0

2 years ago

0.192.0

2 years ago

0.203.0

2 years ago

0.201.0

2 years ago

0.194.0

2 years ago

0.196.0

2 years ago

0.198.0

2 years ago

0.211.0

2 years ago

0.211.1

2 years ago

0.208.0

2 years ago

0.206.0

2 years ago

0.191.0

2 years ago

0.202.0

2 years ago

0.193.0

2 years ago

0.200.0

2 years ago

0.195.0

2 years ago

0.197.0

2 years ago

0.199.0

2 years ago

0.210.1

2 years ago

0.212.0

2 years ago

0.210.0

2 years ago

0.190.0

2 years ago

0.177.0

2 years ago

0.179.0

2 years ago

0.180.0

2 years ago

0.182.0

2 years ago

0.184.0

2 years ago

0.188.0

2 years ago

0.178.1

2 years ago

0.181.0

2 years ago

0.183.0

2 years ago

0.187.1

2 years ago

0.189.0

2 years ago

0.173.0

3 years ago

0.171.1

3 years ago

0.175.0

3 years ago

0.172.0

3 years ago

0.174.0

3 years ago

0.176.1

3 years ago

0.176.0

3 years ago

0.163.0

3 years ago

0.164.0

3 years ago

0.162.0

3 years ago

0.158.0

3 years ago

0.159.0

3 years ago

0.152.0

3 years ago

0.151.1

3 years ago

0.153.0

3 years ago

0.150.0

3 years ago

0.151.0

3 years ago

0.156.0

3 years ago

0.157.0

3 years ago

0.154.0

3 years ago

0.155.0

3 years ago

0.146.1

3 years ago

0.161.0

3 years ago

0.146.0

3 years ago

0.145.0

3 years ago

0.144.0

3 years ago

0.143.0

3 years ago

0.138.0

3 years ago

0.137.1

3 years ago

0.142.0

3 years ago

0.140.0

3 years ago

0.137.0

3 years ago

0.136.0

3 years ago

0.131.0

3 years ago

0.130.0

3 years ago

0.131.1

3 years ago

0.128.0

3 years ago

0.127.0

3 years ago

0.126.0

4 years ago

0.125.0

4 years ago

0.128.4

3 years ago

0.128.3

3 years ago

0.128.2

3 years ago

0.129.0

3 years ago

0.128.1

3 years ago

0.124.0

4 years ago

0.123.0

4 years ago

0.118.0

4 years ago

0.119.0

4 years ago

0.122.0

4 years ago

0.121.1

4 years ago

0.121.0

4 years ago

0.120.0

4 years ago

0.117.0

4 years ago

0.116.0

4 years ago