0.0.20 • Published 8 years ago

socket-screen v0.0.20

Weekly downloads
2
License
MIT
Repository
-
Last release
8 years ago

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

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago