0.0.20 • Published 10 years ago
socket-screen v0.0.20
Server
const io = require('socket.io')(80);
const ss = require('socket-screen')(io);
// That's really it.
Receiver
const io = require('socket.io-client');
const ss = require('socket-screen/client')(io);
ss.create((err, session) => {
// Now we have a new session on the server. The user also needs to join the
// session on their smartphone before the full interaction is there.
if (!err) console.log(`join session ${session} on your second device`);
});
// Listen for when the second screen is paired up.
ss.on('pair', () => console.log('all set to go'));
ss.on('unpair', () => console.log('beep boop no input'));
// Listen for updates from the second screen.
ss.on('update', (message) => {
let { x, y } = message.touch;
console.log(`touched ${x}, ${y}`);
});
Sender
const io = require('socket.io-client');
const ss = require('socket-screen/client')(io);
let session = prompt("What's your session?");
ss.join(session, (err, session) => {
if (!err) console.log(`joined session ${session}`)
});
// The pair and unpair events work the same on both clients.
ss.on('pair', () => console.log('all set to go'));
ss.on('unpair', () => console.log('beep boop all alone'));
// Send all of the touch events to the receiver.
window.ontouchstart(touched);
window.ontouchmove(touched);
window.ontouchend(touched);
function touched(event) {
let touch = event.touches.items(0);
ss.update({ touch });
}
0.0.20
10 years ago
0.0.19
10 years ago
0.0.18
10 years ago
0.0.17
10 years ago
0.0.16
10 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago