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

openframe-extension

v0.1.0

Published

Base Openframe Extension module.

Downloads

14

Readme

NOTE: The Openframe platform is in an early stage. The extension API may change significantly.

Openframe Extension

A base module used to create extensions for Openframe.

Openframe is an open source platform for displaying art. Frames running the Openframe controller software can load extensions which add functionality.

Developing an Extension

An extension is simply a node module which exports an instance of the Extension class. The Extension class constructor takes a single argument, a properties object which can be used to specify the extension's functionality.

The Extension class provides instance properties which give access to the REST API client (this.rest), the global event system (this.pubsub), and the frame model object (this.frame).

...

module.exports = new Extension({
    // props
});

...

Adding support for a new artwork format

An extension can add support for a new artwork 'format'. Conceptually, a format can be thought of as the 'media type' of the artwork, e.g. 'an image' or 'a shader'. A format defines how the frame controller should start and stop an artwork of its media type, and installs any dependencies that the media type needs in order to run.

Each artwork specifies exactly one format, and each frame can support any number of formats. Artworks can specify a config object which formats can use when determining how to display the artwork.

Each extension can define a single format.

To add a format, define a format property on the extension properties object:

...

module.exports = new Extension({
    format: {
        // the name should be the same as the npm package name
        'name': pjson.name,
        // displayed to the user, perhaps?
        'display_name': 'Image',
        // does this type of artwork need to be downloaded to the frame?
        'download': true,
        // how do start this type of artwork? currently two token replacements, $filepath and $url
        'start_command': function(config) {
            debug('Artwork config: ', config);
            var command = 'image-player';
            config = config || {};
            if (config.display_mode) {
                switch (config.display_mode) {
                    case 'contain':
                        command += ' --contain';
                        break;
                    case 'cover':
                        command += ' --cover';
                        break;
                }
            }
            command += ' $filepath';
            return command;
        },
        // how do we stop this type of artwork?
        'end_command': 'pkill image-player'
    }
});

...

The format definition object

To define a format, we need to specify five values:

name {String} A unique format name used by artworks to specify this format. We highly recommend using the npm package name in order to enforce uniqueness. E.g. 'openframe-glslviewer'

display_name {String} A human-friendly name for the format, e.g. 'Shader'

download {Boolean} Does the artwork need to be downloaded in order to run?

start_command {String | Function} A string command or function returning a string command which will be executed when starting an artwork. If a function, it will be passed a config object optionally defined on the artwork being started. The output command can contain two tokens, '$filepath' and '$url', which will be replaced by their respective values.

end_command {String} A string command executed when stopping an artwork.

For an example a format extension, see Openframe-glslViewer.

Adding hardware extensions to the frame

An extension can also add functionality to the frame itself. Extensions might be used to interact with the frame hardware, for example allowing for a custom input device to be used via GPIO. In other cases, an extension might add functionality that interacts directly with artworks, for example by sending OSC messages.

...

var gpio = require('onoff').Gpio;

module.exports = new Extension({
    init: function() {

        var button = new gpio(17, 'in', 'both'),    // add a button via GPIO
            pubsub = this.pubsub;                   // access to the global event system

        // when the button changes, publish an event
        button.watch(function(err, state) {
            if (err) debug(err);
            pubsub.publish('/openframe-gpio/17', state);
        });
    }
});

...

For an example frame extension, ~~see Openframe-GPIO~~ (we need to update this to the most recent extension structure).

Installing dependencies

If a extension requires NPM packages, they should be included in the package.json dependencies (as with any other npm package).

Some extensions may need to install other types of dependencies, or run other types of non-nodejs installation processes. We recommend using npm scripts to execute the install.sh shell script upon install. As a best practice, extensions that modify the system using install.sh should take care of undoing those changes using an uninstall.sh script, which is executed when the npm module is removed. See package.json, install.sh, and uninstall.sh.