-
Notifications
You must be signed in to change notification settings - Fork 2
/
jrpc.min.js
6 lines (6 loc) · 9.21 KB
/
jrpc.min.js
1
2
3
4
5
6
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JRPC=e()}}(function(){return function n(r,u,l){function c(t,e){if(!u[t]){if(!r[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(a)return a(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var s=u[t]={exports:{}};r[t][0].call(s.exports,function(e){return c(r[t][1][e]||e)},s,s.exports,n,r,u,l)}return u[t].exports}for(var a="function"==typeof require&&require,e=0;e<l.length;e++)c(l[e]);return c}({1:[function(r,u,e){(function(e,n){
/*! JRPC v3.1.0
* <https://github.com/vphantom/js-jrpc>
* Copyright 2016 Stéphane Lavergne
* Free software under MIT License: <https://opensource.org/licenses/MIT> */
"use strict";function t(e){this.active=!0,this.transmitter=null,this.remoteTimeout=6e4,this.localTimeout=0,this.serial=0,this.outbox={requests:[],responses:[]},this.inbox={},this.localTimers={},this.outTimers={},this.localComponents={"system.listComponents":!0,"system.extension.dual-batch":!0},this.remoteComponents={},this.exposed={},this.exposed["system.listComponents"]=function(e,t){return"object"==typeof e&&null!==e&&(this.remoteComponents=e,this.remoteComponents["system._upgraded"]=!0),t(null,this.localComponents)}.bind(this),this.exposed["system.extension.dual-batch"]=function(e,t){return t(null,!0)},"object"==typeof e&&("remoteTimeout"in e&&"number"==typeof e.remoteTimeout&&(this.remoteTimeout=1e3*e.remoteTimeout),"localTimeout"in e&&"number"==typeof e.localTimeout&&(this.localTimeout=1e3*e.localTimeout))}function o(e,t,o){var i={jsonrpc:"2.0",method:e};return this.active?("function"==typeof t&&(o=t,t=null),"system._upgraded"in this.remoteComponents&&!(e in this.remoteComponents)?("function"==typeof o&&n(o,{code:-32601,message:"Unknown remote method"}),this):("object"==typeof t&&(i.params=t),this.serial++,"function"==typeof o&&(i.id=this.serial,this.inbox[this.serial]=o),this.outbox.requests.push(i),this.transmit(),"function"!=typeof o||(0<this.remoteTimeout?this.outTimers[this.serial]=setTimeout(s.bind(this,{jsonrpc:"2.0",id:this.serial,error:{code:-1e3,message:"Timed out waiting for response"}}),this.remoteTimeout):this.outTimers[this.serial]=!0),this)):this}function s(e){var t=!1,o=null;this.active&&"id"in e&&e.id in this.outTimers&&(clearTimeout(this.outTimers[e.id]),delete this.outTimers[e.id],e.id in this.inbox&&("error"in e?t=e.error:o=e.result,n(this.inbox[e.id],t,o),delete this.inbox[e.id]))}function i(e,t,o){var i={jsonrpc:"2.0",id:e};null!==e&&this.active&&e in this.localTimers&&(clearTimeout(this.localTimers[e]),delete this.localTimers[e],null!=t&&!1!==t?i.error="number"==typeof t?{code:t,message:"error"}:!0===t?{code:-1,message:"error"}:"string"==typeof t?{code:-1,message:t}:"object"==typeof t&&"code"in t&&"message"in t?t:{code:-2,message:"error",data:t}:i.result=o,this.outbox.responses.push(i),this.transmit())}e.setImmediate=r("timers").setImmediate,t.prototype.shutdown=function(){var t=this;return t.active=!1,t.transmitter=null,t.remoteTimeout=0,t.localTimeout=0,t.localComponents={},t.remoteComponents={},t.outbox.requests.length=0,t.outbox.responses.length=0,t.inbox={},t.exposed={},Object.keys(t.localTimers).forEach(function(e){clearTimeout(t.localTimers[e]),delete t.localTimers[e]}),Object.keys(t.outTimers).forEach(function(e){clearTimeout(t.outTimers[e]),delete t.outTimers[e]}),t},t.prototype.call=o,t.prototype.notify=o,t.prototype.expose=function(e,t){var o;if(!this.active)return this;if("string"==typeof e)this.localComponents[e]=!0,this.exposed[e]=t;else if("object"==typeof e)for(o in e)e.hasOwnProperty(o)&&(this.localComponents[o]=!0,this.exposed[o]=e[o]);return this},t.prototype.upgrade=function(){return this.active?this.call("system.listComponents",this.localComponents,function(e,t){e||"object"!=typeof t||(this.remoteComponents=t,this.remoteComponents["system._upgraded"]=!0)}.bind(this)):this},t.prototype.receive=function(e){var t=[],o=[];if(!this.active)return this;if("string"==typeof e)try{e=JSON.parse(e)}catch(e){return this}if(e.constructor===Array){if(0===e.length)return this;"string"==typeof e[0].method?t=e:o=e}else"object"==typeof e&&(void 0!==e.requests&&void 0!==e.responses?(t=e.requests,o=e.responses):"string"==typeof e.method?t.push(e):o.push(e));return o.forEach(s.bind(this)),t.forEach(function(e){var t,o=null;if(!this.active||"object"!=typeof e||null===e)return;if("string"!=typeof e.jsonrpc||"2.0"!==e.jsonrpc)return;if(t=void 0!==e.id?e.id:null,"string"!=typeof e.method)return void(null!==t&&(this.localTimers[t]=!0,n(i.bind(this,t,-32600))));if(!(e.method in this.exposed))return void(null!==t&&(this.localTimers[t]=!0,n(i.bind(this,t,-32601))));if("params"in e){if("object"!=typeof e.params)return void(null!==t&&(this.localTimers[t]=!0,n(i.bind(this,t,-32602))));o=e.params}null!==t&&(0<this.localTimeout?this.localTimers[t]=setTimeout(i.bind(this,t,{code:-1002,message:"Method handler timed out"}),this.localTimeout):this.localTimers[t]=!0);return void n(this.exposed[e.method],o,i.bind(this,t))}.bind(this)),this},t.prototype.transmit=function(e){var t,o,i=null,s={responses:[],requests:[]};if("function"!=typeof e&&(e=this.transmitter),!this.active||"function"!=typeof e)return this;if(t=this.outbox.responses.length,o=this.outbox.requests.length,0<t&&0<o&&"system.extension.dual-batch"in this.remoteComponents)s=i={responses:this.outbox.responses,requests:this.outbox.requests},this.outbox.responses=[],this.outbox.requests=[];else if(0<t)1<t?(s.responses=i=this.outbox.responses,this.outbox.responses=[]):s.responses.push(i=this.outbox.responses.pop());else{if(!(0<o))return this;1<o?(s.requests=i=this.outbox.requests,this.outbox.requests=[]):s.requests.push(i=this.outbox.requests.pop())}return n(e,JSON.stringify(i),function(e,t){this.active&&t&&(0<e.responses.length&&Array.prototype.push.apply(this.outbox.responses,e.responses),0<e.requests.length&&Array.prototype.push.apply(this.outbox.requests,e.requests))}.bind(this,s)),this},t.prototype.setTransmitter=function(e){return this.transmitter=e,this.transmit()},"undefined"!=typeof Promise&&"function"==typeof Promise.promisify&&(t.prototype.callAsync=Promise.promisify(o)),u.exports=t}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},r("timers").setImmediate)},{timers:3}],2:[function(e,t,o){var i,s,n=t.exports={};function r(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function l(t){if(i===setTimeout)return setTimeout(t,0);if((i===r||!i)&&setTimeout)return i=setTimeout,setTimeout(t,0);try{return i(t,0)}catch(e){try{return i.call(null,t,0)}catch(e){return i.call(this,t,0)}}}!function(){try{i="function"==typeof setTimeout?setTimeout:r}catch(e){i=r}try{s="function"==typeof clearTimeout?clearTimeout:u}catch(e){s=u}}();var c,a=[],m=!1,h=-1;function p(){m&&c&&(m=!1,c.length?a=c.concat(a):h=-1,a.length&&f())}function f(){if(!m){var e=l(p);m=!0;for(var t=a.length;t;){for(c=a,a=[];++h<t;)c&&c[h].run();h=-1,t=a.length}c=null,m=!1,function(t){if(s===clearTimeout)return clearTimeout(t);if((s===u||!s)&&clearTimeout)return s=clearTimeout,clearTimeout(t);try{s(t)}catch(e){try{return s.call(null,t)}catch(e){return s.call(this,t)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function y(){}n.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var o=1;o<arguments.length;o++)t[o-1]=arguments[o];a.push(new d(e,t)),1!==a.length||m||l(f)},d.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=y,n.addListener=y,n.once=y,n.off=y,n.removeListener=y,n.removeAllListeners=y,n.emit=y,n.prependListener=y,n.prependOnceListener=y,n.listeners=function(e){return[]},n.binding=function(e){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(e){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},{}],3:[function(l,e,c){(function(e,t){var i=l("process/browser.js").nextTick,o=Function.prototype.apply,s=Array.prototype.slice,n={},r=0;function u(e,t){this._id=e,this._clearFn=t}c.setTimeout=function(){return new u(o.call(setTimeout,window,arguments),clearTimeout)},c.setInterval=function(){return new u(o.call(setInterval,window,arguments),clearInterval)},c.clearTimeout=c.clearInterval=function(e){e.close()},u.prototype.unref=u.prototype.ref=function(){},u.prototype.close=function(){this._clearFn.call(window,this._id)},c.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},c.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},c._unrefActive=c.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;0<=t&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},c.setImmediate="function"==typeof e?e:function(e){var t=r++,o=!(arguments.length<2)&&s.call(arguments,1);return n[t]=!0,i(function(){n[t]&&(o?e.apply(null,o):e.call(null),c.clearImmediate(t))}),t},c.clearImmediate="function"==typeof t?t:function(e){delete n[e]}}).call(this,l("timers").setImmediate,l("timers").clearImmediate)},{"process/browser.js":2,timers:3}]},{},[1])(1)});