README
arpc
a node RPC library based on socket.io
examples
const server = require('arpc/server')(2333)
server.createService('test', {
a: [() => {
return 233
}]
})
(async function(){
const client = require('arpc/client')
let obj = client('ws://127.0.0.1:2333', 'test')
console.log(await obj.a[0]())
//output: 233
})()
API
client require('arpc/client')
client(socketOrUrl, name, obj = null, path = '/rpc')
- parameters
socketOrUrl: Socket | stringobj: anyobject for the calling from the serverpath: stringthe path for socket.io (invalided if you passed a socket at the first parameter). this can be a secret token for rpc connection
- return
: Promisea object which can call the remote object with a prochain way (see examples)
server require('arpc/server')
server(ioOrPort, path = '/rpc')
- parameters
ioOrPort: Server | numberpath: stringthe same as the client api
- return
: RPCthe rpc object
RPC require('arpc')
- constructor
new RPC() - metheds
connected(conn, name = 'server')call this when sockets connected- parameters
conn: Socketname: stringthe service we request the other side
- parameters
createService(name, obj, onConnect, onDisconnect)name: stringthe name of the service we createobj: anythe object we provide for the remote callingonConnected: (object: Promise) => undefined(optional) the function which will be called when a client connectsonDisconnect: (socket: Socket, reason: string) => undefined(optional) the function which will be called when a client disconnects
getServer(obj = null)creates a remote object from the server- paramaters
obj: anythe object we provide for the remote calling
- return
: Promisethe remote object from the server
- paramaters
license
MIT