space-dud
HTTP server plugin that routes events from input clients to output clients on different devices.
Last updated 2 years ago by mmazzocchi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install space-dud 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.7.6                                ...           latest (2 years ago)

27 Versions

  • 2.7.6                                ...           2 years ago
  • 2.7.5                                ...           2 years ago
  • 2.7.4                                ...           2 years ago
  • 2.7.3                                ...           2 years ago
  • 2.7.2                                ...           2 years ago
  • 2.7.1                                ...           2 years ago
  • 2.7.0                                ...           2 years ago
  • 2.6.0                                ...           3 years ago
  • 2.5.1                                ...           3 years ago
  • 2.5.0                                ...           3 years ago
  • 2.4.4                                ...           3 years ago
  • 2.4.3                                ...           3 years ago
  • 2.4.2                                ...           3 years ago
  • 2.4.1                                ...           3 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.2                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 3
Dependencies (4)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |