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

Commit 3ba6fa1

Browse files
committedMay 2, 2015
fix(websockets): properly patch websockets in Safari 7.0
Closes #88
1 parent 657f6fe commit 3ba6fa1

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed
 

‎zone.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,34 @@ Zone.patchViaCapturingAllTheEvents = function () {
472472
});
473473
};
474474

475+
475476
// we have to patch the instance since the proto is non-configurable
476477
Zone.patchWebSocket = function() {
477478
var WS = window.WebSocket;
478479
Zone.patchEventTargetMethods(WS.prototype);
479480
window.WebSocket = function(a, b) {
480481
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
481-
Zone.patchProperties(socket, ['onclose', 'onerror', 'onmessage', 'onopen']);
482-
return socket;
482+
var proxySocket;
483+
484+
// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
485+
var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');
486+
if (onmessageDesc && onmessageDesc.configurable === false) {
487+
proxySocket = Object.create(socket);
488+
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) {
489+
proxySocket[propName] = function() {
490+
return socket[propName].apply(socket, arguments);
491+
};
492+
});
493+
} else {
494+
// we can patch the real socket
495+
proxySocket = socket;
496+
}
497+
498+
Zone.patchProperties(proxySocket, ['onclose', 'onerror', 'onmessage', 'onopen']);
499+
500+
return proxySocket;
483501
};
484-
}
502+
};
485503

486504

487505
// wrap some native API on `window`

0 commit comments

Comments
 (0)
This repository has been archived.