# HG changeset patch # User Sonny Piers # Date 1328719446 -3600 # Node ID d9804e206393b0efaadedac01bd17e9398784153 # Parent 7f4e43d6cb1599e4d52691e8ff5fd6f71a3c706c Fix Safari/iOS support. diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -151,20 +151,26 @@ Lightstring.Connection.prototype = { if (!this.service) return; //TODO: error - if (typeof(WebSocket) === "function") { + // Standard + if (typeof(WebSocket) === 'function') this.socket = new WebSocket(this.service, 'xmpp'); - } - else if (typeof(MozWebSocket) === "function") { + // Safari + else if (typeof(WebSocket) === 'object') + this.socket = new WebSocket(this.service); + // Old Gecko + else if (typeof(MozWebSocket) === 'function') { this.socket = new MozWebSocket(this.service, 'xmpp'); } + // No known WebSocket support else { return; //TODO: error } var Conn = this; this.socket.addEventListener('open', function() { - if (this.protocol !== 'xmpp') - return; //TODO: error + //FIXME: Opera/Safari WebSocket implementation doesn't support sub-protocol mechanism. + //if (this.protocol !== 'xmpp') + //return; //TODO: error var stream = Lightstring.stanzas.stream.open(Conn.jid.domain); //FIXME: Use Lightstring.Connection.send (problem with parsing steam); diff --git a/polyfill.js b/polyfill.js new file mode 100644 --- /dev/null +++ b/polyfill.js @@ -0,0 +1,24 @@ +//js-core doesn't support bind, polyill taken from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== "function") { + // closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP + ? this + : oThis || window, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + + return fBound; + }; +}