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 :
|
else :
|
||||||
self.redirect("/")
|
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):
|
class DisconnectionHandler(BaseHandler):
|
||||||
def post(self):
|
def post(self):
|
||||||
@ -106,10 +93,13 @@ class DisconnectionHandler(BaseHandler):
|
|||||||
self.set_cookie("user", "0")
|
self.set_cookie("user", "0")
|
||||||
self.redirect("/")
|
self.redirect("/")
|
||||||
|
|
||||||
class TestSocket(tornado.websocket.WebSocketHandler):
|
class WSocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
def open(self) :
|
def open(self) :
|
||||||
|
if not self.current_user :
|
||||||
|
self.close()
|
||||||
|
self.redirect("/")
|
||||||
|
return
|
||||||
print "->Websocket opened"
|
print "->Websocket opened"
|
||||||
print '->lol'
|
|
||||||
while 1 :
|
while 1 :
|
||||||
try :
|
try :
|
||||||
f = urlopen('http://test:a@192.168.1.15/image.jpg?cidx=791836195')
|
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"
|
print "->Websocket closed"
|
||||||
|
|
||||||
|
|
||||||
class testHtml(BaseHandler):
|
|
||||||
def get(self):
|
|
||||||
self.render("test.html")
|
|
||||||
|
|
||||||
|
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/video", VideoHandler),
|
(r"/video", VideoHandler),
|
||||||
(r"/unauthorized", UnauthorizedHandler),
|
(r"/unauthorized", UnauthorizedHandler),
|
||||||
(r"/ajax", AJAXHandler),
|
|
||||||
(r"/disconnection", DisconnectionHandler),
|
(r"/disconnection", DisconnectionHandler),
|
||||||
(r"/test", TestSocket),
|
(r"/test", WSocketHandler),
|
||||||
(r"/testHtml", testHtml),
|
|
||||||
], cookie_secret="1213215656")
|
], cookie_secret="1213215656")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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>
|
<title>Acces camera</title>
|
||||||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
|
var ws = new WebSocket ("ws://192.168.1.23/test");
|
||||||
function refresh() {
|
ws.onmessage = function (evt) {
|
||||||
$.ajax({
|
console.log("data receive");
|
||||||
type: "POST",
|
var str = "<img src='data:image/jpeg;base64,"+evt.data+"'>";
|
||||||
url:'/ajax',
|
$('.image').html(str);
|
||||||
contentType: "image/jpeg",
|
|
||||||
success: function(data){
|
|
||||||
var str = "<img src='data:image/jpeg;base64,"+data+"'>";
|
|
||||||
$('.image').html(str);}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$(document).ready(refresh())
|
ws.onopen = function () {
|
||||||
setInterval('refresh()', 2000);
|
console.log("websocket engage");
|
||||||
|
};
|
||||||
|
ws.onclose = function () {
|
||||||
|
console.log("connection closed");
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -32,3 +28,4 @@
|
|||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user