Use sockjs instead of only websocket

This commit is contained in:
Oskar Hahn 2013-10-26 10:42:48 +02:00
parent 6f7dabe870
commit 47c60078b3
8 changed files with 49 additions and 17 deletions

View File

@ -258,6 +258,12 @@ OpenSlides uses the following projects or parts of them:
* `ReportLab <http://www.reportlab.com/software/opensource/rl-toolkit/>`_,
License: BSD
* `sockjs-client <https://github.com/sockjs/sockjs-client>`_,
License: MIT
* `sockjs-tornado <https://github.com/mrjoes/sockjs-tornado>`_,
License: MIT
* `Sphinx <http://sphinx-doc.org/>`_, License: BSD
* `Sphinx Bootstrap Theme

View File

@ -7,7 +7,7 @@ How to create a new portable Windows distribution of OpenSlides:
2. Install all required python packages (see requirements_production.txt):
easy_install -Z django django-mptt beautifulsoup4 bleach pillow reportlab tornado django-haystack whoosh
easy_install -Z django django-mptt beautifulsoup4 bleach pillow reportlab sockjs_tornado tornado django-haystack whoosh
3. Install pywin32 from binary installer:

View File

@ -79,6 +79,9 @@ SITE_PACKAGES = {
"pillow": {
"copy": ["PIL"],
},
"sockjs-tornado": {
"copy": ["sockjs"],
},
"tornado": {
"copy": ["tornado"],
},

View File

@ -45,10 +45,10 @@ var updater = {
socket: null,
start: function() {
var url = "ws://" + location.host + "/projector/socket/";
updater.socket = new WebSocket(url);
var url = "http://" + location.host + "/projector/socket";
updater.socket = new SockJS(url);
updater.socket.onmessage = function(event) {
updater.updateProjector(JSON.parse(event.data));
updater.updateProjector(event.data);
}
updater.socket.onclose = function() {
setTimeout('updater.start()', 5000);

File diff suppressed because one or more lines are too long

View File

@ -35,6 +35,7 @@
</div>
</div>
<script type="text/javascript" src="{% static 'javascript/jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'javascript/sockjs-0.3.min.js' %}"></script>
<script type="text/javascript" src="{% static 'javascript/projector.js' %}"></script>
<script type="text/javascript">
{% for js in overlay_js %}

View File

@ -14,11 +14,11 @@ from urllib import unquote
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler as Django_WSGIHandler
from django.utils.translation import ugettext as _
from sockjs.tornado import SockJSRouter, SockJSConnection
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line
from tornado.web import Application, FallbackHandler, StaticFileHandler
from tornado.websocket import WebSocketHandler
from tornado.wsgi import WSGIContainer
@ -37,20 +37,13 @@ class DjangoStaticFileHandler(StaticFileHandler):
return super(DjangoStaticFileHandler, self).get(absolute_path, include_body)
class ProjectorSocketHandler(WebSocketHandler):
class ProjectorSocketHandler(SockJSConnection):
"""
Handels the websocket for the projector.
"""
waiters = set()
# The following lines can be uncommented, if there are any problems with
# websockts in iOS Safari 5.0
## def allow_draft76(self):
## # for iOS 5.0 Safari
## return True
def open(self):
def on_open(self, info):
ProjectorSocketHandler.waiters.add(self)
def on_close(self):
@ -59,7 +52,7 @@ class ProjectorSocketHandler(WebSocketHandler):
@classmethod
def send_updates(cls, data):
for waiter in cls.waiters:
waiter.write_message(data)
waiter.send(data)
def run_tornado(addr, port, reload=False):
@ -73,12 +66,13 @@ def run_tornado(addr, port, reload=False):
url_string = 'http://%s:%s' % (addr, port)
print _("Starting OpenSlides' tornado webserver listening to %(url_string)s") % {'url_string': url_string}
socket_js_router = SockJSRouter(ProjectorSocketHandler, '/projector/socket')
# Start the application
app = WSGIContainer(Django_WSGIHandler())
tornado_app = Application([
tornado_app = Application(socket_js_router.urls + [
(r"%s(.*)" % settings.STATIC_URL, DjangoStaticFileHandler),
(r'%s(.*)' % settings.MEDIA_URL, StaticFileHandler, {'path': settings.MEDIA_ROOT}),
(r'/projector/socket/', ProjectorSocketHandler),
('.*', FallbackHandler, dict(fallback=app))
], debug=reload)

View File

@ -3,6 +3,7 @@ django-mptt==0.6.0
reportlab==2.7
pillow==2.2.1
tornado==3.1.1
sockjs-tornado==1.0.0
bleach==1.2.2
beautifulsoup4==4.3.2
django-haystack==2.1.0