Skip to content

Commit

Permalink
fix(websocket): fix angular#824, patch websocket onproperties correct…
Browse files Browse the repository at this point in the history
…ly in phantomjs
  • Loading branch information
JiaLiPassion committed Jun 29, 2017
1 parent 98f3903 commit d502e1d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/browser/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ export function apply(_global: any) {
const socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
let proxySocket: any;

let proxySocketProto: any;

// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
const onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');
if (onmessageDesc && onmessageDesc.configurable === false) {
proxySocket = Object.create(socket);
// socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
// but proxySocket not, so we will keep socket as prototype and pass it to
// patchOnProperties method
proxySocketProto = socket;
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) {
proxySocket[propName] = function() {
return socket[propName].apply(socket, arguments);
Expand All @@ -34,7 +40,7 @@ export function apply(_global: any) {
proxySocket = socket;
}

patchOnProperties(proxySocket, ['close', 'error', 'message', 'open']);
patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);

return proxySocket;
};
Expand Down

0 comments on commit d502e1d

Please sign in to comment.