Sunday, 15 June 2014

javascript - Ionic, Socket.io and AngularJS, Acknowleage doesnt work -



javascript - Ionic, Socket.io and AngularJS, Acknowleage doesnt work -

i'm using ionic , socket.io, , have problem "fire" acknowleage callback of emits..

in normal javascript client side is:

function ack(response){ console.log(response); } socket.emit('message',{data:"data"}, ack);

when server recibe message client fire function, server side is..

socket.on('message',function(data,fn){ fn({data:"response"}); });

so, when server execute fn({data:"response"}), client fire ack function.

i build ionic framework factory:

services.factory('$socket', ['$rootscope', function($rootscope) { var socket = io.connect('http://127.0.0.1:9564'); function on(eventname, callback){ console.log(eventname); socket.on(eventname, function () { var args = arguments; $rootscope.$apply(function () { callback.apply(socket, args); }); }); } function emit(eventname, data, callback){ socket.emit(eventname, data, function () { var args = arguments; $rootscope.$apply(function () { callback.apply(socket, args); }); }); } homecoming { on: on, emit: emit }; }]);

and in userctrl seek utilize in way:

function onlogin(data){ console.log(data); $scope.closelogin(); } $scope.dologin = function() { $socket.emit('user:login', $scope.logindata, onlogin); };

the problem function onlogin never called, seek puting function $scope.onlogin, same.

eny solution this?

thanks

did create sure url local host same script added? (i.e other js scripts included, above internal js files?)

javascript node.js angularjs sockets

No comments:

Post a Comment