-
Notifications
You must be signed in to change notification settings - Fork 0
Home
HyroVitalyProtago edited this page Mar 29, 2022
·
8 revisions
Peers are discovered through a signalling server and connected through WebRTC. A contract is established between them as a list of slots. This way, only listened messages are sended between them.
By default, there is nothing to do, but you can configure the library by calling the init function before anything else from the lib
// signalling server address
mh.init('phone-tracker.glitch.me');
// default way to use the lib is by sending json signals
// object.evt define the signal name connected to a slot with the same name
// userId is optional, broadcast when not used
// mh.send(object, userId?:int);
mh.json('avatar', { position: {x:0, y:0, z:0} }); // elegant way
mh.json({ evt:'avatar', position: {x:0, y:0, z:0} }); // raw way
// you can also send raw values
mh.send('image', rawData, userId);
// how to receive data
// define slot to receive signal
mh.on('avatar', (data, userId) => {
// data.position ...
});