Merge pull request #959 from ostcar/sockjs

Use sockjs instead of only websocket
This commit is contained in:
Oskar Hahn 2013-10-28 00:51:21 -07:00
commit 466e2ae565
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/>`_, * `ReportLab <http://www.reportlab.com/software/opensource/rl-toolkit/>`_,
License: BSD 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 <http://sphinx-doc.org/>`_, License: BSD
* `Sphinx Bootstrap Theme * `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): 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: 3. Install pywin32 from binary installer:

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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