modifié: superTornado.py
modifié: v/video.html
This commit is contained in:
parent
4df402ca1c
commit
7c9ba01568
@ -26,6 +26,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||||||
|
|
||||||
class MainHandler(BaseHandler):
|
class MainHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
|
print "-> IP = " + self.remote_ip
|
||||||
self.render("v/index.html")
|
self.render("v/index.html")
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
@ -42,13 +43,35 @@ class MainHandler(BaseHandler):
|
|||||||
print "->An unauthorized user try to access"
|
print "->An unauthorized user try to access"
|
||||||
self.redirect("/unauthorized")
|
self.redirect("/unauthorized")
|
||||||
|
|
||||||
class VideoHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
class VideoHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
if not self.current_user :
|
if not self.current_user :
|
||||||
self.redirect("/")
|
self.redirect("/")
|
||||||
return
|
return
|
||||||
self.render("v/video.html")
|
self.render("v/video.html")
|
||||||
|
|
||||||
|
class UnauthorizedHandler(BaseHandler):
|
||||||
|
def get(self):
|
||||||
|
self.render("v/illegal.html")
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
force = self.get_argument("illegalAccess","")
|
||||||
|
if force == "1" :
|
||||||
|
self.set_secure_cookie("user", "illegalUser")
|
||||||
|
self.redirect("/video")
|
||||||
|
else :
|
||||||
|
self.redirect("/")
|
||||||
|
|
||||||
|
|
||||||
|
class DisconnectionHandler(BaseHandler):
|
||||||
|
def post(self):
|
||||||
|
if not self.current_user :
|
||||||
|
self.close()
|
||||||
|
return
|
||||||
|
self.clear_cookie("user")
|
||||||
|
self.redirect("/")
|
||||||
|
|
||||||
|
class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
||||||
def open(self) :
|
def open(self) :
|
||||||
if not self.current_user :
|
if not self.current_user :
|
||||||
self.close()
|
self.close()
|
||||||
@ -96,6 +119,7 @@ class VideoHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=0")'
|
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=0")'
|
||||||
print"->"+iden+" Deconnection"
|
print"->"+iden+" Deconnection"
|
||||||
|
|
||||||
|
|
||||||
def send_image(self) :
|
def send_image(self) :
|
||||||
try :
|
try :
|
||||||
socket.setdefaulttimeout(5)
|
socket.setdefaulttimeout(5)
|
||||||
@ -108,35 +132,12 @@ class VideoHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
print e
|
print e
|
||||||
self.write_message("error")
|
self.write_message("error")
|
||||||
|
|
||||||
|
|
||||||
class UnauthorizedHandler(BaseHandler):
|
|
||||||
def get(self):
|
|
||||||
self.render("v/illegal.html")
|
|
||||||
|
|
||||||
def post(self):
|
|
||||||
force = self.get_argument("illegalAccess","")
|
|
||||||
if force == "1" :
|
|
||||||
self.set_secure_cookie("user", "illegalUser")
|
|
||||||
self.redirect("/video")
|
|
||||||
else :
|
|
||||||
self.redirect("/")
|
|
||||||
|
|
||||||
|
|
||||||
class DisconnectionHandler(BaseHandler):
|
|
||||||
def post(self):
|
|
||||||
if not self.current_user :
|
|
||||||
self.close()
|
|
||||||
return
|
|
||||||
self.clear_cookie("user")
|
|
||||||
self.redirect("/")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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"/disconnection", DisconnectionHandler),
|
(r"/disconnection", DisconnectionHandler),
|
||||||
|
(r"/socket", WSocketHandler),
|
||||||
(r"/style/(.*)", tornado.web.StaticFileHandler,{"path":"./v/style"},),
|
(r"/style/(.*)", tornado.web.StaticFileHandler,{"path":"./v/style"},),
|
||||||
(r"/images/(.*)", tornado.web.StaticFileHandler,{"path":"./v/images"},),
|
(r"/images/(.*)", tornado.web.StaticFileHandler,{"path":"./v/images"},),
|
||||||
(r"/js/(.*)", tornado.web.StaticFileHandler,{"path":"./v/js"},)],
|
(r"/js/(.*)", tornado.web.StaticFileHandler,{"path":"./v/js"},)],
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>Acces camera</title>
|
<title>Acces camera</title>
|
||||||
<script src="js/jquery-2.1.0.min.js"></script>
|
<script src="js/jquery-2.1.0.min.js"></script>
|
||||||
<script >
|
<script >
|
||||||
var ws = new WebSocket ("ws://192.168.1.12/video");
|
var ws = new WebSocket ("ws://192.168.1.12/socket");
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
console.log("data receive");
|
console.log("data receive");
|
||||||
if(evt.data != "error") {
|
if(evt.data != "error") {
|
||||||
|
Reference in New Issue
Block a user