UNPKG

latte_web2

Version:
49 lines (48 loc) 1.32 kB
(function(define) { 'use strict'; define("latte_web/server/rpc/orpc", ["require", "exports", "module", "window"], function(require, exports, module, window) { var latte_lib = require("latte_lib"); function RPC() { this.methods = {}; this.id = 0; }; latte_lib.inherits(RPC, latte_lib.events); (function() { this.Call = function(handle, params, socket, cb) { var self = this; if(latte_lib.isFunction(socket)) { cb = socket; socket = null; } this.write({ method: handle, params: params, id: ++self.id }, socket); if(cb) { this.once(self.id, cb); } } this.Set = function(method, func) { this.methods[method] = func; } this.CallAll = this.Call = function(method, params, socket ,callback) { if(!this.methods[method]){ //console.log(latte_lib.debug.info); return latte_lib.debug.info("no method: "+method); } if(socket) { if(latte_lib.isFunction(socket)) { callback = socket; socket = null; } } params.push(function(err, data) { callback(err, data); }); this.methods[method].apply(null, params); } }).call(RPC.prototype); module.exports = RPC; }); })(typeof define === "function"? define: function(name, reqs, factory) { factory(require, exports, module); });