Sahe
Sahe

Reputation: 163

What best way use in Angular in my case?

I need write some methods that works with socket.io in Angular JS.

  1. SendMessage()
  2. GetMessages()
  3. TypingMessage();

For example, after event ng-click="SendMessage()" I need send message via Socket.io.

I have wrote a good tutotial in Stack overflow about service and factory Angular JS. But still can not choose right way what use in my case. Put this methods in Factory method or make service?

Upvotes: 0

Views: 68

Answers (1)

Daan van Hulst
Daan van Hulst

Reputation: 1436

I would suggest you have a look at the following git repo:

https://github.com/btford/angular-socket-io

I use this in combination with a Python socket server and it works great. You will be able to create your own socket factory from btford's socketFactory which you can use as a normal factory.

angular.module('myApp', [
  'btford.socket-io'
]).
factory('mySocket', function (socketFactory) {
  var myIoSocket = io.connect('/some/path');

  mySocket = socketFactory({
    ioSocket: myIoSocket
  });

  return mySocket;
});

Upvotes: 1

Related Questions