UNPKG

socket.io-rpc

Version:

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

32 lines (29 loc) 725 B
/* global notdefined */ var rpcClient = require('socket.io-rpc-client') var rpc = rpcClient('http://localhost:8032') rpc.expose({ fnOnClient: function () { console.log('called client method') return 42 }, asyncOnClient: function () { return new Promise(function (resolve, reject) { setTimeout(function () { resolve('resolved after 40ms') }, 40) }) }, erroringMethod: function () { notdefined.error.will.propagate }, callTextTestOnServer: function () { return rpc('textTest')() }, callGenerator: function *(a) { return yield new Promise((resolve, reject) => { setTimeout(() => { resolve('from server generator ' + a) }, 10) }) } })