-
Notifications
You must be signed in to change notification settings - Fork 227
Add support for deferred sockets. #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…cation interaction before connecting) Allow socket swapping
Nice work! |
Glad you liked it and thanks for your code it was a great guide.
|
Awesome. This is exactly what I am looking for. In my opinion its actually more common to connect to realtime backends after some activity(in production), hardly ever on app initialization. So thanks for the awesome job. So if I download mritzco/angular-socket-io I get this instead of the original btford's? I am kind of still confused about github. I checked mritzco/angular-socket-io didn't find the README-deffered.md. Where do I download everything?
BTW thank you @davisford! I started using your gist, my problem is I couldn't figure our where to add socket.on. (Is it in the controller or factory? Sorry I am from .net and signalr. Only been on node and angualr for two months. The socket.io thing is still very confusing to me and all the books don't use angular in their samples.) |
Sorry I got and downloaded it! Thanks! |
Hi! Now I really need help. Been trying this for hours without success. My code is like this: app.factory('realtime, ['$rootScope', 'socketFactory', 'defferedSocketFactory', function(etc) { I access this from another factory The connection is being made to the server okay. But I am not able to receive. When I was using btford's, I could receive it, but not I can't. Pls what am I doing wrong? |
Hi, Questions
It really depends on the nature of your application, for us it makes possible to swap sockets from web to local intranet for locations with bad/no internet access. How to install: More info here: Problem Normally you would work with the socket like this: Factory: Return the socket immediately so it can be injected anywhere else by angular: socket = socketFactory({ either return socket or return it immediately return socketFactory({ ...
//OR keep code as before and:
return socket; From that point you can just refer to socket as is it were connected and request angular to inject it. angular.module('myapp').controller|factory|service(['ngSocket', function (socket) {
socket.on('test',...);
}]); The code for swapping can remain in the factory or anywhere outside (socket is injected as in previous paragraph) $rootScope.$on('authenticated', Finally: Let me know if that helps, good luck! |
If anyone else comes here looking for this functionality, I was able to achieve something similar using the existing functionality in the repo. Instead of swapping the sockets, just set the
Now you can inject the above |
Add support for deferred sockets. Sockets that require user or application interaction before connecting, it also allows for socket swapping.
It's based on:
#86
Provides an alternative way to:
#64
I added a README-deferred.md to explain in more detail and keep the js file clean.
It currently passes all the tests, added tests with socket replacement before calls and after calls.
These changes are based on the work of @davisford but refactored to:
Needs tests for second real socket swap (real socket for another real socket)