Create multi user experiences which are controlled by time. Built on top of socket.io
and innkeeper
.
There are two parts to polyvision. A server and a client.
Server Usage:
var app = require( 'http' ).createServer( function() {} );
var io = require( 'socket.io' )( app );
var polyvision = require( 'polyvision' );
app.listen( 3333 );
polyvision( io );
Client Usage:
var io = require( 'socket.io-client' );
var polyvision = require( 'polyvision/client' );
var socket = io( 'http://localhost:3333' );
polyvision( socket )
.then( function( client ) {
// a user entered
client.on( 'user', function( info ) {
console.log( 'users', info.users );
});
// the experience should start playing
client.on( 'play', function() {
console.log( 'playing' );
});
// the experience should be paused
client.on( 'pause', function() {
console.log('paused');
});
function join(id) {
client.enter(id);
}
});
This is an innkeeper
client room. You can use the room to reserve a key read it's id etc. Room's are places where users will all join and then have the ability to set room data. One polyvision client can have one room.
Returns a promise which will return a reference to the polyivision client when a room has been reserved.
Returns a promise which will return a reference to the polyivision client when a room has been entered. id
is an room id.
Returns a promise which will return a reference to the polyivision client when a room has been entered. key
is an room id.
Returns true
or false
depending whether a polyvision experience has started playing.
Returns true
or false
depending whether a polyvision experience is paused.
Returns a Number
that is the number of milliseconds since the experience started. -1 will be returned if the experience has not started.
Returns a Number
is the servers current time. This can be used to sync actions.
Set a variable on the room that everyone can access. key
is the name of the variable. value
is the name of the variable. A promise is returned which will resolve once the variable has been set.
Get a variable on the room. key
is the name of the variable. A promise is returned which will return the variables value when it resolves.
Start the experience by calling play. Calling play will notify everyone whose joined the room that the experience has started. After play has been called calling the time of the experience will begin incrementing. In order to ensure that all clients start the experience at the exact same time client.getTime()
will return -1 for one second.
Pause the experience.
Seek the experience to another time. This should not be called until the experience has truly started after that one second delay which is mentioned in client.play
MIT, see LICENSE.md for details.