0.5.59 • Published 11 months ago

imjoy-rpc v0.5.59

Weekly downloads
547
License
MIT
Repository
github
Last release
11 months ago

ImJoy RPC

Usage

Load the library to the browser

<script
  type="text/javascript"
  onload="imjoyRPC.setupRPC()"
  src="https://cdn.jsdelivr.net/npm/imjoy-rpc@0.3.35/dist/imjoy-rpc.min.js"
></script>

Or, you can use the npm module:

npm install imjoy-rpc
import { imjoyRPC } from 'imjoy-rpc';

imjoyRPC.setupRPC({name: 'My Awesome App'}).then(api => {

})

imjoyRPC.waitForInitialization

This function is used to setup a base frame for running plugins. It will send imjoyRPCReady signal to the imjoy-core and listen for the initialize signal. Once received, it will call setupRPC with the config from the imjoy-core:

<script
  type="text/javascript"
  onload="imjoyRPC.waitForInitialization()"
  src="https://cdn.jsdelivr.net/npm/imjoy-rpc@0.3.35/dist/imjoy-rpc.min.js"
></script>

If needed, the authentication will also be done in this step (see config below).

config

You can optionally pass a config object into the function imjoyRPC.waitForInitialization(config)

  • config.credential_required: boolean, whether your RPC app requires credentials
  • config.credential_fields: array(of object), what are the fields required for the credentials, the properties of the objects will be used to generate HTML <input> field, it should contain label, id, value(the default value), type(any type supported by <input>, e.g.: text, number, password). For example: [{id: 'username', label: 'User Name', value: '', type: 'text'}, {id: 'password', label: 'Password', value: '', type: 'password'}].
  • config.verify_credential: function, a function to check if the submitted credential is valid
  • config.target_origin: string, the target origin required to connect to the RPC app, it's mandatory to set an explicit origin.

imjoyRPC.setupRPC

Setup ImJoy RPC manually:

imjoyRPC.setupRPC({name: 'My Awesome App'}).then((api)=>{
    // use the api object to interact with imjoy-core
})

Configuration for setupRPC

  • name Name of your app

    Required

  • description Short description of your app

    Default: [TODO: add description for YOUR APP]

  • version Version of your app

    Default: "0.1.0"

  • allow_execution Allow code execution

    Default: false

  • target_origin Set the target origin for postMessage

    Default: *

  • enable_service_worker Enable service worker for cachine requirements

    Default: false

  • cache_requirements A callback function for caching requirements in the service worker

    Default: null

  • forwarding_functions A list of function names which will be exported automatically and forwarded to the remote api. Default: ["close", "on", "off", "emit"] for all plugins, window plugins will include additional ones: ["resize", "show", "hide", "refresh"]

Connect to Hypha

import { hyphaWebsocketClient } from "imjoy-rpc";

hyphaWebsocketClient.connectToServer({
  server_url: 'https://ai.imjoy.io',
}).then(async (api)=>{
  await api.register_service(
      {
          "id": "echo-service",
          "config":{
              "visibility": "public"
          },
          "type": "echo",
          echo( data ){
              console.log("Echo: ", data)
              return data
          }
      }
  )
})
0.5.54

1 year ago

0.5.55

1 year ago

0.5.52

1 year ago

0.5.53

1 year ago

0.5.50

1 year ago

0.5.51

1 year ago

0.5.59

11 months ago

0.5.56

1 year ago

0.5.57

12 months ago

0.5.49

1 year ago

0.5.48-post1

1 year ago

0.5.48

1 year ago

0.5.47

1 year ago

0.5.46

2 years ago

0.5.18

2 years ago

0.5.19

2 years ago

0.5.35-post0

2 years ago

0.5.43

2 years ago

0.5.44

2 years ago

0.5.41

2 years ago

0.5.42

2 years ago

0.5.19-post.1

2 years ago

0.5.40

2 years ago

0.5.32

2 years ago

0.5.33

2 years ago

0.5.30

2 years ago

0.5.31

2 years ago

0.5.38

2 years ago

0.5.39

2 years ago

0.5.36

2 years ago

0.5.34

2 years ago

0.5.35

2 years ago

0.5.18-alpha.0

2 years ago

0.5.18-alpha.2

2 years ago

0.5.18-alpha.1

2 years ago

0.5.21

2 years ago

0.5.22

2 years ago

0.5.20

2 years ago

0.5.27

2 years ago

0.5.28

2 years ago

0.5.25

2 years ago

0.5.26

2 years ago

0.5.23

2 years ago

0.5.24

2 years ago

0.5.16

3 years ago

0.5.14

3 years ago

0.5.15

3 years ago

0.5.10

3 years ago

0.5.11

3 years ago

0.5.12

3 years ago

0.5.13

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.9

3 years ago

0.5.0-a5

3 years ago

0.5.0-a2

3 years ago

0.3.42

3 years ago

0.3.41

3 years ago

0.3.40

4 years ago

0.5.0-alpha.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.39

4 years ago

0.3.38

4 years ago

0.3.37

4 years ago

0.3.36

4 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.3.35

4 years ago

0.3.34

4 years ago

0.3.33

4 years ago

0.3.32

4 years ago

0.3.31

4 years ago

0.3.29

4 years ago

0.3.28

4 years ago

0.3.27

4 years ago

0.3.26

4 years ago

0.3.25

4 years ago

0.3.24

4 years ago

0.3.20

4 years ago

0.3.22

4 years ago

0.3.21

4 years ago

0.3.19

4 years ago

0.3.18

4 years ago

0.3.17

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.0

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.4

4 years ago

0.2.41

4 years ago

0.2.40

4 years ago

0.3.9

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.2.42

4 years ago

0.2.32

4 years ago

0.2.31

5 years ago

0.2.30

5 years ago

0.2.29

5 years ago

0.2.28

5 years ago

0.2.27

5 years ago

0.2.26

5 years ago

0.2.25

5 years ago

0.2.25-rc0

5 years ago

0.2.24-rc2

5 years ago

0.2.24-rc3

5 years ago

0.2.24

5 years ago

0.2.24-rc1

5 years ago

0.2.24-rc

5 years ago

0.2.23

5 years ago

0.2.22

5 years ago

0.2.20

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.1

5 years ago

0.2.2

5 years ago

0.2.0

5 years ago

0.1.18

5 years ago

0.1.13

5 years ago

0.1.14

5 years ago

0.1.15

5 years ago

0.1.16

5 years ago

0.1.17

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.8

5 years ago

0.1.9

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.4

5 years ago

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago