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

vue-remote

v1.0.8

Published

A websocket based remote event system for Vue.js 2.0

Downloads

16

Readme

vue-remote

A websocket based remote event system for Vue.js.

Works with Vue 2.0, untested with Vue 1.0.

Installation

1.) Install package via NPM
npm install vue-remote
2.) Activate plugin within project.
import Vue from 'vue';
import VueRemote from 'vue-remote';

Vue.use(
    VueRemote,
    {
        secure: false,
        host: "localhost",
        port: 8080,
        identifier: 'identifier'
    }
)

or

window.Vue = require('vue');
const VueRemote = require('vue-remote');

Vue.use(
    VueRemote,
    {
        secure: false,
        host: "localhost",
        port: 8080
    }
)

Usage

The Vue.Remote global object.

This plugin provides a direct interface into the websocket client using attach, detach, and emit functions.

The $remote prototype object.

This plugin provides a vm.$remote object with functionally based on Vue's event system with $on, $once, $off, and $emit.


A Note on $emit and emit functions, unlike the normal event system these calls send the information through the client and the server triggers the callback.


The remote component object

This plugin provides a mixin object remote which simplifies the attachment of server events.

Firing an event

There are 2 methods that fire events. They're functionally identical and only differ in name.

...
    this.$remote.$emit('trigger', ...Arguments)

    Vue.Remote.emit('trigger', ...Arguments)
...

The structure used by vue-remote is as follows

// One Argument
// Vue.Remote.emit('trigger', 5)
{
    "identifier": 'trigger',
    "arguments": 5
}

// One Argument which is an object
// Vue.Remote.emit('trigger', { 'data': 5, 'id': 10 })
{
    "identifier": 'trigger',
    "data": 5,
    "id": 10
}

// Two or more Arguments
// Vue.Remote.emit('trigger', 5, 10, 15)
{
    "identifier": 'trigger',
    "arguments": [
        5,
        10,
        15
    ]
}

Listening for an event

There are 3 methods that register event listeners. They're functionally identical and only differ in name.

...
    this.$remote.$on('trigger', function(data) {})
    
    Vue.Remote.attach('trigger', function(data) {}, thisArg)
    
    new Vue({
        remote: {
            trigger: function(data) {
                ...
            }
        }
    })
...

The structure expected by the client is as follows.

{
    "identifier": <identifier>,
    "data": <value to send into the function handler>
}

// example
{
    "identifier": 'trigger',
    "data": {
        "id": 10,
        "foo": "bar"
    }
}

server

vue-remote comes with a basic websocket server script based on the Websocket node package.

Usage

// testServer.js

const Server = require('vue-remote/server');

function messageHandler(message) {
    // message = {
    //    identifier: "trigger",
    //    arguments: [...]
    // }

    ... Handle Message object

    return {
        identifier: "trigger",
        data: "Handled Message"
    };
}

let socketServer = Server( messageHandler, [options]);

use node testServer.js to run the server.

Example

Vue-remote-chat is a quick chat example of the system in action.

License

MIT