AngularJS and WebSockets

4,619 views
Skip to first unread message

Gordon McGuire

unread,
Mar 26, 2013, 11:42:50 AM3/26/13
to ang...@googlegroups.com
Hey,

So I'm working on a project that will (hopefully) be moving to AngularJS soon. Before it can though, I need to assess angular's capabilities in different areas (security, working with other js libraries, modularity, etc).

One thing that I'm a bit stuck on is AngularJS and WebSockets. I'll admit I don't know much about WebSockets. What we want to have is an angular web app that hooks into a Play 1.2.5 RESTful backend. Eventually we want to be able to add in WebSockets for updating live dashboard screens etc.

What I'm hoping the community can tell me is: what's support like for WebSockets in AngularJS? Presumably there isn't built-in support, but I could create a service around some js library for sockets? What JS libraries are there that handle sockets really well? I know there's Socket.IO but that requires Node.JS right?

Thanks,
Gordon

Mac Fee

unread,
Mar 28, 2013, 5:15:27 AM3/28/13
to ang...@googlegroups.com
Brian Ford wrote an excellent tutorial that should get you started:


This is a clean approach that provides websockets as a service around soket.io. This is a pattern I employ quite frequently in my apps.

Max

Gordon McGuire

unread,
Mar 28, 2013, 7:59:06 AM3/28/13
to ang...@googlegroups.com
Hey Max,

Thanks for the link. However, as far as I'm aware, socket.io requires you to be using nodejs for the server right? I'm using the Play Framework for my backend, so is it possible to just use socket.io without nodejs? If not, then are there alternatives?

Thanks

Mac Fee

unread,
Mar 28, 2013, 9:00:45 AM3/28/13
to ang...@googlegroups.com
The benefit of using socket.io (or Faye) is that it offers different means of transports as fall back on older browsers that do not support websockets. If you know that you will be dealing with modern browsers, you could write your own websocket service in AngularJS which isn't that difficult to do. Here is an example:

Gordon McGuire

unread,
Apr 15, 2013, 5:16:31 AM4/15/13
to ang...@googlegroups.com
Sorry for the late reply, I've been away for a while.
Thanks for the link Max. I can't guarantee that I'll be dealing with modern browsers and I'm aware of the benefits of socket.io, but I guess my question is can socket.io be used without nodejs?

Paul Spaulding

unread,
Apr 15, 2013, 8:51:27 AM4/15/13
to ang...@googlegroups.com

Tlvenn

unread,
Apr 15, 2013, 1:16:56 PM4/15/13
to ang...@googlegroups.com
Hi Gordon, 

Since you are using Play framework, the best is to use Atmosphere ( https://github.com/Atmosphere/atmosphere ) which happens to support socket.io js lib if you must have it but I would rather use the atmopshere.js lib instead.
There is now a plugin for Play 2.1: https://github.com/Atmosphere/atmosphere-play
Reply all
Reply to author
Forward
Message has been deleted
0 new messages