Skip to content

Commit

Permalink
Pipe the workerstream to websocket stream, try mineflayer in worker. G…
Browse files Browse the repository at this point in the history
  • Loading branch information
deathcap committed Mar 25, 2015
1 parent d8c6680 commit f53487d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion clientmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,21 @@ ClientMC.prototype.enable = function() {

this.mfworker = webworkify(require('./mf-worker.js'));
this.mfworkerStream = workerstream(this.mfworker);
this.websocketStream = websocket_stream(this.opts.url);

this.websocketStream.pipe(this.mfworkerStream);

/*
this.mfworkerStream.write('test');
this.mfworkerStream.on('data', function(data) {
console.log('mfworkerStream data',data);
});
*/

// create bot
this.bot = mineflayer.createBot({
username: username,
stream: websocket_stream(this.opts.url)
stream: this.websocketStream,
});

this.game.voxels.on('missingChunk', this.missingChunk.bind(this));
Expand Down
17 changes: 16 additions & 1 deletion mf-worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
'use strict';

var ParentStream = require('workerstream/parent');
var mineflayer = require('wsmc/mineflayer-stream');

module.exports = function(self) {
console.log('mf-worker initializing',self);
console.log('Object=',Object.prototype);

self.parentStream = ParentStream();

/*
self.bot = mineflayer.createBot({
username: 'user1', // TODO
stream: self.parentStream,
});
console.log('mf-worker bot',self.bot);
*/

self.onmessage = function(event) {
console.log('mf-worker onmessage',event);
self.postMessage({whats: 'up'});
//self.postMessage({whats: 'up'});
};
};

0 comments on commit f53487d

Please sign in to comment.