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

Commit b3db9f4

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(patch): fix #828, patch socket.io client
1 parent 2dc7e5c commit b3db9f4

10 files changed

+4131
-2128
lines changed

Diff for: NON-STANDARD-APIS.md

+17
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,21 @@ import 'zone.js/dist/zone-patch-electron'; // add zone-patch-electron to patch E
180180

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

183+
* socket.io-client
184+
185+
user need to patch `io` themselves just like following code.
186+
187+
```javascript
188+
<script src="socket.io-client/dist/socket.io.js"></script>
189+
<script src="zone.js/dist/zone.js"></script>
190+
<script src="zone.js/dist/zone-patch-socket-io.js"></script>
191+
<script>
192+
// patch io here
193+
Zone[Zone.__symbol__('socketio')](io);
194+
</script>
195+
```
196+
197+
198+
please reference the sample repo [zone-socketio](https://github.com/JiaLiPassion/zone-socketio) about
199+
detail usage.
183200

Diff for: gulpfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ gulp.task('build/zone-patch-user-media.min.js', ['compile-esm'], function(cb) {
192192
return generateScript('./lib/browser/webapis-user-media.ts', 'zone-patch-user-media.min.js', true, cb);
193193
});
194194

195+
gulp.task('build/zone-patch-socket-io.js', ['compile-esm'], function(cb) {
196+
return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.js', false, cb);
197+
});
198+
199+
gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) {
200+
return generateScript('./lib/extra/socket-io.ts', 'zone-patch-socket-io.min.js', true, cb);
201+
});
202+
195203
gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
196204
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
197205
});
@@ -297,6 +305,8 @@ gulp.task('build', [
297305
'build/zone-patch-electron.min.js',
298306
'build/zone-patch-user-media.js',
299307
'build/zone-patch-user-media.min.js',
308+
'build/zone-patch-socket-io.js',
309+
'build/zone-patch-socket-io.min.js',
300310
'build/zone-mix.js',
301311
'build/bluebird.js',
302312
'build/bluebird.min.js',

Diff for: lib/extra/socket-io.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
Zone.__load_patch('socketio', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9+
(Zone as any)[Zone.__symbol__('socketio')] = function patchSocketIO(io: any) {
10+
// patch io.Socket.prototype event listener related method
11+
api.patchEventTarget(global, [io.Socket.prototype], {
12+
useG: false,
13+
chkDup: false,
14+
rt: true,
15+
diff: (task: any, delegate: any) => {
16+
return task.callback === delegate;
17+
}
18+
});
19+
// also patch io.Socket.prototype.on/off/removeListener/removeAllListeners
20+
io.Socket.prototype.on = io.Socket.prototype.addEventListener;
21+
io.Socket.prototype.off = io.Socket.prototype.removeListener =
22+
io.Socket.prototype.removeAllListeners = io.Socket.prototype.removeEventListener;
23+
};
24+
});

0 commit comments

Comments
 (0)