From 0119f16d07cbefce19b522cf2b9ccea62c441aea Mon Sep 17 00:00:00 2001 From: "JiaLi.Passion" Date: Tue, 16 Jan 2018 22:39:57 +0900 Subject: [PATCH] feat(patch): fix #828, patch socket.io client --- gulpfile.js | 10 ++++++++++ lib/extra/socket-io.ts | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lib/extra/socket-io.ts diff --git a/gulpfile.js b/gulpfile.js index b524bf3ca..c79d1970e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -192,6 +192,14 @@ gulp.task('build/zone-patch-user-media.min.js', ['compile-esm'], function(cb) { return generateScript('./lib/browser/webapis-user-media.ts', 'zone-patch-user-media.min.js', true, cb); }); +gulp.task('build/zone-patch-socket-io.js', ['compile-esm'], function(cb) { + return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.js', false, cb); +}); + +gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) { + return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.min.js', true, cb); +}); + gulp.task('build/bluebird.js', ['compile-esm'], function(cb) { return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb); }); @@ -297,6 +305,8 @@ gulp.task('build', [ 'build/zone-patch-electron.min.js', 'build/zone-patch-user-media.js', 'build/zone-patch-user-media.min.js', + 'build/zone-patch-socket-io.js', + 'build/zone-patch-socket-io.min.js', 'build/zone-mix.js', 'build/bluebird.js', 'build/bluebird.min.js', diff --git a/lib/extra/socket-io.ts b/lib/extra/socket-io.ts new file mode 100644 index 000000000..21e3b921b --- /dev/null +++ b/lib/extra/socket-io.ts @@ -0,0 +1,24 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +Zone.__load_patch('socketio', (global: any, Zone: ZoneType, api: _ZonePrivate) => { + (Zone as any)[Zone.__symbol__('socketio')] = function patchSocketIO(io: any) { + // io is being mixed with Emitter.prototype, so we can patchEventTargetMethods + // with io.prototype + api.patchEventTarget(global, [io.Socket.prototype], { + useG: false, + chkDup: false, + rt: true, + diff: (task: any, delegate: any) => { + return task.callback === delegate; + } + }); + io.Socket.prototype.on = io.Socket.prototype.addEventListener; + io.Socket.prototype.off = io.Socket.prototype.removeListener = + io.Socket.prototype.removeAllListeners = io.Socket.prototype.removeEventListener; + }; +});