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

@soundworks/plugin-platform-init

v1.0.0-alpha.5

Published

soundworks plugin to simplify initialization of certain client features

Downloads

38

Readme

soundworks | plugin platform init

npm version

soundworks plugin to handle initialization of browser client features that require a user interaction such as resuming audio context, etc.

Tutorial: https://soundworks.dev/tutorials/plugin-platform-init.html

Table of Contents

Installation

npm install @soundworks/plugin-platform-init --save

Usage

Server

// src/server/index.js
import { Server } from '@soundworks/core/server.js';
import platformInitPlugin from '@soundworks/plugin-platform-init/server.js';

const server = new Server(config);
// 
server.pluginManager.register('platform-init', platformInitPlugin);

Client

// src/clients/**/index.js
import { Client } from '@soundworks/core/client.js';
import platformInitPlugin from '@soundworks/plugin-platform-init/client.js';

const audioContext = new AudioContext();

const client = new Client(config);
// pass the audio context to the plugin will automatically generate a landing page 
// for resuming the audio context
client.pluginManager.register('platform-init', platformInitPlugin, { audioContext });

await client.start();

console.log(audioContext.state === 'running');

Available features

By default, the @soundworks/plugin-platform-init provide a way to resume audio context (as shown above) but also to access microphone, camera streams, and motion sensors throught the @ircam/devicemotion package.

npm install --save @ircam/devicemotion
// src/clients/**/index.js
import { Client } from '@soundworks/core/client.js';
import platformInitPlugin from '@soundworks/plugin-platform-init/client.js';
import devicemotion from '@ircam/devicemotion';

const client = new Client(config);

client.pluginManager.register('platform-init', platformInitPlugin, { 
  microphone: true,
  camera: true,
  devicemotion,
});

await client.start();

const platformInit = await client.pluginManager.get('platform-init');

const micStream = platformInit.get('microphone');
const cameraStream = platformInit.get('camera');
devicemotion.addEventListener(e => console.log(e));

Note that these additional features require a https connection.

You can also add any arbitraty logic by passing a function to the onCheck and onActivate options:

let onCheckCalled = false;
let onActivateCalled = false;

client.pluginManager.register('platform-init', platformInitPlugin, {
  onCheck: (plugin) => {
    onCheckCalled = true;
    return Promise.resolve();
  },
  onActivate: (plugin) => {
    onActivateCalled = true;
    return Promise.resolve();
  }
});

API

Classes

PluginPlatformInitClient

Client-side representation of the soundworks' platform init plugin.

Kind: global class

new PluginPlatformInitClient()

The constructor should never be called manually. The plugin will be instantiated by soundworks when registered in the pluginManager

Available options:

  • audioContext {AudioContext} - instance audio context to be resumed aliases: ['webaudio', 'audio-context', 'audioContext']
  • devicemotion {DeviceMotion} - @ircam/devicemotion module. aliases: ['devicemotion', 'device-motion']
  • micro {Boolean} - create a microphone stream with all feature (i.e. echoCancellation, noiseReduction, autoGainControl) set to false.
    • aliases: ['mic', 'micro']
    • todo: implement deviceId
  • video {Boolean} - create a camera stream
    • todo: implement deviceId
  • onCheck {Function} - function executed when the plugin is started to check for example if the feature is available. The provided function should return a Promise.
  • onActive {Function} - function executed on the user gesture to init a feature. The provided function should return a Promise.

Example

client.pluginManager.register('platform-init', platformInitPlugin, { audioContext });

pluginPlatformInitClient.onUserGesture()

Method to be executed by the application on the first user gesture. Calling this method several times will result in a no-op after the first call.

By default, this method is automatically called by the soundworks launcher, you should not have to call it manually in most cases.

Kind: instance method of PluginPlatformInitClient
Example

myView.addEventListener((e) => {
  platformPlugin.onUserGesture(e);
});

pluginPlatformInitClient.get(featureId)

Returns the poayload associated to a given feature.

Kind: instance method of PluginPlatformInitClient

| Param | Type | Description | | --- | --- | --- | | featureId | String | Id of the feature as given when the plugin was registered |

PluginPlatformInitServer

Client-side representation of the soundworks' platform init plugin.

Kind: global class

Credits

https://soundworks.dev/credits.html

License

BSD-3-Clause