MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / getProxy

Method getProxy

www/js/ext/socket.js:124–171  ·  view source on GitHub ↗
(timeout)

Source from the content-addressed store, hash-verified

122 }
123 var socket = new WebSocket(parseUrl(url.evalStatically()));
124 function getProxy(timeout) {
125 return new Proxy(
126 {},
127 {
128 get: function(obj, property) {
129 if (PROXY_BLACKLIST.includes(property)) {
130 return null;
131 } else if (property === "noTimeout") {
132 return getProxy(-1);
133 } else if (property === "timeout") {
134 return function(i) {
135 return getProxy(parseInt(i));
136 };
137 } else {
138 return function() {
139 var uuid = genUUID();
140 var args = [];
141 for (var i = 0; i < arguments.length; i++) {
142 args.push(arguments[i]);
143 }
144 var rpcInfo = {
145 iid: uuid,
146 function: property,
147 args
148 };
149 socket = socket ? socket : new WebSocket(parseUrl(url.evalStatically()));
150 socket.send(JSON.stringify(rpcInfo));
151 var promise = new Promise(function(resolve, reject) {
152 promises[uuid] = {
153 resolve,
154 reject
155 };
156 });
157 if (timeout >= 0) {
158 setTimeout(function() {
159 if (promises[uuid]) {
160 promises[uuid].reject("Timed out");
161 }
162 delete promises[uuid];
163 }, timeout);
164 }
165 return promise;
166 };
167 }
168 }
169 }
170 );
171 }
172 var rpcProxy = getProxy(defaultTimeout);
173 var socketObject = {
174 raw: socket,

Callers

nothing calls this directly

Calls 4

genUUIDFunction · 0.70
parseUrlFunction · 0.70
setTimeoutFunction · 0.50
evalStaticallyMethod · 0.45

Tested by

no test coverage detected