janpantel / angular-sails

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

$sails.connect() is not working manually. #89

Open AKamanjha opened 8 years ago

AKamanjha commented 8 years ago

Hey, I have no control over connection to sails server. on $sails.disconnect() disconnects socket connection properly , but when i tried to connect manually its not getting connected. Here is my code.

fzLive.config(function($sailsProvider) {
  $sailsProvider.url = "http://192.168.1.110:1338";
});

// custom provider to interact with $sailsProvider

fzLive.provider("mySocket", function() {
  var provider = this;
  provider.$get = function($sails) {
    var service = {};
    var token = "default Token";

    service.fzConnect = function(){
      var socket = $sails.connect();
    };

    service.setToken = function(key, value) {
      console.log(value);
      $sails.query = key + '=' + value;
      token = $sails.query;
    };

    service.findBug = function() {
      return token;
    };

    service.post = function(url, data) {
      var data = data || {};
      var urlPrefix = '/' + url + "?" + token;
      return $sails.post(urlPrefix, data);
    };

    service.channel = function(channelName, callback) {
      return $sails.on(channelName, callback);
    };

    service.onConnect = function(callback) {
      $sails.on('connect', callback);
      console.log($sails.isConnected());
    };

    service.onDisconnect = function(callback) {
      return $sails.on('disconnect', callback);
    };

    service.destroy = function (callback) {
      return $sails.disconnect();
      // body...
    };

    service.connect = function () {
     $sails.connect();
    }

    return service;
  }

  return provider;
});