How to view/collect data output of MPP

41 views
Skip to first unread message

Lamp

unread,
Jan 2, 2018, 6:01:32 PM1/2/18
to Multiplayer Piano Forum
In browser client you can collect the websocket data to console like so:
MPP.client.ws.addEventListener('message', function(msg){console.log(msg.data)});



To view data in terminal and collect to text file, using node.js; first run `npm install mpp-client`
then paste the following into a text file

var fs = require('fs');
var MPPclient = require('mpp-client');
var gClient = new MPPclient('ws://www.multiplayerpiano.com:443');
gClient
.setChannel('lobby');
gClient
.start();
gClient
.ws.addEventListener('message', function(message){
     
var line = `${Date.now()} ${message.data}`;
     console.log(line);
     
fs.appendFileSync('MPPoutput.txt', line+'\n')
});
//

save it to `mppdatacollector.js` (or whatever you want to call it) and run with `node mppdatacollector.js`

You can also just run `node`, then paste the code in. (make sure to copy all of it, including the empty line cause each new line enters in the last line and you want to add the listener immediately after creating the websocket to collect the initial data)
Reply all
Reply to author
Forward
0 new messages