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

Socket.IO #828

Closed
Kaffiend opened this issue Jun 30, 2017 · 6 comments · Fixed by #994
Closed

Socket.IO #828

Kaffiend opened this issue Jun 30, 2017 · 6 comments · Fixed by #994

Comments

@Kaffiend
Copy link

Is there a way we can get Socket.io to run within zone? or will we manually have to run every socket callback through zone?

@JiaLiPassion
Copy link
Collaborator

@Kaffiend ,currently you have to use Zone.current.wrap(callback) yourself, I can implement a patch for socket.io later.

@brgaulin
Copy link

I guarantee this is not optimal, but the only way I found to wrap the emitter .on event, was something like this:

let socketOn = socket.on;
socket.on = (event: string, fn: () => any) => {
  let wrappedFunction = function() {
    let args = arguments;
    zone.run(() => fn.apply(this, args));
  };
  return socketOn.apply(socket, [event, wrappedFunction]);
};

@brgaulin
Copy link

Although, its weird. I do see that websockets themselves are wrapped. socket.io uses the Component Emitter for handling its events: https://www.npmjs.com/package/component-emitter

@Kaffiend
Copy link
Author

I added ngrx to manage state better and discovered that onPush change detection and async slices of state updated from my socket services makes this work just fine. Not saying it doesnt need patched for other implementations without a reactive library for angular in use.

@Kaffiend
Copy link
Author

Kaffiend commented Jan 4, 2018

Will zone be patched any time soon for Socket.IO?

@JiaLiPassion
Copy link
Collaborator

@Kaffiend , I am working on it, I will create a PR soon.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 16, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 16, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 16, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 21, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 22, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Jan 25, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 8, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants