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

feat(patch): fix #828, patch socket.io client #994

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions NON-STANDARD-APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,21 @@ import 'zone.js/dist/zone-patch-electron'; // add zone-patch-electron to patch E

there is a sampel repo [zone-electron](https://github.com/JiaLiPassion/zone-electron).

* socket.io-client

user need to patch `io` themselves just like following code.

```javascript
<script src="socket.io-client/dist/socket.io.js"></script>
<script src="zone.js/dist/zone.js"></script>
<script src="zone.js/dist/zone-patch-socket-io.js"></script>
<script>
// patch io here
Zone[Zone.__symbol__('socketio')](io);
</script>
```


please reference the sample repo [zone-socketio](https://github.com/JiaLiPassion/zone-socketio) about
detail usage.

10 changes: 10 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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',
Expand Down
24 changes: 24 additions & 0 deletions lib/extra/socket-io.ts
Original file line number Diff line number Diff line change
@@ -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) {
// patch io.Socket.prototype event listener related method
api.patchEventTarget(global, [io.Socket.prototype], {
useG: false,
chkDup: false,
rt: true,
diff: (task: any, delegate: any) => {
return task.callback === delegate;
}
});
// also patch io.Socket.prototype.on/off/removeListener/removeAllListeners
io.Socket.prototype.on = io.Socket.prototype.addEventListener;
io.Socket.prototype.off = io.Socket.prototype.removeListener =
io.Socket.prototype.removeAllListeners = io.Socket.prototype.removeEventListener;
};
});
Loading