modifié: superTornado.py
renommé: test.html -> video.html
This commit is contained in:
parent
98507e30b4
commit
f769e3e1ea
@ -71,19 +71,6 @@ class UnauthorizedHandler(BaseHandler):
|
||||
else :
|
||||
self.redirect("/")
|
||||
|
||||
class AJAXHandler(BaseHandler):
|
||||
def post(self):
|
||||
if not self.current_user :
|
||||
self.redirect("/")
|
||||
return
|
||||
try :
|
||||
f = urlopen('http://test:a@192.168.1.15/image.jpg?cidx=791836195')
|
||||
data = f.read()
|
||||
encoded = base64.b64encode(data)
|
||||
self.write(encoded)
|
||||
self.finish()
|
||||
except Exception, e :
|
||||
pass
|
||||
|
||||
class DisconnectionHandler(BaseHandler):
|
||||
def post(self):
|
||||
@ -106,10 +93,13 @@ class DisconnectionHandler(BaseHandler):
|
||||
self.set_cookie("user", "0")
|
||||
self.redirect("/")
|
||||
|
||||
class TestSocket(tornado.websocket.WebSocketHandler):
|
||||
class WSocketHandler(tornado.websocket.WebSocketHandler):
|
||||
def open(self) :
|
||||
if not self.current_user :
|
||||
self.close()
|
||||
self.redirect("/")
|
||||
return
|
||||
print "->Websocket opened"
|
||||
print '->lol'
|
||||
while 1 :
|
||||
try :
|
||||
f = urlopen('http://test:a@192.168.1.15/image.jpg?cidx=791836195')
|
||||
@ -127,19 +117,15 @@ class TestSocket(tornado.websocket.WebSocketHandler):
|
||||
print "->Websocket closed"
|
||||
|
||||
|
||||
class testHtml(BaseHandler):
|
||||
def get(self):
|
||||
self.render("test.html")
|
||||
|
||||
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/video", VideoHandler),
|
||||
(r"/unauthorized", UnauthorizedHandler),
|
||||
(r"/ajax", AJAXHandler),
|
||||
(r"/disconnection", DisconnectionHandler),
|
||||
(r"/test", TestSocket),
|
||||
(r"/testHtml", testHtml),
|
||||
(r"/test", WSocketHandler),
|
||||
], cookie_secret="1213215656")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
31
test.html
31
test.html
@ -1,31 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="stylesheet" type="text/css" href="style/styles.css">
|
||||
<title>Acces camera</title>
|
||||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||
<script type="text/javascript" >
|
||||
var ws = new WebSocket ("ws://192.168.1.23/test");
|
||||
ws.onmessage = function (evt) {
|
||||
console.log("data receive");
|
||||
var str = "<img src='data:image/jpeg;base64,"+evt.data+"'>";
|
||||
$('.image').html(str);
|
||||
}
|
||||
ws.onopen = function () {
|
||||
console.log("websocket engage");
|
||||
};
|
||||
ws.onclose = function () {
|
||||
console.log("connection closed");
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Vue camera</h2>
|
||||
<div class="image"></div>
|
||||
<form action="/disconnection" method="post">
|
||||
<input type="submit" value="Deconnexion">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
27
video.html
27
video.html
@ -6,22 +6,18 @@
|
||||
<title>Acces camera</title>
|
||||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||
<script type="text/javascript" >
|
||||
|
||||
function refresh() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url:'/ajax',
|
||||
contentType: "image/jpeg",
|
||||
success: function(data){
|
||||
var str = "<img src='data:image/jpeg;base64,"+data+"'>";
|
||||
$('.image').html(str);}
|
||||
});
|
||||
|
||||
var ws = new WebSocket ("ws://192.168.1.23/test");
|
||||
ws.onmessage = function (evt) {
|
||||
console.log("data receive");
|
||||
var str = "<img src='data:image/jpeg;base64,"+evt.data+"'>";
|
||||
$('.image').html(str);
|
||||
}
|
||||
$(document).ready(refresh())
|
||||
setInterval('refresh()', 2000);
|
||||
|
||||
|
||||
ws.onopen = function () {
|
||||
console.log("websocket engage");
|
||||
};
|
||||
ws.onclose = function () {
|
||||
console.log("connection closed");
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@ -32,3 +28,4 @@
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Reference in New Issue
Block a user