-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (32 loc) · 908 Bytes
/
index.js
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
37
38
39
40
41
42
var path = require("path");
var server = require("elm-expressway/lib/server");
var socket = require("elm-expressway/lib/socket");
var basePath = path.resolve(process.cwd());
var filename = path.resolve(basePath, "Pong", "Server.elm");
var pongSocketConfig = {
filename: filename,
basePath: basePath,
portDefaults: {
receiveInput: {
space: false,
dir1: 0,
dir2: 0,
delta: 0.0
}
},
onConnection: onConnection
};
var pongSocket = socket(pongSocketConfig);
pongSocket(server);
server.listen(8000, "0.0.0.0");
function onConnection(pongServer) {
return function(connection) {
pongServer.emitter.on("sendGameState", function(gameState) {
connection.write(gameState);
});
connection.on("data", function(rawInput) {
pongServer.emitter.emit("receiveInput", JSON.parse(rawInput));
});
connection.on("close", function() { });
};
}