Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(websockets): properly patch websockets in Safari 7.0
Browse files Browse the repository at this point in the history
Closes #88
  • Loading branch information
IgorMinar committed May 2, 2015
1 parent 657f6fe commit 3ba6fa1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,34 @@ Zone.patchViaCapturingAllTheEvents = function () {
});
};


// we have to patch the instance since the proto is non-configurable
Zone.patchWebSocket = function() {
var WS = window.WebSocket;
Zone.patchEventTargetMethods(WS.prototype);
window.WebSocket = function(a, b) {
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
Zone.patchProperties(socket, ['onclose', 'onerror', 'onmessage', 'onopen']);
return socket;
var proxySocket;

// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');
if (onmessageDesc && onmessageDesc.configurable === false) {
proxySocket = Object.create(socket);
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) {
proxySocket[propName] = function() {
return socket[propName].apply(socket, arguments);
};
});
} else {
// we can patch the real socket
proxySocket = socket;
}

Zone.patchProperties(proxySocket, ['onclose', 'onerror', 'onmessage', 'onopen']);

return proxySocket;
};
}
};


// wrap some native API on `window`
Expand Down

0 comments on commit 3ba6fa1

Please sign in to comment.