diff lightstring.js @ 39:5e32481b8a92

Better WebSocket feature discovering and Opera support
author Sonny Piers <sonny.piers@gmail.com>
date Tue, 31 Jan 2012 04:12:34 +0100
parents 6773e5bc2ca0
children e02bfcb78428
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -266,11 +266,14 @@ Lightstring.Connection.prototype = {
       throw 'Lightstring: Connection.service is undefined.';
 
     //"Bug 695635 - tracking bug: unprefix WebSockets" https://bugzil.la/695635
-    try {
+    if(typeof(MozWebSocket) == "function") {
+      this.socket = new MozWebSocket(this.service, 'xmpp');
+    }
+    else if(typeof(WebSocket) == "function") {
       this.socket = new WebSocket(this.service, 'xmpp');
     }
-    catch (error) {
-      this.socket = new MozWebSocket(this.service, 'xmpp');
+    else {
+      throw new Error('WebSocket not available.');
     }
 
     var that = this;