From f53487da44e974e50277a85a84defea8c5c1fc2d Mon Sep 17 00:00:00 2001 From: deathcap Date: Tue, 24 Mar 2015 20:35:44 -0700 Subject: [PATCH] Pipe the workerstream to websocket stream, try mineflayer in worker. GH-8 Requires deathcap/wsmc@45096b5acea6e4f58a05d0f6fc5a6cf91fd5228b --- clientmc.js | 8 +++++++- mf-worker.js | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clientmc.js b/clientmc.js index 8a20313..2f1bbb9 100644 --- a/clientmc.js +++ b/clientmc.js @@ -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)); diff --git a/mf-worker.js b/mf-worker.js index a681e4c..9cb7d05 100644 --- a/mf-worker.js +++ b/mf-worker.js @@ -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'}); }; };