npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sap-devx/webview-rpc

v1.0.0

Published

An RPC library for VSCode WebViews

Downloads

17,479

Readme

CircleCI Coverage Status Commitizen friendly GitHub license REUSE status dependentbot

vscode-webview-rpc-lib

Description

Provides a conventient way to communicate between VSCode extension and its webviews. Use RPC calls to invoke functions on the webview, receive callbacks and vice versa.

Requirements

You need to have node.js installed on your machine. Also, to use this library, you need to run it inside a VSCode extension using VSCode or Theia.

How to use

An example of using this libary can be seen under the "example" folder.

Installation

  • Create VSCode extension with a Webview. To create your extension go to https://code.visualstudio.com/api/extension-guides/webview.
  • Install using npm
    npm install @sap-devx/webview-rpc
    This will install the library in your node_modules folder. The extension library can be used as any node.js module (with TypeScript). The webview library needs to be imported to your html.
  • Add the following script to the root html of your Webview
    <head>
        <script>var exports = {};</script>
        <script type="module" src="vscode-resource:/node_modules/@sap-devx/webview-rpc/out.browser/rpc-common.js"></script>
        <script type="module" src="vscode-resource:/node_modules/@sap-devx/webview-rpc/out.browser/rpc-browser.js"></script>
        <script type="module" src="vscode-resource:/out/media/main.js"></script>
    </head>

Initializations

Create new instance of the Rpc in the extension side and the Webview side

  • In the extension code use the following example to start new instance of the RpcExtension:
    this._rpc = new RpcExtension(this._panel.webview);
  • In the Webview JS code use the following example to start new instance of the RpcBrowser:
    const vscode = acquireVsCodeApi();
    let rpc = new RpcBrowser(window, vscode);

Register methods

In order to invoke an extension method from the webbiew or webview method from the extension, you will have to register the functions that can be invoked. Here is an example on how to register the methods

function add(a,b) {
    return a+b;
}

rpc.registerMethod({func: add});

Usage

To invoke a method use the invoke method on the rpc instance. You can pass a callback that will be invoked once the response received.
For version < 1.x :

rpc.invoke("add", [1,2]).then((response)=>{
    console.log("1+2="+response);
});

Since version 1.x :

rpc.invoke("add", 1,2).then((response)=>{
    console.log("1+2="+response);
});

Build and Development

To build for development purpose do the following:

  • Run "npm install" on the repo to download the project dependencies.
    npm install @sap-devx/webview-rpc
  • Run "npm run compile-ext" to compile the extension library sources to javascript. The compilation results will be on the directory "out.ext".
    npm run compile-ext
  • Run "npm run compile-browser" to compile the browser library sources to javascript. The compilation results will be on the directory "out.browser".
    npm run compile-browser
  • Run the test using "npm run test".
    npm run test

Known Issues

  • Browser library is does not generate d.ts files.

  • overcome Cors issue preventing post message to get through and hit the window: use the setHost method and sent the host name from the webview - and then the message should get through.

How to obtain support

  • To get more help, support and information please open a github issue.

Contributing

Contributing information can be found in the CONTRIBUTING.md file.

To-Do (upcoming changes)

  • remove the need to decalre exposed functions