Permalink
Browse files

Move html and js into a new directory.

Add a timeout to the wait for the return from IPC and make sure to clear the event.

git-svn-id: svn://svn.freevo.org/freevo/branches/rel-1/freevo@11867 cc3e1ea1-1e01-0410-8d68-8b121e83a9d5
  • Loading branch information...
1 parent 808c5b5 commit 7817a9332fa8537010ec4c6be4d590d22defcff0 @charrea6 charrea6 committed Aug 23, 2011
View
@@ -0,0 +1,57 @@
+/*
+# -----------------------------------------------------------------------
+# Module for communication between web browser and freevo
+# -----------------------------------------------------------------------
+# $Id: youtube.py 11862 2011-08-07 11:56:13Z adam $
+# -----------------------------------------------------------------------
+#
+#
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------
+*/
+
+function sendEvent(event, data){
+ send('event', {'event':event, 'data':data});
+}
+
+function send(cmd, data){
+ var args = { 'cmd': cmd, 'data': data};
+ var xhr = new XMLHttpRequest();
+ xhr.open('POST', '/freevo/ipc', true);
+ xhr.send(JSON.stringify(args));
+}
+
+function poll(){
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', '/freevo/ipc', true);
+ xhr.timeout = 50000;
+ xhr.onreadystatechange = function () {
+ if ((this.readyState == 3 || this.readyState == 4) && this.status == 200) {
+ var args = JSON.parse(this.responseText);
+ var r = eval(args['cmd']);
+ send('return', r);
+ poll();
+ }
+ };
+ xhr.ontimeout = poll;
+ xhr.send();
+}
+
+window.onload = poll;
View
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<title>Freevo</title>
+<script type="text/javascript">
+ window.onload = function(){
+ window.resizeTo(%d, %d);
+ window.moveTo(%d,%d);
+ window.location = "%s";
+ };
+</script>
+</head>
+<body style="background-color: black;">
+</body>
+</html>
@@ -56,7 +56,7 @@
}
</script>
</head>
- <body style="font-family: Arial;border: 0 none;margin: 0; background-color: black; overflow: hidden;">
+ <body style="font-family: Arial;border: 0 none; margin: 0; background-color: black; overflow: hidden;">
$EMBED$
</body>
</html>
View
@@ -32,6 +32,7 @@
import json
import threading
+import os.path
from kaa.process import Process
@@ -41,54 +42,7 @@
JSON_MIMETYPE= 'application/json'
JS_MIMETYPE = 'application/javascript'
-INITIAL_HTML="""
-<html>
-<head>
-<title>Freevo</title>
-<script type="text/javascript">
-window.resizeTo(%d, %d);
-window.moveTo(%d,%d);
-</script>
-</head>
-<body style="background-color: black;">
-<script type="text/javascript">
-window.location = "%s";
-</script>
-</body>
-</html>
-"""
-
-
-IPC_JS = """
- function sendEvent(event, data){
- send('event', {'event':event, 'data':data});
- }
-
- function send(cmd, data){
- var args = { 'cmd': cmd, 'data': data};
- var xhr = new XMLHttpRequest();
- xhr.open('POST', '/freevo/ipc', true);
- xhr.send(JSON.stringify(args));
- }
-
- function poll(){
- var xhr = new XMLHttpRequest();
- xhr.open('GET', '/freevo/ipc', true);
- xhr.timeout = 50000;
- xhr.onreadystatechange = function () {
- if ((this.readyState == 3 || this.readyState == 4) && this.status == 200) {
- var args = JSON.parse(this.responseText);
- var r = eval(args['cmd']);
- send('return', r);
- poll();
- }
- };
- xhr.ontimeout = poll;
- xhr.send();
- }
-
- window.onload = poll;
-"""
+HTML_DIR = os.path.join(config.SHARE_DIR, 'html')
_initial_url = None
@@ -132,7 +86,9 @@ def __js_handler(self, request):
request.send_response(200)
request.send_header('content-type', JS_MIMETYPE)
request.end_headers()
- request.wfile.write(IPC_JS)
+ f = open(os.path.join(HTML_DIR, 'ipc.js'))
+ request.wfile.write(f.read())
+ f.close()
def __send_handler(self, request):
@@ -167,7 +123,8 @@ def __send_handler(self, request):
def __calljs(self, js):
self.return_pending = True
self.lphandler.append(json.dumps({'cmd':js}))
- self.return_event.wait()
+ self.return_event.wait(10.0)
+ self.return_event.clear()
return self.return_result
@@ -196,7 +153,10 @@ def __call__(self, *args, **kwargs):
def _get_initial_HTML(request):
- html = INITIAL_HTML % (config.CONF.width, config.CONF.height, config.CONF.x, config.CONF.y, _initial_url)
+ f = open(os.path.join(HTML_DIR, 'wbinitial.html'))
+ initial_html = f.read()
+ f.close()
+ html = initial_html % (config.CONF.width, config.CONF.height, config.CONF.x, config.CONF.y, _initial_url)
request.send_response(200)
request.send_header('content-type', 'text/html')
request.send_header('content-length', str(len(html)))
@@ -83,9 +83,6 @@ def __init__(self):
self.local_server = util.httpserver.get_local_server()
self.local_server.register_handler('^(http://www.youtube.com/watch\?v=.+)$', self.__html_handler)
print 'PROXY:', self.local_server.get_url('/')
- f = open(os.path.join(config.SHARE_DIR, 'ytflashplayer.html'))
- self.ytplayer_html = f.read()
- f.close()
def rate(self, item):
@@ -196,7 +193,7 @@ def get_html(self, url):
embed = re.sub('width="[0-9]+"', 'width="%d"' % (config.CONF.width-2), embed)
embed = re.sub('height="[0-9]+"', 'height="%d"' % (config.CONF.height-2), embed)
- f = open(os.path.join(config.SHARE_DIR, 'ytflashplayer.html'))
+ f = open(os.path.join(webbrowser.HTML_DIR, 'ytflashplayer.html'))
html = f.read()
f.close()

0 comments on commit 7817a93

Please sign in to comment.