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

Commit

Permalink
fix(WebSocket): don't patch EventTarget methods twice
Browse files Browse the repository at this point in the history
closes #235

On older versions of Chrome, patching via property descriptors isn't
available, but unlike Safari, window.EventTarget exists and is already
patched, so the EventTarget methods on WebSocket.prototype don't need to
be patched again.

Closes #233.
  • Loading branch information
tlancina authored and vicb committed Jan 27, 2016
1 parent 767a30e commit 345e56c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/patch/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as utils from '../utils';
// we have to patch the instance since the proto is non-configurable
export function apply() {
var WS = (<any>global).WebSocket;
utils.patchEventTargetMethods(WS.prototype);
// On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
// On older Chrome, no need since EventTarget was already patched
if (!(<any>global).EventTarget) {
utils.patchEventTargetMethods(WS.prototype);
}
(<any>global).WebSocket = function(a, b) {
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
var proxySocket;
Expand Down

0 comments on commit 345e56c

Please sign in to comment.