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

space-dud

v2.7.6

Published

HTTP server plugin that routes events from input clients to output clients on different devices.

Downloads

70

Readme

space-dud

space-dud is a plugin that facilitates the streaming of game controller events from web clients on one device to web clients on other devices.

Installation

$ npm install space-dud

Usage

space-dud creates a tunnel from one web client to another, through a web server. When a gamepad is connected to the "controller" client, all events are captured and sent to the server. The server can then forward these events to the "display" client, or process them itself.

Server

space-dud provides a function which takes one argument: an HTTP service. Once given the HTTP service, all that's needed is to serve the clients.

Example index.js:

Hint: All these examples are in a runnable package in the space-dud repository!

const HOST = '0.0.0.0';
const PORT = 3000;

// Set up the express app and space-dud.
var express = require('express');
var app = express();
var http = require('http').Server(app);
var space_dud = require('space-dud')(http);

// On every event, pass it on to any connected consumers
var game = space_dud.getGame();
game.on('player_ready', function(player) {
  player.on('controller_event', player.sendEventToConsumers);
});

// Start the space-dud server.
space_dud.start();

// Serve the static files.
app.use('/space-dud-client.js', express.static(__dirname+'/space-dud-client.js'));
app.use('/controller.html', express.static(__dirname+'/controller.html'));
app.use('/display.html', express.static(__dirname+'/display.html'));

// Start the server.
http.listen(PORT, HOST, function(){
  console.log('listening on '+HOST+':'+PORT);
});

Clients

Controller Client

The controller client runs on a machine with a USB game controller attached. The controller must be compatible with the HTML5 gamepad API. Once connected, the server will provide the client with a player ID number. The client captures all gamepad events, and forwards them onto the server.

Example controller.html:

<!DOCTYPE html>
<html>
    <body>
        <p>Player ID: <span id="player_id">None</span></p>

        <input id="A" type="button" value="A"/>
        <input id="B" type="button" value="B"/>

        <script src="/space-dud-client.js"></script>
        <script>

var client = new SpaceDudClient.ControllerConnection();
client.on('player_id', function (player_id) {
    document.getElementById('player_id').innerHTML = player_id;
});

document.getElementById('A').onmousedown = function() {
    client.sendEvent(0, 'button', 1);
};
document.getElementById('A').onmouseup = function() {
    client.sendEvent(0, 'button', 0);
};
document.getElementById('B').onmousedown = function() {
    client.sendEvent(1, 'button', 1);
};
document.getElementById('B').onmouseup = function() {
    client.sendEvent(1, 'button', 0);
};

        </script>
    </body>
</html>

Display Client

The display client runs on the machine that is reacting to the controller events. Upon connection, the display client should send a player ID to the server. Once verified, the server will then begin streaming gamepad events to the display client.

Example display.html:

<!DOCTYPE html>
<html>
  <body>
    <p>Player ID: 
      <input id="player_id" type="text"/>
      <input id="submit_player_id" type="button" value="Submit"/>
    </p>
 
    <p>Last event received was: <span id="event">None</span>

    <script src="/space-dud-client.js"></script>
    <script>

var client = new DisplayConnection();
client.on('event', function(data) {
    document.getElementById('event').innerHTML = JSON.stringify(data);
});

document.getElementById('submit_player_id').onclick = function(e) {
    var player_id = document.getElementById('player_id').value;
    client.selectPlayer(player_id);
};

    </script>
  </body>
</html>

Logging

space-dud uses the debug package for logging. To view log messages, add the space-dud namespace to the DEBUG call.

$ DEBUG=space-dud* node index.js