UNPKG

socket.io-rpc

Version:

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

46 lines 1.46 kB
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <h1>Plain browser socket.io-rpc test/showcase</h1> getTime: <span id="serverTime"></span><br> asyncTest: <span id="asyncText"></span> </body> <script src="/socket.io/socket.io.js"></script> <script> //define shim taken from: https://github.com/cujojs/when window.define = function(factory) { try{ delete window.define; } catch(e){ window.define = void 0; } // IE window.when = factory(); }; window.define.amd = {}; </script> <script src="/rpc/when.js"></script> <script src="/rpc/rpc-client.js"></script> <script> RPC.connect('http://localhost:8080'); RPC.loadChannel('myChannel').then( function (channel) { channel.getTime().then(function (date) { console.log('time on server is: ' + date); document.getElementById('serverTime').innerText = date; }); channel.myAsyncTest('passing string as argument').then(function(retVal){ console.log('server returned: ' + retVal); document.getElementById('asyncText').innerText = retVal; }); } ); RPC.expose('clientChannel', { fnOnClient: function (param) { return 'whatever you need from client returned ' + param; } }).then( function (channel) { console.log(" client channel ready"); } ); </script> </html>