chrisenytc / ng-socket

Angular Module for Socket.io
MIT License
49 stars 18 forks source link

How to specify the server:port where the client has to connect ? #2

Closed olimungo closed 9 years ago

olimungo commented 10 years ago

Hi,

I can't find how to specify the server:port where the client has to connect ? Can you help me, please.

Thank you, Olivier

alexzaporozhets commented 10 years ago

Hi, I got the same problem. According to code it is not possible to do so.

alexzaporozhets commented 10 years ago

I use hack based on monkey patching. It is not a best option but it works.

(function() {
    // saving original function
    var _connect = io.connect;
    io.connect = function() {
        return _connect.apply(io, ['domain.com']);
    };
})();
chrisenytc commented 10 years ago

I'll fix this. Currently I use socket.io globally and then I use your connection in AngularJS.

init.js

window.socket = io.connect('domain.com');
alexzaporozhets commented 10 years ago

This solution does not work for me, conosle.log(socket) === undefined

chrisenytc commented 10 years ago
console.log(io);

Returns undefined?

/socket.io/socket.io.js is included before window.socket? because this works for me.

alexzaporozhets commented 10 years ago
script(type='text/javascript', src='/socket.io/socket.io.js')
script(type='text/javascript').
    window.socket = io.connect('domain.com');
script(type='text/javascript', src='/lib/ng-socket/ngSocket.js')
angular.module('ngSocket', []).factory('$socket', ['$rootScope', function ($rootScope) {
    console.log(socket);
    //Check if socket is undefined
    if (typeof socket === 'undefined') {
      var socket = io.connect();
    }

undefined

chrisenytc commented 10 years ago

I'll be reviewing this implementation. Is also very old.

chrisenytc commented 9 years ago

This feature was implemented by @dprothero. Update to version 0.1.2