angular / ngSocket

WebSocket support for angular
Apache License 2.0
204 stars 25 forks source link

Why send "deferred":{"promise":{}} to server #18

Open yinhm opened 10 years ago

yinhm commented 10 years ago

I found ngSocket send "deferred":{"promise":{}} as part of json message when I was migrating from another websocket library. See: angular/ngSocket/blob/master/src/ngSocket.js#L136

I don't see the reason behind this, I have monkey patched it to:

          this.socket.send(typeof data.message === 'string'?
            data.message :
            JSON.stringify(data.message));

to make it compatible with my server code.

I think ngSocket should not make any assumption of server implementation. So my question is: can we let user define what it should send?

algolov commented 10 years ago

It's disappoints me too. I fix it with

JSON.stringify(data, function(key, value) { return key === 'deferred' ? undefined : value; }));
TomClarkson commented 10 years ago

Also when we send JSON does the data have to be under a message key? Just wondering why not send the data with the same JSON supplied as an argument to the send method? (on the server I have to do $message->message->propertySetInSendJSON).

Thanks.

ratbeard commented 9 years ago

Yes this is definitely a bug, @globin 's PR fixes this for me.

gsmetal commented 9 years ago

+1 for this bug

fotoflo commented 9 years ago

Seems like its still open!