forked from jehervy/node-virtual-gamepads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.coffee
36 lines (28 loc) · 945 Bytes
/
main.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
###
Created by MIROOF on 04/03/2015
Virtual gamepad application
###
uinput = require './lib/uinput'
path = require('path')
express = require('express')
app = express()
http = require('http').Server(app)
io = require('socket.io')(http)
config = require './config.json'
gamepad_hub = require './app/virtual_gamepad_hub'
hub = new gamepad_hub()
app.use(express.static(__dirname + '/public'));
io.on 'connection', (socket) ->
socket.on 'disconnect', () ->
if socket.gamePadId != undefined
hub.disconnectGamepad socket.gamePadId, () ->
socket.on 'connectGamepad', () ->
hub.connectGamepad (gamePadId) ->
if gamePadId != -1
socket.gamePadId = gamePadId
socket.emit 'gamepadConnected', {padId: gamePadId}
socket.on 'padEvent', (data) ->
if socket.gamePadId != undefined and data
hub.sendEvent socket.gamePadId, data
http.listen config.port, () ->
console.info "Listening on #{config.port}"