janpantel / angular-sails

An angular module for using the sails socket.io api
MIT License
307 stars 56 forks source link

v1 or v2? #88

Open luislobo opened 8 years ago

luislobo commented 8 years ago

Hi, We are using currently the v1 for our application. I'm wondering if the V2 version should be used and if it is stable enough. What do you think? Is there a plan to release the final version soon?

TheSharpieOne commented 8 years ago

v2 it pretty different than v1. I use v2, but I really don't use all of the feature it offers. I've asked for feedback and issue reports... and the lack of them may mean it good or that no one is using it.

neonexus commented 8 years ago

I tried using v2 yesterday, and it broke my build, as it doesn't want to use the $sailsProvider.url I've set in my config.

I was also hoping v2 would have exposed socket.io's request() function, but that doesn't seem to be the case (at least, not from what I can tell). I need that function exposed, in-order for this to be a truly drop-in replacement for $http (as one of my custom services is built on $http's request() function).

TheSharpieOne commented 8 years ago

https://docs.angularjs.org/api/ng/service/$http doesn't seem to have a request() function

neonexus commented 8 years ago

You're right, I realized that a little bit ago, as I was modifying my service. What I was referring to in $http, is using $http(), so I can pass in the method to use, the data, etc. The closest thing to this is request() in socket.io.

TheSharpieOne commented 8 years ago

2.0 still accepts a url through the provider: https://github.com/janpantel/angular-sails/blob/c9cd8a32db0bd223964f9d4fa5556b11a6ad3712/src/service/%24sails.js#L47 You also have the ability to create your own socket and pass that to the provider, it will be used instead of creating a new connection.

You can use $sails() just like $http(), it just calls the specific function based on the method specified in the config passed in the call. https://github.com/janpantel/angular-sails/blob/c9cd8a32db0bd223964f9d4fa5556b11a6ad3712/src/service/%24sails.js#L50-L52 The thing you are probably running into is that the socket it a constant connection, to a single server. $http would allow you to sent anywhere, $sails limits it to the socket connection. It seems angular-sails may need to have the ability to set up multiple socket connections (maybe a factory service)? But angular-sails is more or less designed to work with sails, which assumes a single socket endpoint. Also, in 2.0, you can get to the socket via $sails._socket._socket. $sails._socket is the sails socket.io wrapper, which itself exposes the underlying socket through ._socket. https://github.com/janpantel/angular-sails/blob/c9cd8a32db0bd223964f9d4fa5556b11a6ad3712/src/service/%24sails.js#L54 https://github.com/janpantel/angular-sails/blob/c9cd8a32db0bd223964f9d4fa5556b11a6ad3712/src/service/%24sailsIo.js#L46 (or https://github.com/janpantel/angular-sails/blob/c9cd8a32db0bd223964f9d4fa5556b11a6ad3712/src/service/%24sailsIo.js#L36 )

neonexus commented 8 years ago

I understand v2 is supposed to accept an URL through the provider (I dug into the code to make sure), just as v1 does, however, that's what forced me to go back to v1: v2 ignores it for some reason, and uses the domain/port it was served from. I had v1 working, found out about v2; updated to v2 (only calling functions on button presses, pressed no buttons); v2 was attempting to connect to localhost:3000, even though I told it to use localhost:1337, the exact same way v1 does.

As far as $sails(), that's awesome, didn't know, will keep it in-mind.

And the multiple sockets: I don't think that's necessary. It would just be nice to tell the service to hold off on the connection, until it's kicked off manually down the line. Not a need, just a nice-to-have. Only because supplying the HTML attributes for socket.io is impossible when using something like gulp to handle assets. Which makes supplying my own socket handler useless, as I still can't disable the eager beaver.