UNPKG

socket.io-rpc

Version:

Minimalistic remote procedure call(RPC/RMI) library bootstrapped on socket.io

52 lines (48 loc) 1.86 kB
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <h1>Angular socket.io-rpc test/showcase</h1> <!--You can also use regular ng-controller, but then you have to load channel yourself by calling $rpc.loadChannel('myChannel'); inside it--> <div rpc-controller="testCtrl" rpc-channel="myChannel"> getTime: <span ng-bind="serverTime"></span><br> asyncTest: {{ asyncTest }} </div> </body> <script src="/socket.io/socket.io.js"></script> <script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script> <script src="/rpc/rpc-client-angular.js"></script> <script> angular.module('app', ['RPC']) .controller('testCtrl', function ($scope, $rpc) { $scope.rpc.getTime().then(function (date) { console.log('time on server is: ' + date); $scope.serverTime = date; //no need to call $scope.$apply, because it is called in $rpc; }); $scope.rpc.myAsyncTest('passing string as argument').then(function (retVal) { console.log('server returned: ' + retVal); $scope.asyncTest = retVal; }); console.log('ctr ' + new Date().toJSON()); $rpc.expose('clientChannel', { fnOnClient: function (param) { return 'whatever you need from client returned ' + param; } }).then( function (channel) { console.log(" client channel ready"); } ); } ).run(function ($rpc, $rootScope) { $rpc.connect('http://localhost:8080'); // don't forget port, if you are not on 80 console.log('run ' + new Date().toJSON()); }); var injector = angular.bootstrap(document, ['app']); </script> </html>