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

Commit 6885151

Browse files
committed
feat(patch): fix #828, patch socket.io client
1 parent fd91152 commit 6885151

10 files changed

+4133
-2129
lines changed

NON-STANDARD-APIS.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,23 @@ add following line into `polyfill.ts` after load zone-mix.
170170
import 'zone.js/dist/zone-patch-electron';
171171
```
172172

173-
there is a sampel repo [zone-electron](https://github.com/JiaLiPassion/zone-electron) here
173+
there is a sample repo [zone-electron](https://github.com/JiaLiPassion/zone-electron) here
174+
175+
* socket.io-client
176+
177+
user need to patch `io` themselves just like following code.
178+
179+
```javascript
180+
<script src="socket.io-client/dist/socket.io.js"></script>
181+
<script src="zone.js/dist/zone.js"></script>
182+
<script src="zone.js/dist/zone-patch-socket-io.js"></script>
183+
<script>
184+
// patch io here
185+
Zone[Zone.__symbol__('socketio')](io);
186+
</script>
187+
```
188+
189+
190+
please reference the sample repo [zone-socketio](https://github.com/JiaLiPassion/zone-socketio) about
191+
detail usage.
174192

gulpfile.js

Lines changed: 10 additions & 0 deletions
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',

lib/extra/socket-io.ts

Lines changed: 24 additions & 0 deletions
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)