Last active
March 13, 2016 23:59
-
-
Save pythoneer/4518138 to your computer and use it in GitHub Desktop.
meteor js with binary js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.isClient) { | |
Meteor.startup(function () { | |
loadbinaryjs(); | |
var client = new BinaryClient('ws://localhost:9000'); | |
client.on('stream', function(stream, meta){ | |
var parts = []; | |
stream.on('data', function(data){ | |
parts.push(data); | |
}); | |
stream.on('end', function(){ | |
var img = document.createElement("img"); | |
img.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts)); | |
document.body.appendChild(img); | |
}); // on end | |
});// on stream | |
});// startup | |
}// is client | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
var require = __meteor_bootstrap__.require | |
var BinaryServer = require('binaryjs').BinaryServer; | |
var fs = require('fs'); | |
var server = BinaryServer({port: 9000}); | |
server.on('connection', function(client){ | |
var file = fs.createReadStream("/home/<user>/Documents/dev/test/meteor_binaryjs/" + '/flower.png'); | |
client.send(file); | |
}); | |
});// startup | |
}// is server | |
function loadbinaryjs(){ | |
/*text of binary.js file*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment