From b16e4ce91f938d45aa7a3b0ca89abec39f4c8518 Mon Sep 17 00:00:00 2001 From: Hiroshi Ichikawa Date: Sat, 17 Dec 2011 20:06:26 +0900 Subject: Using MozWebSocket when available. Issue #87 --- NEWS.md | 5 +++++ web_socket.js | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index ebdff16..42caa9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +- 2011-12-17 + - web-socket-js now uses MozWebSocket when available. i.e. When you load + web_socket.js, WebSocket is defined as alias of MozWebSocket when + available. + - 2011-09-18 - web-socket-js now speaks WebSocket version hybi-10. Old versions spoke hixie-76. If you really need web-socket-js which speaks hixie-76, you can diff --git a/web_socket.js b/web_socket.js index 0037d68..6b629a6 100644 --- a/web_socket.js +++ b/web_socket.js @@ -5,7 +5,15 @@ (function() { - if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) return; + if (window.WEB_SOCKET_FORCE_FLASH) { + // Keeps going. + } else if (window.WebSocket) { + return; + } else if (window.MozWebSocket) { + // Firefox. + window.WebSocket = MozWebSocket; + return; + } var logger; if (window.WEB_SOCKET_LOGGER) { @@ -30,14 +38,14 @@ } /** - * This class represents a faux web socket. + * Our own implementation of WebSocket class using Flash. * @param {string} url * @param {array or string} protocols * @param {string} proxyHost * @param {int} proxyPort * @param {string} headers */ - WebSocket = function(url, protocols, proxyHost, proxyPort, headers) { + window.WebSocket = function(url, protocols, proxyHost, proxyPort, headers) { var self = this; self.__id = WebSocket.__nextId++; WebSocket.__instances[self.__id] = self; -- cgit v1.2.1