Skip to content

Commit 0724392

Browse files
committed
initial scaffolding
1 parent 9bb4bed commit 0724392

File tree

7 files changed

+163
-2
lines changed

7 files changed

+163
-2
lines changed

app/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const Tone = require('tone')

index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>React Webpack Template Title</title>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
9+
<link rel="stylesheet" type="text/css" href="css/style.css">
10+
<script type="text/javascript" src="paper/paper-full.js"></script>
11+
<script type="text/paperscript" src="js/ui.js" canvas="paperCanvas"></script>
12+
</head>
13+
<body>
14+
<canvas id="paperCanvas"></canvas>
15+
<script type="text/javascript" src="js/bundle.js" charset="utf-8"></script>
16+
</body>
17+
</html>

package.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@
44
"description": "a tone.js and socket.io based collaborative music improv app",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build-watch": "webpack -w",
9+
"start": "nodemon server/index.js"
810
},
911
"author": "ian munro",
10-
"license": "ISC"
12+
"license": "ISC",
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/ianmunrobot/socketjam.git"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/ianmunrobot/socketjam/issues"
19+
},
20+
"homepage": "https://github.com/ianmunrobot/socketjam#readme",
21+
"dependencies": {
22+
"express": "^4.14.0",
23+
"http": "0.0.0",
24+
"paper": "^0.10.2",
25+
"path": "^0.12.7",
26+
"socket.io": "^1.7.2",
27+
"tone": "^0.9.0",
28+
"volleyball": "^1.4.1"
29+
}
1130
}

public/css/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* { margin: 0; padding: 0;}
2+
3+
body, html { height:100%; }
4+
5+
#paperCanvas {
6+
position:absolute;
7+
width:100%;
8+
height:100%;
9+
}

public/js/ui.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var height = window.innerHeight;
2+
var width = window.innerWidth;
3+
console.log(height);
4+
console.log(width);
5+
6+
var hCount = height/80;
7+
var wCount = width/80
8+
9+
var squarePath = new Path.Rectangle(new Point(20, 20), new Size(20, 20));
10+
squarePath.fillColor = 'aquamarine';
11+
var squareSymbol = new Symbol(squarePath);
12+
13+
// lets place some squares using symbols, and rotate each instance slightly
14+
var offset = 1;
15+
for (var j = 0; j < hCount; j++) {
16+
for (var i = 0; i < wCount; i++) {
17+
var placedSymbol = squareSymbol.place(new Point(20 + (i * 40), 20 + (50 * j)));
18+
placedSymbol.rotate(i * 10 + offset); // operation on the instance
19+
offset += 1 + Math.floor(Math.random() * 10)
20+
}
21+
offset += 1 + Math.floor(Math.random() * 10)
22+
}
23+
24+
function onFrame(event) {
25+
// Add 1 degree to the hue
26+
// of the symbol definition's fillColor:
27+
squareSymbol.definition.fillColor.hue += .01;
28+
// rotate
29+
squareSymbol.definition.rotate(0.3);
30+
}

server/index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const path = require('path');
2+
3+
const http = require('http');
4+
const server = http.createServer();
5+
const volleyball = require('volleyball')
6+
7+
const express = require('express');
8+
const app = express();
9+
10+
const socketio = require('socket.io');
11+
12+
server.on('request', app);
13+
14+
const io = socketio(server);
15+
16+
// store the current rooms' data
17+
const memory = {};
18+
19+
20+
server.listen(1337, () => console.log('The server is listening on port 1337!'));
21+
22+
let variable = path.join(__dirname, '../public')
23+
24+
// serve static files
25+
app.use('/paper', express.static(path.join(__dirname, '../node_modules/paper/dist')));
26+
app.use(express.static(path.join(__dirname, '../public')));
27+
28+
app.use(volleyball)
29+
30+
io.on('connection', socket => {
31+
console.log('New client connection');
32+
console.log(socket.id);
33+
// let roomName = req.params.roomName
34+
35+
// join room on create (room name is passed from client)
36+
socket.on('create', room => {
37+
socket.join(room)
38+
39+
if (!memory[room]) memory[room] = [];
40+
// iterate through memory, draw the board
41+
memory[room].forEach(el => {
42+
io.to(room).emit('otherDrawing', ...el)
43+
})
44+
45+
// on 'draw' add to memory and draw to others in room
46+
socket.to(room).on('draw', (...payload) => {
47+
memory[room].push(payload);
48+
io.to(room).emit('otherDrawing', ...payload)
49+
})
50+
51+
// log on disconnect
52+
socket.on('disconnect', () => {
53+
socket.leave(room);
54+
console.log('disconnect :()');
55+
});
56+
})
57+
});
58+
59+
app.use('/', (req, res) => {
60+
res.sendFile(path.join(__dirname, '../index.html'));
61+
});

webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
entry: "./app/index.js",
3+
output: {
4+
path: __dirname,
5+
filename: "./public/js/bundle.js"
6+
},
7+
context: __dirname,
8+
devtool: 'source-map',
9+
resolve: {
10+
extensions: ['', '.js', '.jsx']
11+
},
12+
module: {
13+
loaders: [
14+
{
15+
test: /\.css$/, loader: "style!css" ,
16+
exclude: /(node_modules|bower_components)/,
17+
loader: 'babel',
18+
query: {
19+
presets: ['es2015', 'stage-2']
20+
}
21+
}
22+
]
23+
},
24+
};

0 commit comments

Comments
 (0)