Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different count of arguments in service method from rest api and socket api calling #31

Closed
Vitaliy-Yarovuy opened this issue Dec 23, 2013 · 8 comments

Comments

@Vitaliy-Yarovuy
Copy link

than i create "Services" and use socket client it send 2 arguments to "get" method of Service but than i use REST api it call with 3 arguments?
what i do wrong ?

@daffl
Copy link
Member

daffl commented Dec 23, 2013

Just pass the same number of arguments when emitting the SocketIO event by using an empty object as the parameters:

var myService = {
  get: function(id, params, callback) {

  }
}

socket.emit('todo::get', 1, {}, function() {});

You can also write your service method so that it works both ways:

var myService = {
  get: function(id, params, callback) {
    if(!callback) {
      callback = params;
      params = {};
    }
  }
}

socket.emit('todo::get', 1, function() {});

@daffl daffl closed this as completed Dec 23, 2013
@Vitaliy-Yarovuy
Copy link
Author

when i send 4 argument on web browser it not working

socket.emit("testpoints::get", $scope.pointId,{},function(err, point){
    $scope.point = point;
});

socket.io is using xhr-poling
and header "Request Payload" have value:

5:1+::{"name":"testpoints::get","args":["one"]}

and header the same in both way when i use 3 argument and when 4 arguments
for method socket.emit.

and in both type of calling on web browser client, on server i have only 2 arguments on "get" method than i use socket.io client

@daffl
Copy link
Member

daffl commented Dec 30, 2013

I'm not sure I am following here. I just tried it with the example from the website and something like

socket.emit('todos::get', 1, {}, function(error, todo) {})

Most definitely works. How does your testpoints service .get look like?
As noted in #19, using long polling as the default setting isn't entirely correct so that setting will change in the next version.

@Vitaliy-Yarovuy
Copy link
Author

I have solve this problem (for me) in my code, but is not work like in documentation.

my service get looks

TestPointService.prototype.get = function (id) {
    var callback = arguments[arguments.length-1];
    if (!this.testPoints[id]) {
        this.create({id:id},function(){});
    }
    callback(null, this.testPoints[id]);
};

@daffl
Copy link
Member

daffl commented Dec 30, 2013

What part of the documentation are you referring to? As I pointed out in my comment above

TestPointService.prototype.get = function(id, params, callback) {
  if(!callback) {
    callback = params;
    params = {};
  }
  // Do stuff here
}

Should do the same as your solution. I highly recommend however to always use

``js
socket.emit('todos::get', 1, {}, function(error, todo) {})


For SocketIO calls with at least an empty object as the parameters.

@Vitaliy-Yarovuy
Copy link
Author

I apologize,
i find bug in my client code that's broke transfer more that two arguments to socket.emit
i use angural.js and write some service wrapper for socket.io client lib and there was bug

@daffl
Copy link
Member

daffl commented Jan 2, 2014

Ah ok, good to know. Also, if you are interested into open sourcing your Angular wrapper, I'd be happy to hear about it.

daffl pushed a commit that referenced this issue Aug 22, 2018
* chore(package): update shx to version 0.3.0

* package-lock.json
daffl pushed a commit that referenced this issue Aug 23, 2018
* chore(package): update shx to version 0.3.0

* package-lock.json
daffl pushed a commit that referenced this issue Aug 29, 2018
daffl pushed a commit that referenced this issue Aug 29, 2018
@lock
Copy link

lock bot commented Feb 8, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants