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

@hqer/appliance-plugin

v1.0.11

Published

[中文文档](https://github.com/hqer927/appliance-plugin/blob/master/READMA.zh-CN.md)

Downloads

726

Readme

appliance-plugin

中文文档

The plug-in is attached to the plug-in mechanism of white-web-sdk to achieve a set of whiteboard teaching AIDS, state synchronization, playback, scene switching and other functions still rely on white-web-sdk or window-manager.

Introduction

A whiteboard pencil drawing plugin based on SpriteJS as a rendering engine.

The following two demos are implemented in the example folder for reference only. | scenario | demo path | depends on | | :-- | :----: | :-- | | multi-window | example/src/multi.ts | @netless/window-manager、white-web-sdk | | white-board | example/src/single.ts | white-web-sdk |

Principle

  1. The plugin is mainly based on the 2D functionality of SpriteJS, supports webgl2 rendering, and is backward compatible with downgrades to webgl and canvas2d
  2. The plugin uses the dual webWorker+offscreenCanvas mechanism to process the drawing calculation + rendering logic in a separate worker thread. Does not occupy cpu tasks of the main thread.

Plugin usage

Install

npm install @netless/appliance-plugin 

Sign up for plugins

Plug-ins can support two scenarios, their access plug-in names are different:

  • Multi-window 'ApplianceMultiPlugin'
import { ApplianceMultiPlugin } from '@netless/appliance-plugin'; 
  • Single whiteboard 'ApplianceSinglePlugin'
import { ApplianceSinglePlugin } from '@netless/appliance-plugin'; 

workerjs file cdn deployment

We used two-worker concurrency to improve drawing efficiency, which improved it by more than 40% over single-thread efficiency. However, the common dependencies on the two worker files are repeated, so building directly into the package will greatly increase the package size. So we allow the workerjs file cdn deployment by simply deploying the file under @netless/appliance-plugin/cdn into the cdn and then configuring the c of the last two workerjs via the second parameter of getInstance in the plug-in, options.cdn The dn address is fine. This solves the problem of excessive package size

  • The total package is about 300kB, and the two wokerjs are 600kB each If you need to consider the size of the package you are building, select Configure cdn.

Access mode reference

Multi-window mode (Interconnecting with window-manager)

import '@netless/window-manager/dist/style.css'; 
import '@netless/appliance-plugin/dist/style.css'; 
import { WhiteWebSdk } from "white-web-sdk"; 
import { WindowManager } from "@netless/window-manager"; 
// All bundled
import { ApplianceMultiPlugin } from '@netless/appliance-plugin'; 
// cdn 
// The following steps are optional. If you use cdn, you do not need to import from dist. If you import from dist, you need to import resources and configure them to options.cdn in bolb inline form. Such as? raw, this requires packaging support,vite default support? raw,webpack needs to be configured.
import fullWorkerString from '@netless/appliance-plugin/dist/fullWorker.js?raw';
import subWorkerString from '@netless/appliance-plugin/dist/subWorker.js?raw';
const fullWorkerBlob = new Blob([fullWorkerString], {type: 'text/javascript'});
const fullWorkerUrl = URL.createObjectURL(fullWorkerBlob);
const subWorkerBlob = new Blob([subWorkerString], {type: 'text/javascript'});
const subWorkerUrl = URL.createObjectURL(subWorkerBlob);
 
const whiteWebSdk = new WhiteWebSdk(...) 
const room = await whiteWebSdk.joinRoom({ 
... 
invisiblePlugins: [WindowManager, ApplianceMultiPlugin], 
useMultiViews: true, 
}) 
const manager = await WindowManager.mount({ room , container:elm, chessboard: true, cursor: true, supportAppliancePlugin: true}); 
if (manager) { 
await manager.switchMainViewToWriter(); 
await ApplianceMultiPlugin.getInstance(manager,
        {
            options: {
                cdn: {
                    fullWorkerUrl,
                    subWorkerUrl,
                }
            }
        }
    ); 
} 

Single whiteboard (interconnection with white-web-sdk)

import { WhiteWebSdk } from "white-web-sdk"; 
// All bundled
import { ApplianceSinglePlugin, ApplianceSigleWrapper } from '@netless/appliance-plugin'; 
// The following steps are optional. If you use cdn, you do not need to import from dist. If you import from dist, you need to import resources and configure them to options.cdn in bolb inline form. Such as? raw, this requires packaging support,vite default support? raw,webpack needs to be configured.
import fullWorkerString from '@netless/appliance-plugin/dist/fullWorker.js?raw';
import subWorkerString from '@netless/appliance-plugin/dist/subWorker.js?raw';
const fullWorkerBlob = new Blob([fullWorkerString], {type: 'text/javascript'});
const fullWorkerUrl = URL.createObjectURL(fullWorkerBlob);
const subWorkerBlob = new Blob([subWorkerString], {type: 'text/javascript'});
const subWorkerUrl = URL.createObjectURL(subWorkerBlob);
 
const whiteWebSdk = new WhiteWebSdk(...) 
const room = await whiteWebSdk.joinRoom({ 
... 
invisiblePlugins: [ApplianceSinglePlugin], 
wrappedComponents: [ApplianceSigleWrapper] 
}) 
await ApplianceSinglePlugin.getInstance(room,
    {
        options: {
            cdn: {
                fullWorkerUrl,
                subWorkerUrl,
            }
        }
    }
); 

About ’?raw‘ webpack configuration

module: {
    rules: [
        // ...
        {
            test: /\.m?js$/,
            resourceQuery: { not: [/raw/] },
            use: [ ... ]
        },
        {
            resourceQuery: /raw/,
            type: 'asset/source',
        }
    ]
},

Call introduction

api introduction

The plugin re-implements some of the interfaces of the same name on room or Windows Manager, but internally we have re-injected them back into the original object via injectMethodToObject. No changes are required for external users. As follows:

    // Internal hack
    injectMethodToObject(windowmanager, 'undo');
    injectMethodToObject(windowmanager, 'redo');
    injectMethodToObject(windowmanager,'cleanCurrentScene');
    injectMethodToObject(windowmanager,'insertImage');
    injectMethodToObject(windowmanager,'completeImageUpload');
    injectMethodToObject(windowmanager,'lockImage');
    injectMethodToObject(room,'getImagesInformation');
    injectMethodToObject(room,'callbacks');
    injectMethodToObject(room,'screenshotToCanvasAsync');
    injectMethodToObject(room,'getBoundingRectAsync');
    injectMethodToObject(room,'scenePreviewAsync');
    injectMethodToObject(windowmanager.mainView,'setMemberState');
    // These we can see the call behavior through the front-end log, for example:
    // [ApplianceMultiPlugin] setMemberState
    // [ApplianceMultiPlugin] cleanCurrentScene

The following interfaces are involved:

  1. Interface on room
  • setMemberState
  • undo
  • redo
  • callbacks
  • insertImage
  • lockImage
  • completeImageUpload
  • getImagesInformation
  • cleanCurrentScene
  1. windowmanager upper interface
  • cleanCurrentScene
  1. The mainview interface of windowmanager
  • setMemberState
  • undo
  • redo
  • callbacks
  • insertImage
  • lockImage
  • completeImageUpload
  • getImagesInformation
  • cleanCurrentScene
  1. Customize
  • getBoundingRectAsync
  • screenshotToCanvasAsync
  • scenePreviewAsync
  • destroy

Configure parameters

getInstance(wm: WindowManager, adaptor: ApplianceAdaptor)

  • wm: WindowManager\room\player. In multi-window mode, you pass WindowManager, and in single-window mode, you pass room or player(whiteboard playback mode).
  • adaptor: configures the adapter.
    • options: AppliancePluginOptions; The cdn addresses of both workers must be configured.
          export type AppliancePluginOptions = { 
              /** cdn Configuration item */ 
              cdn: CdnOpt; 
              /** Synchronize data configuration items */ 
              syncOpt? : SyncOpt; 
              /** Canvas configuration item */ 
              canvasOpt? : CanvasOpt; 
          } 
    • cursorAdapter? : CursorAdapter; This parameter is optional. In single whiteboard mode, customize the mouse style.

Front-end debugging introduction

During the interconnection process, if you want to understand and track the internal status of the plug-in, you can view the internal data through the following console commands.

const applianPlugin = await ApplianceSinglePlugin.getInstance(...) 
applianPlugin.CurrentManager  // can see the package version number, internal state, etc 
applianPlugin.CurrentManager.ConsoleWorkerInfo () // can check information to draw on the worker