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

ocf-plugin

v0.0.2

Published

This repository serves as the docs for Open Chat Framework Plugins.

Downloads

4

Readme

Open Chat Framework Plugin Assets

This repository serves as the docs for Open Chat Framework Plugins.

Building your first plugin

Plugin.js

The plugin entry file must be a file called plugin.js in the root directory. From this file you can require any other file as normal, but the entry must be plugin.js

Plugin Anatomy

Every plugin must return an object containing the property middleware or extends.

Middleware

Middleware allows you to transform payloads as they travel through the system. They are executed in order they are assigned.

The only valid properties of the middleware object are send and broadcast.

  • send is executed before the payload is sent over the network to the rest of the connected clients.
  • broadcast is executed when the client receives a payload from another client.
module.exports = (config) => {

    return {
        middleware: {
            send: 
                message: (payload, next) => {
                    payload.sentTime = new Date();
                    next(err, payload);
                }
            },
            broadcast: 
                message: (payload, next) -> {
                    payload.receiveTime = new Date();
                    next(err, payload);
                }
            }
        }
    };

}

The sub properties under send and broadcast are the events that will trigger the transformation.

For example, the plugin above will be executed when a message event is sent from the client.

someChat.send('message', {text: 'This triggers the ```send```` method before it\'s published over the wire.'});
someChat.on('message', (payload) => {

    // payload has been modified by the ```broadcast``` method before this was called
    console.log(payload.receiveTime);

});

#### Extends

You can also extend OCF objects and add new methods to them. For example,
this plugin adds a method called ```newMethod()``` to the ```OCF.Chat``` object.

```js
module.exports - {
    return {
        extends: {
            Chat: {
                construct: () => {
                    // this is called whenever a new Chat is created
                    // the Chat object is available through this.parent
                    console.log('I am extending', this.parent);
                }
                newMethod: (params) => {
                    // this is a new method that gets attached to Chat
                }
            }
        }
    }

}

When the plugin is installed, every instance of OCF.Chat will have a new method called newMethod(). You can call the method like someChat.newMethod().

Using Plugins

Node

It's super easy to use plugins in NodeJs. Just include the file like any other dependency and attach it to your OCF objects.

// include the plugin from the remote file
const myPlugin = require('plugin.js');

// create a new chatroom
let someChatroom = new OCF.Chat('new-channel');

// attach the plugin to the new chatroom
someChatroom.plugin(myPlugin(config));

Web

You'll need the ocf-plugin tool described in the next section to build the package for web.

Once you build the pckage you would include the plugin with a <script> tag like:

<script src="/web/plugin.js"></script>

And the plugin will be available under OpenChatFramework.plugin[namespace]. The namespace is defined in package.json and you can learn more about it in the next section.

Once the plugi is available, you can attach it to OCF objects like we do in the Node version.

let someChatroom = new OCF.Chat('new-channel');
someChatroom.plugin(OpenChatFramework.plugin.myPlugin(config));

Open Chat Framework Plugin Tool

This is a build tool for Open Chat Framework plugins. Because OCF works on the front and back end, the plugin system requires a standardized method for building for web.

This build process assures us that the plugin can be used identically on both web and nodeJS. It uses browserify to compile assets.

It's main features are:

  • Name spacing plugins to avoid collisions
  • Preventing global scope leak in browser
  • Consistent API for integration on web and node
  • Singular tests for web and node

Setup

Install the tool globally.

npm install ocf-plugin -g

Namespace

Define a namespace in package.json in an object called "open-chat-framework".

"main": "plugin.js",
"open-chat-framework": {
    "namespace": "emoji"
},

When used in a browser, this will provide your plugin as a property of the global OpenChatFramework.plugin property.

OpenChatFramework.plugin.emoji.

This helps to avoid collisions with global variables. Be careful to avoid collisions with other OCF plugins!

Run ocf-plugin

Then, just run ocf-plugin from the command line. This will bundle your plugin.js file and it's dependencies so it can be used on the web.

Tests

Tests are defined in test.js and should use the mocha test package with chai for consistency.