pie-client
v0.13.3
Published
A client for connecting to, sending and receiving messages from a pie server instance
Downloads
7
Readme
Pie Client
A client for connecting to, sending and receiving messages from a PieServer instance.
This package is a PieServer client that abstracts PieServer's public API behind simple publicly exported methods.
Getting started, simplest usage:
import PieClient from 'pie-client';
const pie = new PieClient({
env: 'development',
wsUri: 'ws://localhost:8000',
onData: console.log,
onError: console.error,
onServerAssignedData: console.log,
onClientPresenceChanged: console.log,
onRooms: rooms => console.log('rooms', rooms),
onConnectInfo: ({ connected }) => console.log('Connected', connected),
});
function onConnected() {
// To make a room, once connected
pie
.makeRoom({
app: 'Some app name',
name: 'Rock Paper Sissors Unlimited Room!',
version: '0.1',
private: true,
})
.then(() => console.log('New room made!'))
.catch(e => console.error('Could not make new room:', e));
}
function onConnected() {
// To join a room, once connected
pie
.joinRoom({
app: 'Some app name',
name: 'Rock Paper Sissors Unlimited Room!',
version: 'v0.1',
})
.then(() => console.log('Join succeeded!'))
.catch(e => console.error('Join failed:', e));
}
// To send data to everyone in the room
pie.sendData({
any: 'data',
});
Extras
Add <div id='websocket-pie-connection-status'></div>
to the page to have PieClient automatically update it with the connection status