Created
June 25, 2015 11:52
-
-
Save Glench/2677f746fab5e43af4c4 to your computer and use it in GitHub Desktop.
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
<script src="underscore-min.js"></script> | |
<script src="jquery-1.11.0.min.js"></script> | |
<script type="text/javascript"> | |
ws = new WebSocket("ws://puku.local:8001"); | |
ws.onmessage = function(evt) { | |
console.log('hi') | |
$('#display').html('<img src="'+ evt.data +'"/>') | |
}; | |
</script> |
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
ws = new WebSocket("ws://puku.local:8001"); | |
input = document.querySelector('input') | |
input.style.display = 'block' | |
$(input).on('change', function(evt) { | |
var file = input.files[0] | |
var fr = new FileReader(); | |
fr.onload = function() { | |
ws.send(fr.result) | |
}; | |
fr.readAsDataURL(file) | |
}) | |
ws.onmessage = function(evt) { | |
var $success = $('<div>').css({ | |
width: '100%', | |
height: '100%', | |
backgroundColor: 'green', | |
position: 'absolute', | |
top: 0, | |
left: 0, | |
}) | |
$('body').append($success) | |
setTimeout(function() { | |
$success.fadeOut(function() { $success.remove() }) | |
}, 500) | |
} |
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
fs = require('fs') | |
var ws = require("nodejs-websocket") | |
images = [] | |
var server = ws.createServer(function (conn) { | |
console.log("New connection") | |
conn.sendText(images[images.length-1] || '') | |
conn.on("text", function (str) { | |
images.push(str) | |
console.log('sending new image...') | |
conn.sendText(str) | |
fs.writeFile('images.json', JSON.stringify(images)) | |
}) | |
conn.on("close", function (code, reason) { | |
console.log("Connection closed") | |
}) | |
}).listen(8001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment