Commit 64ab5c4d authored by Joel Martin's avatar Joel Martin

Working with Raw rectangles and capital letter keys.

parent c8460b03
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<head><title>Canvas Experiments</title></head> <head><title>Canvas Experiments</title></head>
<body> <body>
Canvas:<br> Canvas:<br>
<canvas id="tutorial" width="500" height="300"> <canvas id="tutorial" width="640" height="480">
Canvas not supported. Canvas not supported.
</canvas> </canvas>
...@@ -16,6 +16,6 @@ ...@@ -16,6 +16,6 @@
<script src="canvas.js"></script> <script src="canvas.js"></script>
<script> <script>
window.onload = function() { init_canvas('tutorial'); } window.onload = function() { init_canvas('tutorial', 640, 480); }
</script> </script>
</html> </html>
...@@ -28,8 +28,9 @@ c_x : 0, ...@@ -28,8 +28,9 @@ c_x : 0,
c_y : 0, c_y : 0,
c_wx : 0, c_wx : 0,
c_wy : 0, c_wy : 0,
ctx : null,
mousedown: function (e) { mouseDown: function (e) {
evt = e.event || window.event; evt = e.event || window.event;
e.stop(); e.stop();
debug('mouse ' + evt.which + '/' + evt.button + ' down:' + debug('mouse ' + evt.which + '/' + evt.button + ' down:' +
...@@ -64,14 +65,21 @@ ctxDisable: function (e) { ...@@ -64,14 +65,21 @@ ctxDisable: function (e) {
}, },
init: function (canvas) { init: function (canvas, width, height, keyDown, keyUp, mouseDown, mouseUp) {
debug(">> init_canvas"); debug(">> init_canvas");
if (! keyDown) keyDown = Canvas.keyDown;
if (! keyUp) keyUp = Canvas.keyUp;
if (! mouseDown) mouseDown = Canvas.mouseDown;
if (! mouseUp) mouseUp = Canvas.mouseUp;
c = $(canvas); c = $(canvas);
c.addEvent('mousedown', Canvas.mouseDown); c.width = width;
c.addEvent('mouseup', Canvas.mouseUp); c.height = height;
document.addEvent('keydown', Canvas.keyDown); document.addEvent('keydown', keyDown);
document.addEvent('keyup', Canvas.keyUp); document.addEvent('keyup', keyUp);
c.addEvent('mousedown', mouseDown);
c.addEvent('mouseup', mouseUp);
/* Work around right and middle click browser behaviors */ /* Work around right and middle click browser behaviors */
document.addEvent('click', Canvas.ctxDisable); document.addEvent('click', Canvas.ctxDisable);
...@@ -83,22 +91,22 @@ init: function (canvas) { ...@@ -83,22 +91,22 @@ init: function (canvas) {
Canvas.c_wy = c.getSize().y; Canvas.c_wy = c.getSize().y;
if (! c.getContext) return; if (! c.getContext) return;
var ctx = c.getContext('2d'); Canvas.ctx = c.getContext('2d');
/* Border */ /* Border */
ctx.stroke(); Canvas.ctx.stroke();
ctx.rect(0, 0, Canvas.c_wx, Canvas.c_wy); Canvas.ctx.rect(0, 0, Canvas.c_wx, Canvas.c_wy);
ctx.stroke(); Canvas.ctx.stroke();
/* /*
// Does not work in firefox // Does not work in firefox
var himg = new Image(); var himg = new Image();
himg.src = "head_ani2.gif" himg.src = "head_ani2.gif"
ctx.drawImage(himg, 10, 10); Canvas.ctx.drawImage(himg, 10, 10);
*/ */
/* Test array image data */ /* Test array image data */
var img = ctx.createImageData(50, 50); var img = Canvas.ctx.createImageData(50, 50);
for (y=0; y< 50; y++) { for (y=0; y< 50; y++) {
for (x=0; x< 50; x++) { for (x=0; x< 50; x++) {
img.data[(y*50 + x)*4 + 0] = 255 - parseInt((255 / 50) * y); img.data[(y*50 + x)*4 + 0] = 255 - parseInt((255 / 50) * y);
...@@ -107,9 +115,21 @@ init: function (canvas) { ...@@ -107,9 +115,21 @@ init: function (canvas) {
img.data[(y*50 + x)*4 + 3] = 255; img.data[(y*50 + x)*4 + 3] = 255;
} }
} }
ctx.putImageData(img, 100, 100); Canvas.ctx.putImageData(img, 100, 100);
debug("<< init_canvas"); debug("<< init_canvas");
},
rfbImage: function(x, y, width, height, arr) {
var img = Canvas.ctx.createImageData(width, height);
for (var i=0; i < (width * height); i++) {
img.data[i*4 + 0] = arr[i*4 + 0];
img.data[i*4 + 1] = arr[i*4 + 1];
img.data[i*4 + 2] = arr[i*4 + 2];
img.data[i*4 + 3] = 255; // Set Alpha
}
Canvas.ctx.putImageData(img, x, y);
} }
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<script src="include/mootools.js"></script> <script src="include/mootools.js"></script>
<script src="include/mootools-more.js"></script> <script src="include/mootools-more.js"></script>
<script src="include/base64a.js"></script> <script src="include/base64a.js"></script>
<script src="include/des2.js"></script>
<script src="canvas.js"></script> <script src="canvas.js"></script>
<script src="vnc.js"></script> <script src="vnc.js"></script>
...@@ -30,12 +31,11 @@ ...@@ -30,12 +31,11 @@
debug("must set host and port"); debug("must set host and port");
return; return;
} }
init_ws(host, port); RFB.init_ws(host, port);
debug("<< connect"); debug("<< connect");
} }
window.onload = function() { window.onload = function() {
Canvas.init('vnc');
connect(); connect();
} }
</script> </script>
......
This diff is collapsed.
...@@ -4,6 +4,8 @@ import sys, os, socket, time, traceback ...@@ -4,6 +4,8 @@ import sys, os, socket, time, traceback
from base64 import b64encode, b64decode from base64 import b64encode, b64decode
from select import select from select import select
buffer_size = 65536
server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r Upgrade: WebSocket\r
Connection: Upgrade\r Connection: Upgrade\r
...@@ -35,30 +37,30 @@ def proxy(client, target): ...@@ -35,30 +37,30 @@ def proxy(client, target):
if excepts: raise Exception("Socket exception") if excepts: raise Exception("Socket exception")
if client in ins: if client in ins:
buf = client.recv(1024) buf = client.recv(buffer_size)
if len(buf) == 0: raise Exception("Client closed") if len(buf) == 0: raise Exception("Client closed")
tqueue.append(b64decode(buf[1:-1])) tqueue.append(b64decode(buf[1:-1]))
print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf)) #print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
#traffic("}") traffic("}")
if target in ins: if target in ins:
buf = target.recv(1024) buf = target.recv(buffer_size)
if len(buf) == 0: raise Exception("Target closed") if len(buf) == 0: raise Exception("Target closed")
cqueue.append("\x00" + b64encode(buf) + "\xff") cqueue.append("\x00" + b64encode(buf) + "\xff")
print "Target recv: %s (%d)" % (repr(buf), len(buf)) #print "Target recv: %s (%d)" % (repr(buf), len(buf))
#traffic("{") traffic("{")
if cqueue and client in outs: if cqueue and client in outs:
while cqueue: while cqueue:
print "Client send: %s" % repr(cqueue[0]) #print "Client send: %s" % repr(cqueue[0])
client.send(cqueue.pop(0)) client.send(cqueue.pop(0))
#traffic("<") traffic("<")
if tqueue and target in outs: if tqueue and target in outs:
while tqueue: while tqueue:
print "Target send: %s" % repr(tqueue[0]) #print "Target send: %s" % repr(tqueue[0])
target.send(tqueue.pop(0)) target.send(tqueue.pop(0))
#traffic(">") traffic(">")
def start_server(listen_port, target_host, target_port): def start_server(listen_port, target_host, target_port):
lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment