From 1b38b58da87f97e388c73fcc2c5c271669382e94 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 21 Jan 2012 17:39:37 -0800 Subject: [PATCH] Update websocket chat demo to work when not addressed as localhost. Turn on draft76 support. --- demos/websocket/chatdemo.py | 4 ++++ demos/websocket/static/chat.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/demos/websocket/chatdemo.py b/demos/websocket/chatdemo.py index 21648ebe..60fb956e 100755 --- a/demos/websocket/chatdemo.py +++ b/demos/websocket/chatdemo.py @@ -57,6 +57,10 @@ class ChatSocketHandler(tornado.websocket.WebSocketHandler): cache = [] cache_size = 200 + def allow_draft76(self): + # for iOS 5.0 Safari + return True + def open(self): ChatSocketHandler.waiters.add(self) diff --git a/demos/websocket/static/chat.js b/demos/websocket/static/chat.js index 818bc031..9d8bcc50 100644 --- a/demos/websocket/static/chat.js +++ b/demos/websocket/static/chat.js @@ -50,10 +50,11 @@ var updater = { socket: null, start: function() { + var url = "ws://" + location.host + "/chatsocket"; if ("WebSocket" in window) { - updater.socket = new WebSocket("ws://localhost:8888/chatsocket"); + updater.socket = new WebSocket(url); } else { - updater.socket = new MozWebSocket("ws://localhost:8888/chatsocket"); + updater.socket = new MozWebSocket(url); } updater.socket.onmessage = function(event) { updater.showMessage(JSON.parse(event.data));