javascript - SocketIO emit with callback fails while upgrading 0.9.16 to 1.3.5 -


in 0.9.16, use socket.emit callback chat server return data , can handle result per acknowledgement. after upgrade 1.3.5 i've found error in console this

uncaught typeerror: cannot read property 'apply' of undefined.

i've done this,

from web

socket.emit('usertouser', { 'usename': 'john', 'message': 'hi' }, function(callback){ //callback handled }); 

chat server

socket.on('usertouser', function(content, callback){ //do if(callback) return callback({'result':'success', 'messageid':content.messageid, 'chatid':content.chatid}); }); 

when removed callback client side, there no error. believe there changes done in callback.

i'm getting acknowledgement , chat working properly, concern console error leads socketio.js

socket.prototype.onack = function(packet){   debug('calling ack %s %j', packet.id, packet.data);   var fn = this.acks[packet.id];   fn.apply(this, packet.data);   delete this.acks[packet.id]; }; 

guys, please help

finally i've fixed issue. coding mistake, i've done multiple callbacks in chat server. this:

socket.on('usertouser', function(content, callback){    mysql.insertchat(content, function(err, data){       return callback({'result':'1'})   //first callback   })     sendtouser(content, function(errm successdata){       return callback({'result':'success','chatid':content.chatid});       //second callback ->wrong   })  }); 

in previous versions warning, error !! thats it. so please avoid multiple callacks

please have @ , might useful every nodejs developers: http://www.toptal.com/nodejs/top-10-common-nodejs-developer-mistakes/#remote-developer-job

thanks guys upvoting !


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -